<commit_before>/*
  Copyright (c) 2012 Carsten Burstedde, Donna Calhoun
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "bowl_user.h"

#include <fclaw2d_forestclaw.h>
#include <fclaw2d_clawpatch.h>
#include <fc2d_geoclaw.h>

typedef struct user_options
{

  int is_registered;

} user_options_t;

static void *
options_register_user (fclaw_app_t * app, void *package, sc_options_t * opt)
{
    user_options_t* user = (user_options_t*) package;

    /* [user] User options */

    user->is_registered = 1;
    return NULL;
}

static fclaw_exit_type_t
options_check_user (fclaw_app_t * app, void *package, void *registered)
{
    user_options_t* user = (user_options_t*) package;

    return FCLAW_NOEXIT;
}

static const fclaw_app_options_vtable_t options_vtable_user =
{
    options_register_user,
    NULL,
    options_check_user,
    NULL
};

static
void register_user_options (fclaw_app_t * app,
                            const char *configfile,
                            user_options_t* user)
{
    FCLAW_ASSERT (app != NULL);

    fclaw_app_options_register (app,"user", configfile, &options_vtable_user,
                                user);
}

void run_program(fclaw_app_t* app)
{
    sc_MPI_Comm            mpicomm;

    /* Mapped, multi-block domain */
    p4est_connectivity_t     *conn = NULL;
    fclaw2d_domain_t	       *domain;
    fclaw2d_map_context_t    *cont = NULL;

    amr_options_t            *gparms;

    mpicomm = fclaw_app_get_mpi_size_rank (app, NULL, NULL);

    gparms = fclaw_forestclaw_get_options(app);

    /* Map unit square to disk using mapc2m_disk.f */

    conn = p4est_connectivity_new_unitsquare();
    cont = fclaw2d_map_new_nomap();

    domain = fclaw2d_domain_new_conn_map (mpicomm, gparms->minlevel, conn, cont);
    fclaw2d_domain_list_levels(domain, FCLAW_VERBOSITY_ESSENTIAL);
    fclaw2d_domain_list_neighbors(domain, FCLAW_VERBOSITY_DEBUG);

    /* ---------------------------------------------------------------
       Set domain data.
       --------------------------------------------------------------- */
    fclaw2d_domain_data_new(domain);
    fclaw2d_domain_set_app (domain,app);
    bowl_link_solvers(domain);

    /* ---------------------------------------------------------------
       Run
       --------------------------------------------------------------- */
    fc2d_geoclaw_setup(domain);
    fclaw2d_initialize(&domain);
    fclaw2d_run(&domain);
    fclaw2d_finalize(&domain);
    /* This has to be in this scope */
    fclaw2d_map_destroy(cont);
}

int
main (int argc, char **argv)
{
    fclaw_app_t *app;
    int first_arg;
    fclaw_exit_type_t vexit;

    /* Options */
    sc_options_t                *options;
    user_options_t              suser, *user = &suser;

    int retval;

    /* Initialize application */
    app = fclaw_app_new (&argc, &argv, user);
    fclaw_forestclaw_register(app,"fclaw_options.ini");
    fc2d_geoclaw_register(app,"fclaw_options.ini");

    /* User options */
    register_user_options(app,"fclaw_options.ini",user);

    /* Read configuration file(s) and command line, and process options */
    options = fclaw_app_get_options (app);
    retval = fclaw_options_read_from_file(options);
    vexit =  fclaw_app_options_parse (app, &first_arg,"fclaw_options.ini.used");

    fclaw2d_clawpatch_link_app(app);

    /* Run the program */

    if (!retval & !vexit)
    {
        run_program(app);
    }

    fclaw_forestclaw_destroy(app);
    fclaw_app_destroy (app);

    return 0;
}
<commit_msg>(geoclaw/bowl_radial) Comment out unused variables<commit_after>/*
  Copyright (c) 2012 Carsten Burstedde, Donna Calhoun
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "bowl_user.h"

#include <fclaw2d_forestclaw.h>
#include <fclaw2d_clawpatch.h>
#include <fc2d_geoclaw.h>

typedef struct user_options
{

  int is_registered;

} user_options_t;

static void *
options_register_user (fclaw_app_t * app, void *package, sc_options_t * opt)
{
    user_options_t* user = (user_options_t*) package;

    /* [user] User options */

    user->is_registered = 1;
    return NULL;
}

static fclaw_exit_type_t
options_check_user (fclaw_app_t * app, void *package, void *registered)
{
    /*
    user_options_t* user = (user_options_t*) package;
    */

    return FCLAW_NOEXIT;
}

static const fclaw_app_options_vtable_t options_vtable_user =
{
    options_register_user,
    NULL,
    options_check_user,
    NULL
};

static
void register_user_options (fclaw_app_t * app,
                            const char *configfile,
                            user_options_t* user)
{
    FCLAW_ASSERT (app != NULL);

    fclaw_app_options_register (app,"user", configfile, &options_vtable_user,
                                user);
}

void run_program(fclaw_app_t* app)
{
    sc_MPI_Comm            mpicomm;

    /* Mapped, multi-block domain */
    p4est_connectivity_t     *conn = NULL;
    fclaw2d_domain_t	       *domain;
    fclaw2d_map_context_t    *cont = NULL;

    amr_options_t            *gparms;

    mpicomm = fclaw_app_get_mpi_size_rank (app, NULL, NULL);

    gparms = fclaw_forestclaw_get_options(app);

    /* Map unit square to disk using mapc2m_disk.f */

    conn = p4est_connectivity_new_unitsquare();
    cont = fclaw2d_map_new_nomap();

    domain = fclaw2d_domain_new_conn_map (mpicomm, gparms->minlevel, conn, cont);
    fclaw2d_domain_list_levels(domain, FCLAW_VERBOSITY_ESSENTIAL);
    fclaw2d_domain_list_neighbors(domain, FCLAW_VERBOSITY_DEBUG);

    /* ---------------------------------------------------------------
       Set domain data.
       --------------------------------------------------------------- */
    fclaw2d_domain_data_new(domain);
    fclaw2d_domain_set_app (domain,app);
    bowl_link_solvers(domain);

    /* ---------------------------------------------------------------
       Run
       --------------------------------------------------------------- */
    fc2d_geoclaw_setup(domain);
    fclaw2d_initialize(&domain);
    fclaw2d_run(&domain);
    fclaw2d_finalize(&domain);
    /* This has to be in this scope */
    fclaw2d_map_destroy(cont);
}

int
main (int argc, char **argv)
{
    fclaw_app_t *app;
    int first_arg;
    fclaw_exit_type_t vexit;

    /* Options */
    sc_options_t                *options;
    user_options_t              suser, *user = &suser;

    int retval;

    /* Initialize application */
    app = fclaw_app_new (&argc, &argv, user);
    fclaw_forestclaw_register(app,"fclaw_options.ini");
    fc2d_geoclaw_register(app,"fclaw_options.ini");

    /* User options */
    register_user_options(app,"fclaw_options.ini",user);

    /* Read configuration file(s) and command line, and process options */
    options = fclaw_app_get_options (app);
    retval = fclaw_options_read_from_file(options);
    vexit =  fclaw_app_options_parse (app, &first_arg,"fclaw_options.ini.used");

    fclaw2d_clawpatch_link_app(app);

    /* Run the program */

    if (!retval & !vexit)
    {
        run_program(app);
    }

    fclaw_forestclaw_destroy(app);
    fclaw_app_destroy (app);

    return 0;
}
<|endoftext|>


<commit_before>// posit_properties.cpp example program comparing epsilon and minpos across posit configurations
//
// Copyright (C) 2017-2020 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <limits>

// select the number systems we would like to compare
#include <universal/integer/integer>
#include <universal/fixpnt/fixpnt>
#include <universal/areal/areal>
#include <universal/posit/posit>
#include <universal/lns/lns>
#include <universal/valid/valid>

//constexpr long double pi     = 3.14159265358979323846;
//constexpr long double e      = 2.71828182845904523536;
//constexpr long double log_2e = 1.44269504088896340736;

// variadic template to generate a range of nbits
template<size_t ... nbits, size_t es>
void eps_impl(std::index_sequence<nbits...>, const size_t index) }
    std::array<size_t, sizeof...(nbits)> eps = std::numeric_limits<sw::unum::posit<nbits,es>>::epsilon();
    return eps[index];
}

template<size_t es = 2>
const long double eps(const size_t nbits) {
	return eps_impl(std::make_index_sequence<64>(), nbits);
}

int main(int argc, char** argv)
try {
	using namespace std;
	using namespace sw::unum;

	cout << "epsilon/minpos for different number systems " << endl;

	// report on smallest number, precision and dynamic range of the number system

	streamsize precision = cout.precision();

	cout << setprecision(precision);
	cout << endl;

	return EXIT_SUCCESS;
}
catch (char const* msg) {
	std::cerr << msg << std::endl;
	return EXIT_FAILURE;
}
catch (const std::runtime_error& err) {
	std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (...) {
	std::cerr << "Caught unknown exception" << std::endl;
	return EXIT_FAILURE;
}
<commit_msg>testing variadic template<commit_after>// posit_properties.cpp example program comparing epsilon and minpos across posit configurations
//
// Copyright (C) 2017-2020 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <iostream>
#include <limits>
#include <cmath>
#include <utility>
#include <array>

// select the number systems we would like to compare
#include <universal/integer/integer>
#include <universal/fixpnt/fixpnt>
#include <universal/areal/areal>
#include <universal/posit/posit>
#include <universal/lns/lns>
#include <universal/valid/valid>

//constexpr long double pi     = 3.14159265358979323846;
//constexpr long double e      = 2.71828182845904523536;
//constexpr long double log_2e = 1.44269504088896340736;

template<size_t n>
struct Fib {
  static const size_t val = Fib<n-1>::val + Fib<n-2>::val;
};

template<>
struct Fib<0> {
  static const size_t val = 0;
};

template<>
struct Fib<1> {
  static const size_t val = 1;
};

// create a compile time table using a variadic template
template<size_t ... N>
size_t fib_impl(std::index_sequence<N...>, size_t n)
{
	constexpr std::array<size_t, sizeof...(N)> a
		= { Fib<N>::val... };
    return a[n];
}

size_t fibonacci(size_t n) {
  return fib_impl(std::make_index_sequence<50>(), n);
}

/*
// but there is a closed solution to the Fibonacci sequence with the Binet formula

size_t fib2(const size_t n) {
   const size_t sqrt_5 = std::sqrt(5);

   if (n == 0) return 0;
   if (n == 1) return 1;

   return static_cast<size_t>((1 + sqrt_5, n) - std::pow(1 - sqrt_5, n)) / (std::pow(2, n) * sqrt_5);
}
*/

#if NEXT
// variadic template to generate a range of nbits
template<size_t ... nbits, size_t es>
void eps_impl(std::index_sequence<nbits...>, const size_t index) }
    std::array<size_t, sizeof...(nbits)> eps = std::numeric_limits<sw::unum::posit<nbits,es>>::epsilon();
    return eps[index];
}

