Esempio n. 1
0
		Tokenizer(const String* inString, jerome::Locale const & inLocale = jerome::Locale()) 	
		:mIndex(*inString,boost::char_separator<char>(", ")),
		 mLocale(inLocale)
		{			
			mBegin = mIndex.begin();
			mIterator = mIndex.begin();
			mEndIterator = mIndex.end();
			
		}
Esempio n. 2
0
 virtual F Lookup(const storage_type &data, I data_size,
     const index_type &shape, const index_type &stride, const index_type &index) const override {
   for (auto i = I(0); i < shape.size(); ++i) {
     if (index.at(i) < 0 || shape.at(i) <= index.at(i)) {
       return DefaultValue();
     }
   }
   return identity_.Lookup(data, data_size, shape, stride, index);
 }
Esempio n. 3
0
void CCopasiArray::resize(const index_type & sizes)
{
  mDim = sizes.size();
  mSizes = sizes;
  mFactors.resize(mDim);

  unsigned int tmpDataSize = 1;
  index_type::const_reverse_iterator it, itEnd = sizes.rend();
  index_type::reverse_iterator itFaktor;
  for (it = sizes.rbegin(), itFaktor = mFactors.rbegin(); it != itEnd; ++it, ++itFaktor)
    {
      *itFaktor = tmpDataSize;
      tmpDataSize *= *it;
    }
  mData.resize(tmpDataSize);
}
Esempio n. 4
0
/**
Allocate matrix on integers with dimension [nrl to nrh] x [ncl to nch].
\param nrl lower row matrix index
\param nrh upper row matrix index
\param ncl lower column matrix index
\param nch upper column matrix index
*/
void imatrix::allocate(
  const ad_integer& nrl, const ad_integer& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (nrl > nrh)
  {
    allocate();
  }
  else
  {
    index_min = nrl;
    index_max = nrh;
    if ((ncl.isinteger() && (nrl != ncl.indexmin() || nrh != ncl.indexmax()))
       || (nch.isinteger() && (nrl != nch.indexmin() || nrh != nch.indexmax())))
    {
      cerr << "Incompatible imatrix bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      if(nrh==0) 
      {
        // Some models use 0 for columns to "turn off" a parameter, so we
        // don't want to exit in this case, just throw error.
        cerr << "0 columns - was this intentional?\n" ;
      }
      else
      {
        ad_exit(1);
      }
    }
    unsigned int ss = static_cast<unsigned int>(nrh - nrl + 1);
    if ((m = new ivector[ss]) == 0)
    {
      cerr << " Error: imatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((shape = new mat_shapex(m)) == 0)
    {
      cerr << " Error: imatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    m -= int(nrl);
    for (int i = nrl; i <= nrh; ++i)
    {
      m[i].allocate(ncl(i), nch(i));
    }
  }
}
Esempio n. 5
0
/**
Allocate matrix with dimensions [nrl to nrh] x [ncl to nch]
\param nrl lower matrix row index
\param nrl upper matrix row index
\param ncl lower matrix column index
\param ncl upper matrix column index
*/
void dmatrix::allocate(
  const ad_integer& nrl, const ad_integer& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (nrh < nrl)
  {
    allocate();
  }
  else
  {
    if ((ncl.isinteger() && (nrl != ncl.indexmin() || nrh != ncl.indexmax()))
       || (nch.isinteger() && (nrl != nch.indexmin() || nrh != nch.indexmax())))
    {
      cerr << "Incompatible dmatrix bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      ad_exit(1);
    }
    index_min = int(nrl);
    index_max = int(nrh);
    if ((m = new dvector[rowsize()]) == 0)
    {
      cerr << " Error: dmatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((shape = new mat_shapex(m)) == 0)
    {
      cerr << " Error: dmatrix unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    m -= int(nrl);
    for (int i = nrl; i <= nrh; ++i)
    {
      m[i].allocate(ncl[i], nch[i]);
    }
  }
}
Esempio n. 6
0
/**
Allocate array of matrices with dimensions
[sl to sh] x [nrl to nrh] x [ncl to nch].
\param sl lower vector index
\param sh upper vector index
\param nrl lower matrix row index
\param nrl upper matrix row index
\param ncl lower matrix column index
\param ncl upper matrix column index
*/
void d3_array::allocate(
  const ad_integer& sl, const ad_integer& sh,
  const index_type& nrl, const index_type& nrh,
  const index_type& ncl, const index_type& nch)
{
  if (int(sl) > int(sh))
  {
    allocate();
  }
  else
  {
    if ((nrl.isinteger() && (sl !=nrl.indexmin() || sh !=nrl.indexmax()))
       || (nrh.isinteger() && (sl !=nrh.indexmin() || sh !=nrh.indexmax())))
    {
      cerr << "Incompatible d3_array bounds in " << __FILE__ << ':' << __LINE__ << ".\n";
      ad_exit(1);
    }
    if ((shape = new three_array_shape(sl, sh)) == 0)
    {
      cerr << " Error: d3_array unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    if ((t = new dmatrix[slicesize()]) == 0)
    {
      cerr << " Error: d3_array unable to allocate memory in "
           << __FILE__ << ':' << __LINE__ << '\n';
      ad_exit(1);
    }
    t -= indexmin();
    for (int i = sl; i <= sh; ++i)
    {
      t[i].allocate(nrl[i], nrh[i], ncl[i], nch[i]);
    }
  }
}
    REQUIRE_THROWS_AS(index.get(1), const osmium::not_found&);
    REQUIRE_THROWS_AS(index.get(5), const osmium::not_found&);
    REQUIRE_THROWS_AS(index.get(100), const osmium::not_found&);

    REQUIRE(index.get_noexcept(id1) == osmium::Location{});
    REQUIRE(index.get_noexcept(id2) == osmium::Location{});
    REQUIRE(index.get_noexcept(0) == osmium::Location{});
    REQUIRE(index.get_noexcept(1) == osmium::Location{});
    REQUIRE(index.get_noexcept(5) == osmium::Location{});
    REQUIRE(index.get_noexcept(100) == osmium::Location{});
}

TEST_CASE("Map Id to location: Dummy") {
    using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;

    index_type index1;

    REQUIRE(0 == index1.size());
    REQUIRE(0 == index1.used_memory());

    test_func_all<index_type>(index1);

    REQUIRE(0 == index1.size());
    REQUIRE(0 == index1.used_memory());
}

TEST_CASE("Map Id to location: DenseMemArray") {
    using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;

    index_type index1;
    index1.reserve(1000);
Esempio n. 8
0
ad_integer::ad_integer(const index_type& it) : d(it.integer()) {}
void PrewaveletGridGenerator::addNeighbours(index_type& index,
    size_t current_dim, level_t target_level,
    GridStorage::grid_iterator& iter,
    GridStorage::grid_iterator& shadowIter) {

  level_t sum = 0;

  for (size_t d = 0; d < storage->dim(); ++d) {
    index_t current_index;
    level_t current_level;
    iter.get(d, current_level, current_index);
    sum += current_level;
  }

  if (sum == target_level) {
    GridStorage::index_pointer new_index = new GridStorage::index_type(
      storage->dim());

    if (storage->end(iter.seq()) && shadowstorage->end(shadowIter.seq())) {
      // Ok, point is neither in storage, nor in shadowstorage ...
      // check if the border of index and iter touching
      for (size_t d = 0; d < storage->dim(); ++d) {
        index_t target_index;
        level_t target_level;

        index_t current_index;
        level_t current_level;

        iter.get(d, current_level, current_index);
        index.get(d, target_level, target_index);

        new_index->set(d, current_level, current_index);

        // The index cast to int is required to allow a negative index
        int target_left =
          static_cast<int>((1.0 / (1 << target_level))
                           * static_cast<float_t>(
                             static_cast<int>(target_index) - 3));
        int target_right =
          static_cast<int>((1.0 / (1 << target_level))
                           * static_cast<float_t>(
                             static_cast<int>(target_index) + 3));
        int current_left =
          static_cast<int>((1.0 / (1 << current_index))
                           * static_cast<float_t>(
                             static_cast<int>(current_level) + 3));
        int current_right =
          static_cast<int>((1.0 / (1 << current_index))
                           * static_cast<float_t>(
                             static_cast<int>(current_level) + 3));

        if (!(current_right > target_left || current_left
              < target_right)) {
          return;
          delete new_index;
        }
      }

      // Yepp, the supports touching each other! Add point to shadow!
      shadowstorage->insert(*new_index);
      delete new_index;
      // Call for parents
      insertParents(iter, shadowIter);
    }

    return;
  } else if (sum > target_level) {
    return;
  }

  for (size_t d = current_dim; d < storage->dim(); d++) {
    index_t save_index;
    level_t save_level;
    iter.get(d, save_level, save_index);  // Save current index

    iter.leftChild(d);
    shadowIter.leftChild(d);
    addNeighbours(index, d, target_level, iter, shadowIter);
    iter.set(d, save_level, save_index);  // reset index
    shadowIter.set(d, save_level, save_index);  // reset index

    iter.rightChild(d);
    shadowIter.rightChild(d);
    addNeighbours(index, d, target_level, iter, shadowIter);
    iter.set(d, save_level, save_index);  // reset index
    shadowIter.set(d, save_level, save_index);
  }
}
Esempio n. 10
0
 static iterator insert(index_type& i,iterator it,const value_type& v)
 {
   return i.insert(it,v).first;
 }
Esempio n. 11
0
 static iterator insert(index_type& i,const value_type& v)
 {
   return i.push_back(v).first;
 }
Esempio n. 12
0
void test_tensor_crs_matrix( const size_t M , const size_t N , const bool print = false )
{
  const size_t length = N * N * N ;

  typedef IntType value_type ; // to avoid comparison round-off differences
  typedef KokkosArray::View<value_type**,KokkosArray::LayoutLeft,Device>
    block_vector_type ;

  typedef KokkosArray::SparseProductTensor< 3 , IntType , Device > block_spec ;
  typedef KokkosArray::BlockCrsMatrix< block_spec , value_type , Device > matrix_type ;

  typedef typename matrix_type::graph_type      graph_type ;
  typedef KokkosArray::ProductTensorIndex<3,Device>  index_type ;

  matrix_type matrix ;

  generate_matrix( M , N , matrix );

  block_vector_type x = block_vector_type( "x" , M , length );
  block_vector_type y = block_vector_type( "y" , M , length );

  typename block_vector_type::HostMirror hx = KokkosArray::create_mirror( x );
  typename block_vector_type::HostMirror hy = KokkosArray::create_mirror( y );

  for ( size_t i = 0 ; i < length ; ++i ) {
    for ( size_t j = 0 ; j < M ; ++j ) {
      hx(j,i) = 1 + j + 10 * i ;
    }
  }

  KokkosArray::deep_copy( x , hx );

  KokkosArray::multiply( matrix , x , y );

  KokkosArray::deep_copy( hy , y );

  // Check answer:

  typename graph_type::HostMirror h_graph =
    KokkosArray::create_mirror( matrix.graph );

  std::map< index_type , IntType > tensor_input ;

  generate_tensor( M , tensor_input );

  for ( size_t outer_row = 0 ; outer_row < length ; ++outer_row ) {
    const size_t outer_entry_begin = h_graph.row_map[outer_row];
    const size_t outer_entry_end   = h_graph.row_map[outer_row+1];

    for ( size_t inner_row = 0 ; inner_row < M ; ++inner_row ) {

      value_type value = 0 ;

      for ( size_t outer_entry = outer_entry_begin ;
                   outer_entry < outer_entry_end ; ++outer_entry ) {

        const size_t outer_column = h_graph.entries( outer_entry );

        for ( typename std::map< index_type , IntType >::iterator
              iter =  tensor_input.begin() ;
              iter != tensor_input.end() ; ++iter ) {

          const index_type index = (*iter).first ;
          const IntType    coeff = (*iter).second ;

          size_t i , j ;

          if ( inner_row == index.coord(2) ) {
            i = index.coord(0);
            j = index.coord(1);
          }
          else if ( inner_row == index.coord(1) ) {
            i = index.coord(0);
            j = index.coord(2);
          }
          else if ( inner_row == index.coord(0) ) {
            i = index.coord(1);
            j = index.coord(2);
          }
          else {
            continue ;
          }

          const IntType ai = generate_matrix_value( i , outer_row , outer_column );
          const IntType aj = generate_matrix_value( j , outer_row , outer_column );

          value += coeff * ( i == j ? ( ai * hx( i , outer_column ) )
                                    : ( ai * hx( j , outer_column ) +
                                        aj * hx( i , outer_column ) ) );
        }
      }

      if ( value != hy(inner_row,outer_row) ) {
        std::ostringstream msg ;
        msg << "correctness test failed "
            << value << " != " << hy(inner_row,outer_row)
            << " = hy( " << inner_row << "," << outer_row << ")" ;
        throw std::runtime_error(msg.str());
      }
      else if ( print ) {
        std::cout << " = hy( " << inner_row << "," << outer_row << ") = "
                  << hy( inner_row , outer_row ) << std::endl ;
      }
    }
  }
}
Esempio n. 13
0
 void swap(index_wcsearch3& ir)
 {
     if (this != &ir) {
         index.swap(ir.index);
     }
 }
Esempio n. 14
0
 void load(std::istream& in)
 {
     index.load(in);
 }
Esempio n. 15
0
 size_type serialize(std::ostream& out, sdsl::structure_tree_node* v=NULL, std::string name="")const
 {
     return index.serialize(out, v, name);
 }