template<size_t es = 2>
const long double eps(const size_t nbits) {
	return eps_impl(std::make_index_sequence<64>(), nbits);
}
#endif

int main(int argc, char** argv)
try {
	using namespace std;
	using namespace sw::unum;

	cout << "epsilon/minpos for different number systems " << endl;

	// report on smallest number, precision and dynamic range of the number system

	streamsize precision = cout.precision();

	std::cout << "Fibonacci(45) = " << fibonacci(45) << '\n';

	cout << setprecision(precision);
	cout << endl;

	return EXIT_SUCCESS;
}
catch (char const* msg) {
	std::cerr << msg << std::endl;
	return EXIT_FAILURE;
}
catch (const std::runtime_error& err) {
	std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (...) {
	std::cerr << "Caught unknown exception" << std::endl;
	return EXIT_FAILURE;
}
<|endoftext|>


<commit_before>/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014, 2015
Raffaello D. Di Napoli

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abaclade.hxx>
#include <abaclade/testing/test_case.hxx>
#include <abaclade/collections/map.hxx>

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc {
namespace test {

ABC_TESTING_TEST_CASE_FUNC("abc::collections::map – basic operations") {
   ABC_TRACE_FUNC(this);

   collections::map<int, int> m;

   ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

   m.add_or_assign(10, 100);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[10], 100);

   m.add_or_assign(20, 200);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
   ABC_TESTING_ASSERT_EQUAL(m[10], 100);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);

   m.remove(10);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);

   m.add_or_assign(22, 220);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);
   ABC_TESTING_ASSERT_EQUAL(m[22], 220);

   m.clear();
   ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);

   m.add_or_assign(11, 110);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[11], 110);

   // Add enough key/value pairs until a resize occurs.
   int iKey = 11, iValue = 110;
   std::size_t iInitialCapacity = m.capacity();
   do {
      iKey += 11;
      iValue += 110;
      m.add_or_assign(iKey, iValue);
   } while (m.capacity() == iInitialCapacity);
   /* Verify that some values are still there. Can’t check them all because we don’t know exactly
   how many we ended up adding. */
   ABC_TESTING_ASSERT_EQUAL(m[11], 110);
   ABC_TESTING_ASSERT_EQUAL(m[22], 220);
   ABC_TESTING_ASSERT_EQUAL(m[iKey - 11], iValue - 110);
   ABC_TESTING_ASSERT_EQUAL(m[iKey], iValue);

   // Validate that non-copyable types can be stored in a map.
   {
      collections::map<int, std::unique_ptr<int>> m2;
      m2.add_or_assign(1, std::unique_ptr<int>(new int(10)));
   }
}

} //namespace test
} //namespace abc

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc {
namespace test {

namespace {

/*! Inefficient hash function that results in 100% hash collisions. This also checks that hash 0
(which has a special meaning internally to abc::collections::map) behaves no differently than any
other value.

@param i
   Value to hash.
@return
   Hash of i.
*/
struct poor_hash {
   std::size_t operator()(int i) const {
      ABC_UNUSED_ARG(i);
      return 0;
   }
};

} //namespace

ABC_TESTING_TEST_CASE_FUNC("abc::collections::map – stress test with 100% collisions") {
   ABC_TRACE_FUNC(this);

   static int const sc_iMax = 1000;
   unsigned cErrors;
   collections::map<int, int, poor_hash> m;

   // Verify that values are inserted correctly.
   cErrors = 0;
   for (int i = 0; i < sc_iMax; ++i) {
      m.add_or_assign(i, i);
      if (m[i] != i) {
         ++cErrors;
      }
   }
   ABC_TESTING_ASSERT_EQUAL(cErrors, 0u);

   // Verify that the insertion of later values did not break previously-inserted values.
   cErrors = 0;
   for (int i = 0; i < sc_iMax; ++i) {
      if (m[i] != i) {
         ++cErrors;
      }
   }
   ABC_TESTING_ASSERT_EQUAL(cErrors, 0u);
}

} //namespace test
} //namespace abc
<commit_msg>Add unit tests for abc::collections::map::iterator<commit_after>/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014, 2015
Raffaello D. Di Napoli

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#include <abaclade.hxx>
#include <abaclade/testing/test_case.hxx>
#include <abaclade/collections/map.hxx>

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc {
namespace test {

ABC_TESTING_TEST_CASE_FUNC("abc::collections::map – basic operations") {
   ABC_TRACE_FUNC(this);

   collections::map<int, int> m;

   ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);
   // These assertions target const begin/end.
   ABC_TESTING_ASSERT_TRUE(m.cbegin() == m.cend());
   //ABC_TESTING_ASSERT_TRUE(m.crbegin() == m.crend());

   m.add_or_assign(10, 100);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[10], 100);
   {
      /* This uses begin(), not cbegin(), so we can test equality comparison between const/non-const
      iterators. */
      auto it(m.begin());
      ABC_TESTING_ASSERT_EQUAL(it->key, 10);
      ABC_TESTING_ASSERT_EQUAL(it->value, 100);
      ++it;
      ABC_TESTING_ASSERT_TRUE(it == m.cend());
   }

   m.add_or_assign(20, 200);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
   ABC_TESTING_ASSERT_EQUAL(m[10], 100);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);
   /*{
      // This iterates backwards and is longer than, but symmetrical to, the block above.
      auto it(m.rbegin());
      ABC_TESTING_ASSERT_EQUAL(it->key, 10);
      ABC_TESTING_ASSERT_EQUAL(it->value, 100);
      ++it;
      ABC_TESTING_ASSERT_EQUAL(it->key, 20);
      ABC_TESTING_ASSERT_EQUAL(it->value, 200);
      ++it;
      ABC_TESTING_ASSERT_TRUE(it == m.crend());
   }*/

   m.remove(10);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);

   m.add_or_assign(22, 220);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 2u);
   ABC_TESTING_ASSERT_EQUAL(m[20], 200);
   ABC_TESTING_ASSERT_EQUAL(m[22], 220);

   m.clear();
   ABC_TESTING_ASSERT_EQUAL(m.size(), 0u);
   // These assertions target non-const begin/end.
   ABC_TESTING_ASSERT_TRUE(m.begin() == m.end());
   //ABC_TESTING_ASSERT_TRUE(m.rbegin() == m.rend());

   m.add_or_assign(11, 110);
   ABC_TESTING_ASSERT_EQUAL(m.size(), 1u);
   ABC_TESTING_ASSERT_EQUAL(m[11], 110);

   // Add enough key/value pairs until a resize occurs.
   int iKey = 11, iValue = 110;
   std::size_t iInitialCapacity = m.capacity();
   do {
      iKey += 11;
      iValue += 110;
      m.add_or_assign(iKey, iValue);
   } while (m.capacity() == iInitialCapacity);
   /* Verify that some values are still there. Can’t check them all because we don’t know exactly
   how many we ended up adding. */
   ABC_TESTING_ASSERT_EQUAL(m[11], 110);
   ABC_TESTING_ASSERT_EQUAL(m[22], 220);
   ABC_TESTING_ASSERT_EQUAL(m[iKey - 11], iValue - 110);
   ABC_TESTING_ASSERT_EQUAL(m[iKey], iValue);

   // Validate that non-copyable types can be stored in a map.
   {
      collections::map<int, std::unique_ptr<int>> m2;
      m2.add_or_assign(1, std::unique_ptr<int>(new int(10)));
   }
}

} //namespace test
} //namespace abc

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc {
namespace test {

namespace {

/*! Inefficient hash function that results in 100% hash collisions. This also checks that hash 0
(which has a special meaning internally to abc::collections::map) behaves no differently than any
other value.

@param i
   Value to hash.
@return
   Hash of i.
*/
struct poor_hash {
   std::size_t operator()(int i) const {
      ABC_UNUSED_ARG(i);
      return 0;
   }
};

} //namespace

ABC_TESTING_TEST_CASE_FUNC("abc::collections::map – stress test with 100% collisions") {
   ABC_TRACE_FUNC(this);

   static int const sc_iMax = 1000;
   unsigned cErrors;
   collections::map<int, int, poor_hash> m;

   // Verify that values are inserted correctly.
   cErrors = 0;
   for (int i = 0; i < sc_iMax; ++i) {
      m.add_or_assign(i, i);
      if (m[i] != i) {
         ++cErrors;
      }
   }
   ABC_TESTING_ASSERT_EQUAL(cErrors, 0u);

   // Verify that the insertion of later values did not break previously-inserted values.
   cErrors = 0;
   for (int i = 0; i < sc_iMax; ++i) {
      if (m[i] != i) {
         ++cErrors;
      }
   }
   ABC_TESTING_ASSERT_EQUAL(cErrors, 0u);
}

} //namespace test
} //namespace abc

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc {
namespace test {

ABC_TESTING_TEST_CASE_FUNC("abc::collections::map – operations with iterators") {
   ABC_TRACE_FUNC(this);

   collections::map<int, int> m;

   m.add_or_assign(10, 100);
   ABC_FOR_EACH(auto kv, m) {
      ABC_TESTING_ASSERT_EQUAL(kv.key, 10);
      ABC_TESTING_ASSERT_EQUAL(kv.value, 100);
   }
}

} //namespace test
} //namespace abc
<|endoftext|>


<commit_before>// Difference from running average.

// Include standard headers.
#include <vector>
#include <sstream>
#include <thread>

// Include 3rd party headers.
#include <boost/date_time.hpp>
#include <boost/filesystem.hpp>
#include <opencv2/opencv.hpp>
#include "ConcurrentQueue.hpp"
#include "RateTicker.hpp"
#include "Config.hpp"

// Include application headers.
#include "util.hpp"

void capture(
    cv::VideoCapture* cap,
    const int& duration,
    std::vector <ConcurrentQueue <cv::Mat*>* >* detect_queues,
    ConcurrentQueue <cv::Mat*>* display_queue
    )
{
    // Monitor framerates for the given seconds past.
    RateTicker framerate ({ 1, 5, 10 });

    // Run the loop for designated amount of time.
    auto now = boost::posix_time::microsec_clock::universal_time();
    auto dur = boost::posix_time::seconds(duration);
    auto end = now + dur;
    while (end > boost::posix_time::microsec_clock::universal_time())
    {
        // Take a snapshot.
        auto frame = new cv::Mat;
        *cap >> *frame;

        // Stamp the capture framerate on top of the image.
        auto fps = framerate.tick();
        std::ostringstream line;
        line << std::fixed << std::setprecision(2);
        line << fps[0] << ", " << fps[1] << ", " << fps[2] << " (capture)";
        std::list<std::string> lines;
        lines.push_back(line.str());
        sherlock::writeOSD(*frame, lines, 0.04);

        // Push image onto all queues.
        for(auto proc_queue : *detect_queues)
        {
            proc_queue->push(frame);
        }
        display_queue->push(frame);
    }

    // Signal end-of-processing by pushing NULL onto all queues.
    for(auto proc_queue : *detect_queues)
    {
        proc_queue->push(NULL);
    }
    display_queue->push(NULL);
}

// Collect a list of positive detection rectangles.
struct RectColor{
    cv::Rect rect;
    cv::Scalar color;
};

void detect(
    ConcurrentQueue <cv::Mat*>* detect_queue,
    cv::CascadeClassifier* classifier,
    cv::Scalar color,
    ConcurrentQueue <RectColor>* rect_colors,
    ConcurrentQueue <cv::Mat*>* done_queue
    )
{
    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    detect_queue->wait_and_pop(frame);
    while(frame)
    {
        std::vector<cv::Rect> rects;
        classifier->detectMultiScale(
            *frame,
            rects,
            1.3,  // scale factor.
            3,    // min neighbors.
            0,    // flags.
            {frame->size().width/20, frame->size().height/20},  // min size.
            {frame->size().width/2, frame->size().height/2}     // max size.
            );

        // Add rectangles to the data queue.
        for(auto rect : rects)
        {
            rect_colors->push({ rect, color });
        }

        // Filter out excess images in the input queue.
        // Detection framerate is more likely (than not) to be slower than
        // capture framerate, hence the "lossy filtering" here.
        // Add all dropped frames and processed frames to "done" queue.
        int count = 0;
        auto prev_frame = frame;
        while(detect_queue->try_pop(frame))
        {
            done_queue->push(prev_frame);
            prev_frame = frame;
            count++;
        }
        if(count == 0)
        {
            done_queue->push(prev_frame);
            detect_queue->wait_and_pop(frame);
        }
    }
}

void display(
    ConcurrentQueue <cv::Mat*>* display_queue,
    ConcurrentQueue <RectColor>* rect_colors,
    ConcurrentQueue <cv::Mat*>* done_queue
    )
{
    // Create the output window.
    const char* title = "detect 2";
    cv::namedWindow(title, CV_WINDOW_NORMAL);

    // Monitor framerates for the given seconds past.
    RateTicker framerate ({ 1, 5, 10 });

    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    display_queue->wait_and_pop(frame);
    while(frame)
    {
        // Draw the rectangles.
        RectColor rect_color;
        while(rect_colors->try_pop(rect_color))
        {
            auto rect = rect_color.rect;
            auto color = rect_color.color;
            cv::rectangle(
                *frame,
                cv::Point(rect.x, rect.y),
                cv::Point(rect.x + rect.width, rect.y + rect.height),
                color,
                2  // thickness.
                );
        }

        // Write the display framerate on top of the image.
        auto fps = framerate.tick();
        std::ostringstream line;
        line << std::fixed << std::setprecision(2);
        line << fps[0] << ", " << fps[1] << ", " << fps[2] << " (display)";
        std::list<std::string> lines;
        lines.push_back("");
        lines.push_back(line.str());
        sherlock::writeOSD(*frame, lines, 0.04);

        // Display the snapshot.
        cv::imshow(title, *frame);
        cv::waitKey(1);

        // Filter out excess images in the queue.
        // If display hardware is not fast enough, showing these
        // images introduces (incremental) lag, hence the "lossy filter."
        // Add all dropped and processed frames to "done" queue.
        int count = 0;
        auto prev_frame = frame;
        while(display_queue->try_pop(frame))
        {
            done_queue->push(prev_frame);
            prev_frame = frame;
            ++count;
        }
        if(count == 0)
        {
            done_queue->push(prev_frame);
            display_queue->wait_and_pop(frame);
        }
    }
}

void deallocate(
    ConcurrentQueue <cv::Mat*>* done_queue,
    const int& deallocate_trigger_count
    )
{
    // Count the number of times each frame is encountered
    // in the "done" queue (to know when the count triggers
    // deallocation.)
    std::map <cv::Mat*, int> done_counts;

    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    done_queue->wait_and_pop(frame);
    while(frame)
    {
        // If this is the first time frame is encountered,
        // initialize it's count to 1 (one.)
        if(done_counts.find(frame) == done_counts.end())
        {
            done_counts.insert({ frame, 1 });
        }
        // Otherwise, increment the frame's existing count,
        // and perform deallocation, if triggered.
        else
        {
            done_counts[frame]++;
            if(done_counts[frame] == deallocate_trigger_count)
            {
                delete frame;
                done_counts.erase(frame);
            }
        }

        // Retrieve the next frame.
        done_queue->wait_and_pop(frame);
    }
}

int main(int argc, char** argv)
{
    // Parse command-line arguments.
    int DEVICE, WIDTH, HEIGHT, DURATION;
    std::istringstream(std::string(argv[1])) >> DEVICE;
    std::istringstream(std::string(argv[2])) >> WIDTH;
    std::istringstream(std::string(argv[3])) >> HEIGHT;
    std::istringstream(std::string(argv[4])) >> DURATION;

    // Initialize the classifiers and their respective colors.
    Config config ("conf/classifiers.conf");
    std::vector< cv::CascadeClassifier* > classifiers;
    std::vector< cv::Scalar > colors;
    for(auto fname : config.keys())
    {
        boost::filesystem::path file(fname + ".xml");
        for(auto dname : { "/usr/share/OpenCV/haarcascades",
                    "/usr/share/OpenCV/lbpcascades" }
            )
        {
            boost::filesystem::path dir(dname);
            boost::filesystem::path full = dir / file;
            auto cfer = new cv::CascadeClassifier(full.string());
            if( cfer->empty() ) continue;
            classifiers.push_back(cfer);
            double rr, gg, bb;
            std::stringstream(config[fname]) >> rr >> gg >> bb;
            colors.push_back({ rr, gg, bb });
        }
    }

    // Create the shared queues.
    std::vector< ConcurrentQueue <cv::Mat*>* > detect_queues;
    ConcurrentQueue <cv::Mat*> display_queue;
    ConcurrentQueue <cv::Mat*> done_queue;
    ConcurrentQueue <RectColor> rect_colors;

    // Start up the detector threads.
    std::list <std::thread*> detectors;
    for(int ii=0; ii!= classifiers.size(); ++ii)
    {
        auto frames = new ConcurrentQueue<cv::Mat*>;
        detect_queues.push_back(frames);
        cv::CascadeClassifier* cfer = classifiers[ii];
        cv::Scalar color = colors[ii];
        auto tt = new std::thread(
            detect,
            frames,
            cfer,
            color,
            &rect_colors,
            &done_queue
            );
        detectors.push_back(tt);
    }

    // Create the OpenCV video capture object.
    cv::VideoCapture cap(DEVICE);
    cap.set(3, WIDTH);
    cap.set(4, HEIGHT);

    // Start up capture and display threads.
    std::thread capturer (capture, &cap, DURATION, &detect_queues, &display_queue);
    std::thread displayer (display, &display_queue, &rect_colors, &done_queue);

    // Start up the deallocator thread.
    auto deallocate_trigger_count = detectors.size() + 1;
    std::thread deallocator (
        deallocate, &done_queue, deallocate_trigger_count);

    // Join all threads.
    capturer.join();
    displayer.join();
    for(auto thread : detectors)
    {
        thread->join();
        delete thread;
    }

    // Signal deallocator thread to stop, and join it.
    done_queue.push(NULL);
    deallocator.join();
}
<commit_msg>Use initializer lists, add doc strings.<commit_after>// Object detection.

// Include standard headers.
#include <vector>
#include <sstream>
#include <thread>

// Include 3rd party headers.
#include <boost/date_time.hpp>
#include <boost/filesystem.hpp>
#include <opencv2/opencv.hpp>
#include "ConcurrentQueue.hpp"
#include "RateTicker.hpp"
#include "Config.hpp"

// Include application headers.
#include "util.hpp"

// Capture frames for given *duration* number of seconds,
// and push frames onto queues.
void capture(
    cv::VideoCapture* cap,
    const int& duration,
    std::vector <ConcurrentQueue <cv::Mat*>* >* detect_queues,
    ConcurrentQueue <cv::Mat*>* display_queue
    )
{
    // Monitor framerates for the given seconds past.
    RateTicker framerate ({ 1, 5, 10 });

    // Run the loop for designated amount of time.
    auto now = boost::posix_time::microsec_clock::universal_time();
    auto dur = boost::posix_time::seconds(duration);
    auto end = now + dur;
    while (end > boost::posix_time::microsec_clock::universal_time())
    {
        // Take a snapshot.
        auto frame = new cv::Mat;
        *cap >> *frame;

        // Stamp the capture framerate on top of the image.
        auto fps = framerate.tick();
        std::ostringstream line;
        line << std::fixed << std::setprecision(2);
        line << fps[0] << ", " << fps[1] << ", " << fps[2] << " (capture)";
        std::list<std::string> lines ({ line.str() });
        sherlock::writeOSD(*frame, lines, 0.04);

        // Push image onto all queues.
        for(auto proc_queue : *detect_queues)
        {
            proc_queue->push(frame);
        }
        display_queue->push(frame);
    }

    // Signal end-of-processing by pushing NULL onto all queues.
    for(auto proc_queue : *detect_queues)
    {
        proc_queue->push(NULL);
    }
    display_queue->push(NULL);
}

// Collect a list of positive detection rectangles.
struct RectColor{
    cv::Rect rect;
    cv::Scalar color;
};

// Do detection.
void detect(
    ConcurrentQueue <cv::Mat*>* detect_queue,
    cv::CascadeClassifier* classifier,
    const cv::Scalar& color,
    ConcurrentQueue <RectColor>* rect_colors,
    ConcurrentQueue <cv::Mat*>* done_queue
    )
{
    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    detect_queue->wait_and_pop(frame);
    while(frame)
    {
        std::vector<cv::Rect> rects;
        classifier->detectMultiScale(
            *frame,
            rects,
            1.3,  // scale factor.
            3,    // min neighbors.
            0,    // flags.
            {frame->size().width/20, frame->size().height/20},  // min size.
            {frame->size().width/2, frame->size().height/2}     // max size.
            );

        // Add rectangles to the data queue.
        for(auto rect : rects)
        {
            rect_colors->push({ rect, color });
        }

        // Filter out excess images in the input queue.
        // Detection framerate is more likely (than not) to be slower than
        // capture framerate, hence the "lossy filtering" here.
        // Add all dropped frames and processed frames to "done" queue.
        int count = 0;
        auto prev_frame = frame;
        while(detect_queue->try_pop(frame))
        {
            done_queue->push(prev_frame);
            prev_frame = frame;
            count++;
        }
        if(count == 0)
        {
            done_queue->push(prev_frame);
            detect_queue->wait_and_pop(frame);
        }
    }
}

// Draw rectangles on queued frames, and display.
void display(
    ConcurrentQueue <cv::Mat*>* display_queue,
    ConcurrentQueue <RectColor>* rect_colors,
    ConcurrentQueue <cv::Mat*>* done_queue
    )
{
    // Create the output window.
    const char* title = "detect 2";
    cv::namedWindow(title, CV_WINDOW_NORMAL);

    // Monitor framerates for the given seconds past.
    RateTicker framerate ({ 1, 5, 10 });

    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    display_queue->wait_and_pop(frame);
    while(frame)
    {
        // Draw the rectangles.
        RectColor rect_color;
        while(rect_colors->try_pop(rect_color))
        {
            auto rect = rect_color.rect;
            auto color = rect_color.color;
            cv::rectangle(
                *frame,
                cv::Point(rect.x, rect.y),
                cv::Point(rect.x + rect.width, rect.y + rect.height),
                color,
                2  // thickness.
                );
        }

        // Write the display framerate on top of the image.
        auto fps = framerate.tick();
        std::ostringstream line;
        line << std::fixed << std::setprecision(2);
        line << fps[0] << ", " << fps[1] << ", " << fps[2] << " (display)";
        std::list<std::string> lines ({ "", line.str() });
        sherlock::writeOSD(*frame, lines, 0.04);

        // Display the snapshot.
        cv::imshow(title, *frame);
        cv::waitKey(1);

        // Filter out excess images in the queue.
        // If display hardware is not fast enough, showing these
        // images introduces (incremental) lag, hence the "lossy filter."
        // Add all dropped and processed frames to "done" queue.
        int count = 0;
        auto prev_frame = frame;
        while(display_queue->try_pop(frame))
        {
            done_queue->push(prev_frame);
            prev_frame = frame;
            ++count;
        }
        if(count == 0)
        {
            done_queue->push(prev_frame);
            display_queue->wait_and_pop(frame);
        }
    }
}

// Deallocate frames in given queue.
// Deallocate a frame when its count reaches trigger threshold.
void deallocate(
    ConcurrentQueue <cv::Mat*>* done_queue,
    const int& deallocate_trigger_count
    )
{
    // Count the number of times each frame is encountered
    // in the "done" queue (to know when the count triggers
    // deallocation.)
    std::map <cv::Mat*, int> done_counts;

    // Pull from the queue while there are valid matrices.
    cv::Mat* frame;
    done_queue->wait_and_pop(frame);
    while(frame)
    {
        // If this is the first time frame is encountered,
        // initialize it's count to 1 (one.)
        if(done_counts.find(frame) == done_counts.end())
        {
            done_counts.insert({ frame, 1 });
        }
        // Otherwise, increment the frame's existing count,
        // and perform deallocation, if triggered.
        else
        {
            done_counts[frame]++;
            if(done_counts[frame] == deallocate_trigger_count)
            {
                delete frame;
                done_counts.erase(frame);
            }
        }

        // Retrieve the next frame.
        done_queue->wait_and_pop(frame);
    }
}

int main(int argc, char** argv)
{
    // Parse command-line arguments.
    int DEVICE, WIDTH, HEIGHT, DURATION;
    std::istringstream(std::string(argv[1])) >> DEVICE;
    std::istringstream(std::string(argv[2])) >> WIDTH;
    std::istringstream(std::string(argv[3])) >> HEIGHT;
    std::istringstream(std::string(argv[4])) >> DURATION;

    // Initialize the classifiers and their respective colors.
    Config config ("conf/classifiers.conf");
    std::vector< cv::CascadeClassifier* > classifiers;
    std::vector< cv::Scalar > colors;
    for(auto fname : config.keys())
    {
        boost::filesystem::path file(fname + ".xml");
        for(auto dname : { "/usr/share/OpenCV/haarcascades",
                    "/usr/share/OpenCV/lbpcascades" }
            )
        {
            boost::filesystem::path dir(dname);
            boost::filesystem::path full = dir / file;
            auto cfer = new cv::CascadeClassifier(full.string());
            if( cfer->empty() ) continue;
            classifiers.push_back(cfer);
            double rr, gg, bb;
            std::stringstream(config[fname]) >> rr >> gg >> bb;
            colors.push_back({ rr, gg, bb });
        }
    }

    // Create the shared queues.
    std::vector< ConcurrentQueue <cv::Mat*>* > detect_queues;
    ConcurrentQueue <cv::Mat*> display_queue;
    ConcurrentQueue <cv::Mat*> done_queue;
    ConcurrentQueue <RectColor> rect_colors;

    // Start up the detector threads.
    std::list <std::thread*> detectors;
    for(int ii=0; ii!= classifiers.size(); ++ii)
    {
        auto frames = new ConcurrentQueue<cv::Mat*>;
        detect_queues.push_back(frames);
        cv::CascadeClassifier* cfer = classifiers[ii];
        cv::Scalar color = colors[ii];
        auto tt = new std::thread(
            detect,
            frames,
            cfer,
            color,
            &rect_colors,
            &done_queue
            );
        detectors.push_back(tt);
    }

    // Create the OpenCV video capture object.
    cv::VideoCapture cap(DEVICE);
    cap.set(3, WIDTH);
    cap.set(4, HEIGHT);

    // Start up capture and display threads.
    std::thread capturer (capture, &cap, DURATION, &detect_queues, &display_queue);
    std::thread displayer (display, &display_queue, &rect_colors, &done_queue);

    // Start up the deallocator thread.
    auto deallocate_trigger_count = detectors.size() + 1;
    std::thread deallocator (
        deallocate, &done_queue, deallocate_trigger_count);

    // Join all threads.
    capturer.join();
    displayer.join();
    for(auto thread : detectors)
    {
        thread->join();
        delete thread;
    }

    // Signal deallocator thread to stop, and join it.
    done_queue.push(NULL);
    deallocator.join();
}
<|endoftext|>


<commit_before>#include <core.h>
#include <LiquidCrystal.h>
#include "display.h"
#include "thermostat.h"
#include "display_mode.h"

using namespace core;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

DisplayMode _initialMode;

DisplayMode *mode = &_initialMode;

void switchMode(DisplayMode *newMode) {
  if (newMode == mode) {
    return;
  }

  mode = newMode;
  lcd.clear();
  newMode->enterState();
}

void onModeKey() {
  if (store::digitals[idKeyMode] == HIGH) {
    mode->onModeKey();
  }
}

void onUpKey() {
  if (store::digitals[idKeyUp] == HIGH) {
    mode->onUpKey();
  }
}

void onDownKey() {
  if (store::digitals[idKeyDown] == HIGH) {
    mode->onDownKey();
  }
}

void onSetupKey() {
  if (store::digitals[idKeySetup] == HIGH) {
    mode->onSetupKey();
  }
}

void onTempeHumiChanges() {
  mode->onTempeHumiChanges();
}

void onHeaterChanges() {
  mode->onHeaterChanges();
}

void onClock() {
  mode->onClock();
}

void switchToNormalMode() {
  switchMode(normalMode);
}

void setupDisplay(void) {
  lcd.begin(16, 2);

  lcd.clear();
  lcd.print(F("Thermostat v2.0"));
  lcd.setCursor(0, 1);
  lcd.print(F("Handwork of Forks"));

  store::monitorAnalogs(&onTempeHumiChanges, 2, idTempe, idHumi);
  store::monitorDigitals(&onHeaterChanges, 2, idHeaterReq, idHeaterAct);
  store::monitorDigitals(&onModeKey, 1, idKeyMode);
  store::monitorDigitals(&onUpKey, 1, idKeyUp);
  store::monitorDigitals(&onDownKey, 1, idKeyDown);
  store::monitorDigitals(&onSetupKey, 1, idKeySetup);

  clock::interval(1000, &onClock);
  clock::delay(1000, &switchToNormalMode);
}
<commit_msg>Change spriter<commit_after>#include <core.h>
#include <LiquidCrystal.h>
#include "display.h"
#include "thermostat.h"
#include "display_mode.h"

using namespace core;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

DisplayMode _initialMode;

DisplayMode *mode = &_initialMode;

void switchMode(DisplayMode *newMode) {
  if (newMode == mode) {
    return;
  }

  mode = newMode;
  lcd.clear();
  newMode->enterState();
}

void onModeKey() {
  if (store::digitals[idKeyMode] == HIGH) {
    mode->onModeKey();
  }
}

void onUpKey() {
  if (store::digitals[idKeyUp] == HIGH) {
    mode->onUpKey();
  }
}

void onDownKey() {
  if (store::digitals[idKeyDown] == HIGH) {
    mode->onDownKey();
  }
}

void onSetupKey() {
  if (store::digitals[idKeySetup] == HIGH) {
    mode->onSetupKey();
  }
}

void onTempeHumiChanges() {
  mode->onTempeHumiChanges();
}

void onHeaterChanges() {
  mode->onHeaterChanges();
}

void onClock() {
  mode->onClock();
}

void switchToNormalMode() {
  switchMode(normalMode);
}

void setupDisplay(void) {
  lcd.begin(16, 2);

  lcd.clear();
  lcd.print(F("Thermostat v2.0"));
  lcd.setCursor(2, 1);
  lcd.print(F("by Red Forks"));
  delay(3000);

  store::monitorAnalogs(&onTempeHumiChanges, 2, idTempe, idHumi);
  store::monitorDigitals(&onHeaterChanges, 2, idHeaterReq, idHeaterAct);
  store::monitorDigitals(&onModeKey, 1, idKeyMode);
  store::monitorDigitals(&onUpKey, 1, idKeyUp);
  store::monitorDigitals(&onDownKey, 1, idKeyDown);
  store::monitorDigitals(&onSetupKey, 1, idKeySetup);

  clock::interval(1000, &onClock);
  clock::delay(1000, &switchToNormalMode);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: CellColorHandler.cxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: os $ $Date: 2007-05-03 06:23:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef INCLUDED_CELLCOLORHANDLER_HXX
#include <CellColorHandler.hxx>
#endif
#ifndef INCLUDED_DMAPPER_PROPERTYMAP_HXX
#include <PropertyMap.hxx>
#endif
#ifndef INCLUDED_RESOURCESIDS
#include <doctok/resourceids.hxx>
#endif
#ifndef INCLUDED_DMAPPER_CONVERSIONHELPER_HXX
#include <ConversionHelper.hxx>
#endif

namespace dmapper {

using namespace ::com::sun::star;
//using namespace ::std;

/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
CellColorHandler::CellColorHandler()
{
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
CellColorHandler::~CellColorHandler()
{
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
void CellColorHandler::attribute(doctok::Id rName, doctok::Value & rVal)
{
    sal_Int32 nIntValue = rVal.getInt();
    (void)nIntValue;
    (void)rName;
    switch( rName )
    {
        case NS_rtf::LN_cellTopColor:
        case NS_rtf::LN_cellLeftColor:
        case NS_rtf::LN_cellBottomColor:
        case NS_rtf::LN_cellRightColor:
            // nIntValue contains the color, directly
        break;
//        case NS_rtf::LN_rgbrc:
//        {
//            doctok::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
//            if( pProperties.get())
//            {
//                pProperties->resolve(*this);
//                //
//            }
//        }
//        break;
        default:
            OSL_ASSERT("unknown attribute");
    }
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
void CellColorHandler::sprm(doctok::Sprm & rSprm)
{
    (void)rSprm;
}
/*-- 24.04.2007 09:09:01---------------------------------------------------

  -----------------------------------------------------------------------*/
PropertyMapPtr  CellColorHandler::getProperties()
{
    PropertyMapPtr pPropertyMap(new PropertyMap);
    return pPropertyMap;
}
} //namespace dmapper
<commit_msg>using namespace ::writerfilter<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: CellColorHandler.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: fridrich_strba $ $Date: 2007-05-03 10:07:16 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef INCLUDED_CELLCOLORHANDLER_HXX
#include <CellColorHandler.hxx>
#endif
#ifndef INCLUDED_DMAPPER_PROPERTYMAP_HXX
#include <PropertyMap.hxx>
#endif
#ifndef INCLUDED_RESOURCESIDS
#include <doctok/resourceids.hxx>
#endif
#ifndef INCLUDED_DMAPPER_CONVERSIONHELPER_HXX
#include <ConversionHelper.hxx>
#endif

namespace dmapper {

using namespace ::com::sun::star;
using namespace ::writerfilter;
//using namespace ::std;

/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
CellColorHandler::CellColorHandler()
{
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
CellColorHandler::~CellColorHandler()
{
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
void CellColorHandler::attribute(doctok::Id rName, doctok::Value & rVal)
{
    sal_Int32 nIntValue = rVal.getInt();
    (void)nIntValue;
    (void)rName;
    switch( rName )
    {
        case NS_rtf::LN_cellTopColor:
        case NS_rtf::LN_cellLeftColor:
        case NS_rtf::LN_cellBottomColor:
        case NS_rtf::LN_cellRightColor:
            // nIntValue contains the color, directly
        break;
//        case NS_rtf::LN_rgbrc:
//        {
//            doctok::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
//            if( pProperties.get())
//            {
//                pProperties->resolve(*this);
//                //
//            }
//        }
//        break;
        default:
            OSL_ASSERT("unknown attribute");
    }
}
/*-- 24.04.2007 09:06:35---------------------------------------------------

  -----------------------------------------------------------------------*/
void CellColorHandler::sprm(doctok::Sprm & rSprm)
{
    (void)rSprm;
}
/*-- 24.04.2007 09:09:01---------------------------------------------------

  -----------------------------------------------------------------------*/
PropertyMapPtr  CellColorHandler::getProperties()
{
    PropertyMapPtr pPropertyMap(new PropertyMap);
    return pPropertyMap;
}
} //namespace dmapper
<|endoftext|>


<commit_before><commit_msg>36. Valid Sudoku<commit_after><|endoftext|>


<commit_before>#ifndef _RTFREFERENCETABLE_HXX_
#define _RTFREFERENCETABLE_HXX_

#include <map>
#include <resourcemodel/WW8ResourceModel.hxx>

class SvStream;

namespace writerfilter {
    namespace rtftok {
        class RTFReferenceTable
            : public writerfilter::Reference

        {
            public:
                typedef std::map<int, writerfilter::Reference<Properties>::Pointer_t> Entries_t;
                typedef std::pair<int, writerfilter::Reference<Properties>::Pointer_t> Entry_t;
                RTFReferenceTable(Entries_t const& rEntries);
                virtual ~RTFReferenceTable();
                virtual void resolve(Table & rHandler);
                virtual std::string getType() const;
            private:
                Entries_t m_aEntries;
        };
    } // namespace rtftok
} // namespace writerfilter

#endif // _RTFREFERENCETABLE_HXX_

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>RTFReferenceTable: missing doc<commit_after>#ifndef _RTFREFERENCETABLE_HXX_
#define _RTFREFERENCETABLE_HXX_

#include <map>
#include <resourcemodel/WW8ResourceModel.hxx>

class SvStream;

namespace writerfilter {
    namespace rtftok {
        /// Sends tables (e.g. font table) to the domain mapper.
        class RTFReferenceTable
            : public writerfilter::Reference

        {
            public:
                typedef std::map<int, writerfilter::Reference<Properties>::Pointer_t> Entries_t;
                typedef std::pair<int, writerfilter::Reference<Properties>::Pointer_t> Entry_t;
                RTFReferenceTable(Entries_t const& rEntries);
                virtual ~RTFReferenceTable();
                virtual void resolve(Table & rHandler);
                virtual std::string getType() const;
            private:
                Entries_t m_aEntries;
        };
    } // namespace rtftok
} // namespace writerfilter

#endif // _RTFREFERENCETABLE_HXX_

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: XMLTextPropertySetContext.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2004-11-09 12:19:22 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#ifndef _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX
#include "XMLTextPropertySetContext.hxx"
#endif
#ifndef _XMLTEXTCOLUMNSCONTEXT_HXX
#include "XMLTextColumnsContext.hxx"
#endif
#ifndef _XMLBACKGROUNDIMAGECONTEXT_HXX
#include "XMLBackgroundImageContext.hxx"
#endif
#ifndef _XMLOFF_XMLSECTIONFOOTNOTECONFIGIMPORT_HXX
#include "XMLSectionFootnoteConfigImport.hxx"
#endif

#ifndef _XMLOFF_TXTPRMAP_HXX
#include "txtprmap.hxx"
#endif
#ifndef _XMLOFF_XMLTABI_HXX
#include "xmltabi.hxx"
#endif
#ifndef _XMLOFF_TXTDROPI_HXX
#include "txtdropi.hxx"
#endif

using namespace ::rtl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;

XMLTextPropertySetContext::XMLTextPropertySetContext(
                 SvXMLImport& rImport, sal_uInt16 nPrfx,
                 const OUString& rLName,
                 const Reference< xml::sax::XAttributeList > & xAttrList,
                 sal_uInt32 nFamily,
                 ::std::vector< XMLPropertyState > &rProps,
                 const UniReference < SvXMLImportPropertyMapper > &rMap,
                 OUString& rDCTextStyleName ) :
    SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
                             rProps, rMap ),
    rDropCapTextStyleName( rDCTextStyleName )
{
}

XMLTextPropertySetContext::~XMLTextPropertySetContext()
{
}

SvXMLImportContext *XMLTextPropertySetContext::CreateChildContext(
                   sal_uInt16 nPrefix,
                   const OUString& rLocalName,
                   const Reference< xml::sax::XAttributeList > & xAttrList,
                   ::std::vector< XMLPropertyState > &rProperties,
                   const XMLPropertyState& rProp )
{
    SvXMLImportContext *pContext = 0;

    switch( xMapper->getPropertySetMapper()
                    ->GetEntryContextId( rProp.mnIndex ) )
    {
    case CTF_TABSTOP:
        pContext = new SvxXMLTabStopImportContext( GetImport(), nPrefix,
                                                   rLocalName, rProp,
                                                   rProperties );
        break;
    case CTF_TEXTCOLUMNS:
#ifndef SVX_LIGHT
        pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
                                                   rLocalName, xAttrList, rProp,
                                                   rProperties );
#else
        // create default context to skip content
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
#endif // #ifndef SVX_LIGHT
        break;

    case CTF_DROPCAPFORMAT:
        {
            DBG_ASSERT( rProp.mnIndex >= 2 &&
                        CTF_DROPCAPWHOLEWORD  == xMapper->getPropertySetMapper()
                            ->GetEntryContextId( rProp.mnIndex-2 ),
                        "invalid property map!");
            XMLTextDropCapImportContext *pDCContext =
                new XMLTextDropCapImportContext( GetImport(), nPrefix,
                                                        rLocalName, xAttrList,
                                                        rProp,
                                                        rProp.mnIndex-2,
                                                        rProperties );
            rDropCapTextStyleName = pDCContext->GetStyleName();
        pContext = pDCContext;
        }
        break;

    case CTF_BACKGROUND_URL:
    {
        DBG_ASSERT( rProp.mnIndex >= 2 &&
                    CTF_BACKGROUND_POS  == xMapper->getPropertySetMapper()
                        ->GetEntryContextId( rProp.mnIndex-2 ) &&
                    CTF_BACKGROUND_FILTER  == xMapper->getPropertySetMapper()
                        ->GetEntryContextId( rProp.mnIndex-1 ),
                    "invalid property map!");

        // #99657# Transparency might be there as well... but doesn't have
        // to. Thus, this is checked with an if, rather than with an assertion.
        sal_Int32 nTranspIndex = -1;
        if( (rProp.mnIndex >= 3) &&
            ( CTF_BACKGROUND_TRANSPARENCY ==
              xMapper->getPropertySetMapper()->GetEntryContextId(
                  rProp.mnIndex-3 ) ) )
            nTranspIndex = rProp.mnIndex-3;

        pContext =
            new XMLBackgroundImageContext( GetImport(), nPrefix,
                                           rLocalName, xAttrList,
                                           rProp,
                                           rProp.mnIndex-2,
                                           rProp.mnIndex-1,
                                           nTranspIndex,
                                           rProperties );
    }
    break;
#ifndef SVX_LIGHT
    case CTF_SECTION_FOOTNOTE_END:
    case CTF_SECTION_ENDNOTE_END:
        pContext = new XMLSectionFootnoteConfigImport(
            GetImport(), nPrefix, rLocalName, rProperties,
            xMapper->getPropertySetMapper());
        break;
#endif // #ifndef SVX_LIGHT
    }

    if( !pContext )
        pContext = SvXMLPropertySetContext::CreateChildContext( nPrefix, rLocalName,
                                                            xAttrList,
                                                            rProperties, rProp );

    return pContext;
}

<commit_msg>INTEGRATION: CWS ooo19126 (1.10.220); FILE MERGED 2005/09/05 14:40:05 rt 1.10.220.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: XMLTextPropertySetContext.cxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 15:25:24 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#ifndef _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX
#include "XMLTextPropertySetContext.hxx"
#endif
#ifndef _XMLTEXTCOLUMNSCONTEXT_HXX
#include "XMLTextColumnsContext.hxx"
#endif
#ifndef _XMLBACKGROUNDIMAGECONTEXT_HXX
#include "XMLBackgroundImageContext.hxx"
#endif
#ifndef _XMLOFF_XMLSECTIONFOOTNOTECONFIGIMPORT_HXX
#include "XMLSectionFootnoteConfigImport.hxx"
#endif

#ifndef _XMLOFF_TXTPRMAP_HXX
#include "txtprmap.hxx"
#endif
#ifndef _XMLOFF_XMLTABI_HXX
#include "xmltabi.hxx"
#endif
#ifndef _XMLOFF_TXTDROPI_HXX
#include "txtdropi.hxx"
#endif

using namespace ::rtl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;

XMLTextPropertySetContext::XMLTextPropertySetContext(
                 SvXMLImport& rImport, sal_uInt16 nPrfx,
                 const OUString& rLName,
                 const Reference< xml::sax::XAttributeList > & xAttrList,
                 sal_uInt32 nFamily,
                 ::std::vector< XMLPropertyState > &rProps,
                 const UniReference < SvXMLImportPropertyMapper > &rMap,
                 OUString& rDCTextStyleName ) :
    SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
                             rProps, rMap ),
    rDropCapTextStyleName( rDCTextStyleName )
{
}

XMLTextPropertySetContext::~XMLTextPropertySetContext()
{
}

SvXMLImportContext *XMLTextPropertySetContext::CreateChildContext(
                   sal_uInt16 nPrefix,
                   const OUString& rLocalName,
                   const Reference< xml::sax::XAttributeList > & xAttrList,
                   ::std::vector< XMLPropertyState > &rProperties,
                   const XMLPropertyState& rProp )
{
    SvXMLImportContext *pContext = 0;

    switch( xMapper->getPropertySetMapper()
                    ->GetEntryContextId( rProp.mnIndex ) )
    {
    case CTF_TABSTOP:
        pContext = new SvxXMLTabStopImportContext( GetImport(), nPrefix,
                                                   rLocalName, rProp,
                                                   rProperties );
        break;
    case CTF_TEXTCOLUMNS:
#ifndef SVX_LIGHT
        pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
                                                   rLocalName, xAttrList, rProp,
                                                   rProperties );
#else
        // create default context to skip content
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
#endif // #ifndef SVX_LIGHT
        break;

    case CTF_DROPCAPFORMAT:
        {
            DBG_ASSERT( rProp.mnIndex >= 2 &&
                        CTF_DROPCAPWHOLEWORD  == xMapper->getPropertySetMapper()
                            ->GetEntryContextId( rProp.mnIndex-2 ),
                        "invalid property map!");
            XMLTextDropCapImportContext *pDCContext =
                new XMLTextDropCapImportContext( GetImport(), nPrefix,
                                                        rLocalName, xAttrList,
                                                        rProp,
                                                        rProp.mnIndex-2,
                                                        rProperties );
            rDropCapTextStyleName = pDCContext->GetStyleName();
        pContext = pDCContext;
        }
        break;

    case CTF_BACKGROUND_URL:
    {
        DBG_ASSERT( rProp.mnIndex >= 2 &&
                    CTF_BACKGROUND_POS  == xMapper->getPropertySetMapper()
                        ->GetEntryContextId( rProp.mnIndex-2 ) &&
                    CTF_BACKGROUND_FILTER  == xMapper->getPropertySetMapper()
                        ->GetEntryContextId( rProp.mnIndex-1 ),
                    "invalid property map!");

        // #99657# Transparency might be there as well... but doesn't have
        // to. Thus, this is checked with an if, rather than with an assertion.
        sal_Int32 nTranspIndex = -1;
        if( (rProp.mnIndex >= 3) &&
            ( CTF_BACKGROUND_TRANSPARENCY ==
              xMapper->getPropertySetMapper()->GetEntryContextId(
                  rProp.mnIndex-3 ) ) )
            nTranspIndex = rProp.mnIndex-3;

        pContext =
            new XMLBackgroundImageContext( GetImport(), nPrefix,
                                           rLocalName, xAttrList,
                                           rProp,
                                           rProp.mnIndex-2,
                                           rProp.mnIndex-1,
                                           nTranspIndex,
                                           rProperties );
    }
    break;
#ifndef SVX_LIGHT
    case CTF_SECTION_FOOTNOTE_END:
    case CTF_SECTION_ENDNOTE_END:
        pContext = new XMLSectionFootnoteConfigImport(
            GetImport(), nPrefix, rLocalName, rProperties,
            xMapper->getPropertySetMapper());
        break;
#endif // #ifndef SVX_LIGHT
    }

    if( !pContext )
        pContext = SvXMLPropertySetContext::CreateChildContext( nPrefix, rLocalName,
                                                            xAttrList,
                                                            rProperties, rProp );

    return pContext;
}

<|endoftext|>


<commit_before>/***********************************************
 * Author: Jun Jiang - jiangjun4@sina.com
 * Create: 2017-08-19 18:50
 * Last modified : 2017-08-19 18:50
 * Filename      : DNN.cpp
 * Description   :
 **********************************************/
#include "dnn/DNN.h"
#include "dnn/Layer.h"
#include "utils/Log.h"
#include "utils/Shuffler.h"
#include <vector>

namespace abcdl{
namespace dnn{

void DNN::train(const abcdl::algebra::Mat& train_data,
                const abcdl::algebra::Mat& train_label,
                const abcdl::algebra::Mat& test_data,
                const abcdl::algebra::Mat& test_label){
    LOG(INFO) << "dnn start training...";

    size_t layer_size = _layers.size();
    size_t num_train_data = train_data.rows();

    CHECK(num_train_data == train_label.rows());
    CHECK(train_data.cols() == _layers[0]->get_input_dim());
    CHECK(train_label.cols() == _layers[_layers.size() -1]->get_output_dim());

    abcdl::utils::Shuffler shuffler(num_train_data);
    abcdl::algebra::Mat data;
    abcdl::algebra::Mat label;

    for(size_t i = 0; i != _epoch; i++){
        shuffler.shuffle();
        for(size_t j = 0; j != num_train_data; j++){
            train_data.get_row(&data, shuffler.get_row(j));
            train_label.get_row(&label, shuffler.get_row(j));

            for(size_t k = 0; k != layer_size; k++){
                if(k == 0){
                    ((InputLayer*)_layers[k])->set_x(data);
                }
                _layers[k]->forward(_layers[k-1]);
            }
            //printf("[%ld][%ld]\n", j, num_train_data);

            for(size_t k = layer_size - 1; k > 0; k--){
                if(k == layer_size - 1){
                    ((OutputLayer*)_layers[k])->set_y(label);
                    _layers[k]->backward(_layers[k-1], nullptr);
                }else{
                    _layers[k]->backward(_layers[k-1], _layers[k+1]);
                }

                //mini_batch_update
                if(j % _batch_size == _batch_size - 1 || j == num_train_data - 1){
                    _layers[k]->update_gradient(j % _batch_size + 1, _alpha, _lamda);
                }
            }

            if(j % 100 == 0){
                printf("Epoch[%ld/%ld] Train[%ld/%ld]\r", i + 1, _epoch, j, num_train_data);
            }
        }

        if(test_data.rows() > 0){
            size_t num = evaluate(test_data, test_label);
            printf("Epoch[%ld][%ld/%ld] rate[%f]\n", i + 1, num, test_data.rows(), num/(real)test_data.rows());
        }
        write_model(path);
    }
}

size_t DNN::evaluate(const abcdl::algebra::Mat& test_data, const abcdl::algebra::Mat& test_label){
    CHECK(test_data.cols() == _layers[0]->get_input_dim());
    CHECK(test_data.rows() == test_label.rows());
    CHECK(test_label.cols() == _layers[_layers.size() - 1]->get_output_dim());

    size_t rows = test_data.rows();
    size_t predict_num = 0;
    abcdl::algebra::Mat mat;

    for(size_t i = 0; i != rows; i++){
        predict(mat, test_data.get_row(i));
        size_t p_label = mat.argmax();
        size_t t_label = test_label.get_row(i).argmax();
        if(p_label == t_label){
            ++predict_num;
        }else{
            printf("[%ld][%f][%ld]\n", p_label, mat.max(), t_label);
        }
    }
    return predict_num;
}

void DNN::predict(abcdl::algebra::Mat& result, const abcdl::algebra::Mat& predict_data){
    CHECK(predict_data.cols() == _layers[0]->get_input_dim());
    size_t layer_size = _layers.size();
    for(size_t k = 0; k != layer_size; k++){
        if(k == 0){
            ((InputLayer*)_layers[k])->set_x(predict_data);
        }
        _layers[k]->forward(_layers[k-1]);
    }
    result = _layers[layer_size - 1]->get_activate_data();
}

bool DNN::load_model(const std::string& path){
    std::vector<abcdl::algebra::Mat*> models;
    if(!model_loader.read<real>(path, &models, "DNNMODEL") || models.size() % 2 != 0){
        for(auto& model : models){
            delete model;
        }
        models.clear();
        return false;
    }

    for(auto& layer : _layers){
        delete layer;
    }
    _layers.clear();

    for(size_t i = 0; i != models.size() / 2; i++){
        if(i == 0){
            _layers.push_back(new InputLayer(models[0]->rows()));
        }
        if(i == models.size() / 2 - 1){
            _layers.push_back(new OutputLayer(models[i * 2]->rows(), models[i * 2]->cols(), new SigmoidActivateFunc(), new CrossEntropyCost(), *models[i * 2], *models[i * 2 + 1]));
        }else{
            _layers.push_back(new FullConnLayer(models[i * 2]->rows(), models[i * 2]->cols(), new SigmoidActivateFunc(), *models[i * 2], *models[i * 2 + 1]));
        }
    }

    for(auto& model : models){
        delete model;
    }
    models.clear();
    return true;
}
bool DNN::write_model(const std::string& path){
    std::vector<abcdl::algebra::Mat*> models;
    for(size_t i = 1; i != _layers.size(); i++){
        models.push_back(&_layers[i]->get_weight());
        models.push_back(&_layers[i]->get_bias());
    }
    return model_loader.write<real>(models, path, "DNNMODEL", false);
}

}//namespace dnn
}//namespace abcdl
<commit_msg>initialized<commit_after>/***********************************************
 * Author: Jun Jiang - jiangjun4@sina.com
 * Create: 2017-08-19 18:50
 * Last modified : 2017-08-19 18:50
 * Filename      : DNN.cpp
 * Description   :
 **********************************************/
#include "dnn/DNN.h"
#include "dnn/Layer.h"
#include "utils/Log.h"
#include "utils/Shuffler.h"
#include <vector>

namespace abcdl{
namespace dnn{

void DNN::train(const abcdl::algebra::Mat& train_data,
                const abcdl::algebra::Mat& train_label,
                const abcdl::algebra::Mat& test_data,
                const abcdl::algebra::Mat& test_label){
    LOG(INFO) << "dnn start training...";

    size_t layer_size = _layers.size();
    size_t num_train_data = train_data.rows();

    CHECK(num_train_data == train_label.rows());
    CHECK(train_data.cols() == _layers[0]->get_input_dim());
    CHECK(train_label.cols() == _layers[_layers.size() -1]->get_output_dim());

    abcdl::utils::Shuffler shuffler(num_train_data);
    abcdl::algebra::Mat data;
    abcdl::algebra::Mat label;

    for(size_t i = 0; i != _epoch; i++){
        shuffler.shuffle();
        for(size_t j = 0; j != num_train_data; j++){
            train_data.get_row(&data, shuffler.get_row(j));
            train_label.get_row(&label, shuffler.get_row(j));

            for(size_t k = 0; k != layer_size; k++){
                if(k == 0){
                    ((InputLayer*)_layers[k])->set_x(data);
                }
                _layers[k]->forward(_layers[k-1]);
            }
            //printf("[%ld][%ld]\n", j, num_train_data);

            for(size_t k = layer_size - 1; k > 0; k--){
                if(k == layer_size - 1){
                    ((OutputLayer*)_layers[k])->set_y(label);
                    _layers[k]->backward(_layers[k-1], nullptr);
                }else{
                    _layers[k]->backward(_layers[k-1], _layers[k+1]);
                }

                //mini_batch_update
                if(j % _batch_size == _batch_size - 1 || j == num_train_data - 1){
                    _layers[k]->update_gradient(j % _batch_size + 1, _alpha, _lamda);
                }
            }

            if(j % 100 == 0){
                printf("Epoch[%ld/%ld] Train[%ld/%ld]\r", i + 1, _epoch, j, num_train_data);
            }
        }

        if(test_data.rows() > 0){
            size_t num = evaluate(test_data, test_label);
            printf("Epoch[%ld][%ld/%ld] rate[%f]\n", i + 1, num, test_data.rows(), num/(real)test_data.rows());
        }
    }
}

size_t DNN::evaluate(const abcdl::algebra::Mat& test_data, const abcdl::algebra::Mat& test_label){
    CHECK(test_data.cols() == _layers[0]->get_input_dim());
    CHECK(test_data.rows() == test_label.rows());
    CHECK(test_label.cols() == _layers[_layers.size() - 1]->get_output_dim());

    size_t rows = test_data.rows();
    size_t predict_num = 0;
    abcdl::algebra::Mat mat;

    for(size_t i = 0; i != rows; i++){
        predict(mat, test_data.get_row(i));
        size_t p_label = mat.argmax();
        size_t t_label = test_label.get_row(i).argmax();
        if(p_label == t_label){
            ++predict_num;
        }else{
            printf("[%ld][%f][%ld]\n", p_label, mat.max(), t_label);
        }
    }
    return predict_num;
}

void DNN::predict(abcdl::algebra::Mat& result, const abcdl::algebra::Mat& predict_data){
    CHECK(predict_data.cols() == _layers[0]->get_input_dim());
    size_t layer_size = _layers.size();
    for(size_t k = 0; k != layer_size; k++){
        if(k == 0){
            ((InputLayer*)_layers[k])->set_x(predict_data);
        }
        _layers[k]->forward(_layers[k-1]);
    }
    result = _layers[layer_size - 1]->get_activate_data();
}

bool DNN::load_model(const std::string& path){
    std::vector<abcdl::algebra::Mat*> models;
    if(!model_loader.read<real>(path, &models, "DNNMODEL") || models.size() % 2 != 0){
        for(auto& model : models){
            delete model;
        }
        models.clear();
        return false;
    }

    for(auto& layer : _layers){
        delete layer;
    }
    _layers.clear();

    for(size_t i = 0; i != models.size() / 2; i++){
        if(i == 0){
            _layers.push_back(new InputLayer(models[0]->rows()));
        }
        if(i == models.size() / 2 - 1){
            _layers.push_back(new OutputLayer(models[i * 2]->rows(), models[i * 2]->cols(), new SigmoidActivateFunc(), new CrossEntropyCost(), *models[i * 2], *models[i * 2 + 1]));
        }else{
            _layers.push_back(new FullConnLayer(models[i * 2]->rows(), models[i * 2]->cols(), new SigmoidActivateFunc(), *models[i * 2], *models[i * 2 + 1]));
        }
    }

    for(auto& model : models){
        delete model;
    }
    models.clear();
    return true;
}
bool DNN::write_model(const std::string& path){
    std::vector<abcdl::algebra::Mat*> models;
    for(size_t i = 1; i != _layers.size(); i++){
        models.push_back(&_layers[i]->get_weight());
        models.push_back(&_layers[i]->get_bias());
    }
    return model_loader.write<real>(models, path, "DNNMODEL", false);
}

}//namespace dnn
}//namespace abcdl
<|endoftext|>


<commit_before>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// gc_manager_factory.cpp
//
// Identification: src/backend/concurrency/gc_manager_factory.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "gc_manager_factory.h"

namespace peloton {
namespace gc { GCType GCManagerFactory::gc_type_ = GC_TYPE_OFF; }
}
<commit_msg>turned gc on by default<commit_after>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// gc_manager_factory.cpp
//
// Identification: src/backend/concurrency/gc_manager_factory.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "gc_manager_factory.h"

namespace peloton {
namespace gc { GCType GCManagerFactory::gc_type_ = GC_TYPE_ON; }
}
<|endoftext|>


<commit_before>
# include <emscripten/bind.h>

# include "libcellml/annotator.h"

using namespace emscripten;

EMSCRIPTEN_BINDINGS(libcellml_annotator)
{
    class_<libcellml::Annotator>("Annotator")
        .smart_ptr_constructor("Annotator", &libcellml::Annotator::create)
        .function("setModel", &libcellml::Annotator::setModel)
        .function("modelByXXX", select_overload<libcellml::ModelPtr() const>(&libcellml::Annotator::model))
        .function("modelById", select_overload<libcellml::ModelPtr(const std::string &, size_t)>(&libcellml::Annotator::model))
        .function("modelById", select_overload<libcellml::ModelPtr(const std::string &)>(&libcellml::Annotator::model))
        .function("itemById", select_overload<libcellml::AnyItem(const std::string &)>(&libcellml::Annotator::item))
        .function("itemById", select_overload<libcellml::AnyItem(const std::string &, size_t)>(&libcellml::Annotator::item))
        .function("componentById", select_overload<libcellml::ComponentPtr(const std::string &, size_t)>(&libcellml::Annotator::component))
        .function("componentById", select_overload<libcellml::ComponentPtr(const std::string &)>(&libcellml::Annotator::component))
        .function("componentRefById", select_overload<libcellml::ComponentPtr(const std::string &, size_t)>(&libcellml::Annotator::componentRef))
        .function("componentRefById", select_overload<libcellml::ComponentPtr(const std::string &)>(&libcellml::Annotator::componentRef))
        .function("encapsulationById", select_overload<libcellml::ModelPtr(const std::string &, size_t)>(&libcellml::Annotator::encapsulation))
        .function("encapsulationById", select_overload<libcellml::ModelPtr(const std::string &)>(&libcellml::Annotator::encapsulation))
        .function("variableById", select_overload<libcellml::VariablePtr(const std::string &, size_t)>(&libcellml::Annotator::variable))
        .function("variableById", select_overload<libcellml::VariablePtr(const std::string &)>(&libcellml::Annotator::variable))
        .function("resetById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::reset))
        .function("resetById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::reset))
        .function("importSourceById", select_overload<libcellml::ImportSourcePtr(const std::string &, size_t)>(&libcellml::Annotator::importSource))
        .function("importSourceById", select_overload<libcellml::ImportSourcePtr(const std::string &)>(&libcellml::Annotator::importSource))
        .function("unitsById", select_overload<libcellml::UnitsPtr(const std::string &, size_t)>(&libcellml::Annotator::units))
        .function("unitsById", select_overload<libcellml::UnitsPtr(const std::string &)>(&libcellml::Annotator::units))
        .function("connectionById", select_overload<libcellml::VariablePairPtr(const std::string &, size_t)>(&libcellml::Annotator::connection))
        .function("connectionById", select_overload<libcellml::VariablePairPtr(const std::string &)>(&libcellml::Annotator::connection))
        .function("mapVariablesById", select_overload<libcellml::VariablePairPtr(const std::string &, size_t)>(&libcellml::Annotator::mapVariables))
        .function("mapVariablesById", select_overload<libcellml::VariablePairPtr(const std::string &)>(&libcellml::Annotator::mapVariables))
        .function("unitById", select_overload<libcellml::UnitPtr(const std::string &, size_t)>(&libcellml::Annotator::unit))
        .function("unitById", select_overload<libcellml::UnitPtr(const std::string &)>(&libcellml::Annotator::unit))
        .function("testValueById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::testValue))
        .function("testValueById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::testValue))
        .function("resetValueById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::resetValue))
        .function("resetValueById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::resetValue))
        .function("assignAllIdsByXXX", select_overload<bool()>(&libcellml::Annotator::assignAllIds))
        .function("assignAllIdsByModel", select_overload<bool(libcellml::ModelPtr &)>(&libcellml::Annotator::assignAllIds))
        .function("assignIds", &libcellml::Annotator::assignIds)
        .function("clearAllIdsByXXX", select_overload<void()>(&libcellml::Annotator::clearAllIds))
        .function("clearAllIdsByModel", select_overload<void(libcellml::ModelPtr &)>(&libcellml::Annotator::clearAllIds))
        .function("isUnique", &libcellml::Annotator::isUnique)
        .function("items", &libcellml::Annotator::items)
        .function("ids", &libcellml::Annotator::ids)
        .function("duplicateIds", &libcellml::Annotator::duplicateIds)
        .function("assignIdByItem", select_overload<std::string(const libcellml::AnyItem &)>(&libcellml::Annotator::assignId))
        .function("assignIdByModel", select_overload<std::string(const libcellml::ModelPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByComponent", select_overload<std::string(const libcellml::ComponentPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByImportSource", select_overload<std::string(const libcellml::ImportSourcePtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByReset", select_overload<std::string(const libcellml::ResetPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnits", select_overload<std::string(const libcellml::UnitsPtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnitItem", select_overload<std::string(const libcellml::UnitPtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByVariable", select_overload<std::string(const libcellml::VariablePtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByPair", select_overload<std::string(const libcellml::VariablePairPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByVariable", select_overload<std::string(const libcellml::VariablePtr &, const libcellml::VariablePtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnits", select_overload<std::string(const libcellml::UnitsPtr &, size_t)>(&libcellml::Annotator::assignId))
        .function("assignComponentId", &libcellml::Annotator::assignComponentId)
        .function("assignComponentRefId", &libcellml::Annotator::assignComponentRefId)
        .function("assignConnectionId", &libcellml::Annotator::assignConnectionId)
        .function("assignEncapsulationId", &libcellml::Annotator::assignEncapsulationId)
        .function("assignImportSourceId", &libcellml::Annotator::assignImportSourceId)
        .function("assignMapVariablesId", &libcellml::Annotator::assignMapVariablesId)
        .function("assignModelId", &libcellml::Annotator::assignModelId)
        .function("assignResetId", &libcellml::Annotator::assignResetId)
        .function("assignResetValueId", &libcellml::Annotator::assignResetValueId)
        .function("assignTestValueId", &libcellml::Annotator::assignTestValueId)
        .function("assignUnitId", &libcellml::Annotator::assignUnitId)
        .function("assignUnitsId", &libcellml::Annotator::assignUnitsId)
        .function("assignVariableId", &libcellml::Annotator::assignVariableId)
        .function("itemCount", &libcellml::Annotator::itemCount)
        .function("hasModel", &libcellml::Annotator::hasModel)
    ;
}
<commit_msg>Remove unwanted space in javascript/annotator.cpp<commit_after>
#include <emscripten/bind.h>

#include "libcellml/annotator.h"

using namespace emscripten;

EMSCRIPTEN_BINDINGS(libcellml_annotator)
{
    class_<libcellml::Annotator>("Annotator")
        .smart_ptr_constructor("Annotator", &libcellml::Annotator::create)
        .function("setModel", &libcellml::Annotator::setModel)
        .function("modelByXXX", select_overload<libcellml::ModelPtr() const>(&libcellml::Annotator::model))
        .function("modelById", select_overload<libcellml::ModelPtr(const std::string &, size_t)>(&libcellml::Annotator::model))
        .function("modelById", select_overload<libcellml::ModelPtr(const std::string &)>(&libcellml::Annotator::model))
        .function("itemById", select_overload<libcellml::AnyItem(const std::string &)>(&libcellml::Annotator::item))
        .function("itemById", select_overload<libcellml::AnyItem(const std::string &, size_t)>(&libcellml::Annotator::item))
        .function("componentById", select_overload<libcellml::ComponentPtr(const std::string &, size_t)>(&libcellml::Annotator::component))
        .function("componentById", select_overload<libcellml::ComponentPtr(const std::string &)>(&libcellml::Annotator::component))
        .function("componentRefById", select_overload<libcellml::ComponentPtr(const std::string &, size_t)>(&libcellml::Annotator::componentRef))
        .function("componentRefById", select_overload<libcellml::ComponentPtr(const std::string &)>(&libcellml::Annotator::componentRef))
        .function("encapsulationById", select_overload<libcellml::ModelPtr(const std::string &, size_t)>(&libcellml::Annotator::encapsulation))
        .function("encapsulationById", select_overload<libcellml::ModelPtr(const std::string &)>(&libcellml::Annotator::encapsulation))
        .function("variableById", select_overload<libcellml::VariablePtr(const std::string &, size_t)>(&libcellml::Annotator::variable))
        .function("variableById", select_overload<libcellml::VariablePtr(const std::string &)>(&libcellml::Annotator::variable))
        .function("resetById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::reset))
        .function("resetById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::reset))
        .function("importSourceById", select_overload<libcellml::ImportSourcePtr(const std::string &, size_t)>(&libcellml::Annotator::importSource))
        .function("importSourceById", select_overload<libcellml::ImportSourcePtr(const std::string &)>(&libcellml::Annotator::importSource))
        .function("unitsById", select_overload<libcellml::UnitsPtr(const std::string &, size_t)>(&libcellml::Annotator::units))
        .function("unitsById", select_overload<libcellml::UnitsPtr(const std::string &)>(&libcellml::Annotator::units))
        .function("connectionById", select_overload<libcellml::VariablePairPtr(const std::string &, size_t)>(&libcellml::Annotator::connection))
        .function("connectionById", select_overload<libcellml::VariablePairPtr(const std::string &)>(&libcellml::Annotator::connection))
        .function("mapVariablesById", select_overload<libcellml::VariablePairPtr(const std::string &, size_t)>(&libcellml::Annotator::mapVariables))
        .function("mapVariablesById", select_overload<libcellml::VariablePairPtr(const std::string &)>(&libcellml::Annotator::mapVariables))
        .function("unitById", select_overload<libcellml::UnitPtr(const std::string &, size_t)>(&libcellml::Annotator::unit))
        .function("unitById", select_overload<libcellml::UnitPtr(const std::string &)>(&libcellml::Annotator::unit))
        .function("testValueById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::testValue))
        .function("testValueById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::testValue))
        .function("resetValueById", select_overload<libcellml::ResetPtr(const std::string &, size_t)>(&libcellml::Annotator::resetValue))
        .function("resetValueById", select_overload<libcellml::ResetPtr(const std::string &)>(&libcellml::Annotator::resetValue))
        .function("assignAllIdsByXXX", select_overload<bool()>(&libcellml::Annotator::assignAllIds))
        .function("assignAllIdsByModel", select_overload<bool(libcellml::ModelPtr &)>(&libcellml::Annotator::assignAllIds))
        .function("assignIds", &libcellml::Annotator::assignIds)
        .function("clearAllIdsByXXX", select_overload<void()>(&libcellml::Annotator::clearAllIds))
        .function("clearAllIdsByModel", select_overload<void(libcellml::ModelPtr &)>(&libcellml::Annotator::clearAllIds))
        .function("isUnique", &libcellml::Annotator::isUnique)
        .function("items", &libcellml::Annotator::items)
        .function("ids", &libcellml::Annotator::ids)
        .function("duplicateIds", &libcellml::Annotator::duplicateIds)
        .function("assignIdByItem", select_overload<std::string(const libcellml::AnyItem &)>(&libcellml::Annotator::assignId))
        .function("assignIdByModel", select_overload<std::string(const libcellml::ModelPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByComponent", select_overload<std::string(const libcellml::ComponentPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByImportSource", select_overload<std::string(const libcellml::ImportSourcePtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByReset", select_overload<std::string(const libcellml::ResetPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnits", select_overload<std::string(const libcellml::UnitsPtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnitItem", select_overload<std::string(const libcellml::UnitPtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByVariable", select_overload<std::string(const libcellml::VariablePtr &)>(&libcellml::Annotator::assignId))
        .function("assignIdByPair", select_overload<std::string(const libcellml::VariablePairPtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByVariable", select_overload<std::string(const libcellml::VariablePtr &, const libcellml::VariablePtr &, libcellml::CellmlElementType)>(&libcellml::Annotator::assignId))
        .function("assignIdByUnits", select_overload<std::string(const libcellml::UnitsPtr &, size_t)>(&libcellml::Annotator::assignId))
        .function("assignComponentId", &libcellml::Annotator::assignComponentId)
        .function("assignComponentRefId", &libcellml::Annotator::assignComponentRefId)
        .function("assignConnectionId", &libcellml::Annotator::assignConnectionId)
        .function("assignEncapsulationId", &libcellml::Annotator::assignEncapsulationId)
        .function("assignImportSourceId", &libcellml::Annotator::assignImportSourceId)
        .function("assignMapVariablesId", &libcellml::Annotator::assignMapVariablesId)
        .function("assignModelId", &libcellml::Annotator::assignModelId)
        .function("assignResetId", &libcellml::Annotator::assignResetId)
        .function("assignResetValueId", &libcellml::Annotator::assignResetValueId)
        .function("assignTestValueId", &libcellml::Annotator::assignTestValueId)
        .function("assignUnitId", &libcellml::Annotator::assignUnitId)
        .function("assignUnitsId", &libcellml::Annotator::assignUnitsId)
        .function("assignVariableId", &libcellml::Annotator::assignVariableId)
        .function("itemCount", &libcellml::Annotator::itemCount)
        .function("hasModel", &libcellml::Annotator::hasModel)
    ;
}
<|endoftext|>