예제 #1
0
파일: main.cpp 프로젝트: merckhung/homework
int main(int argc, const char * argv[]) {
  std::unique_ptr<merck::Graph<MyData>> mygraph;
  mygraph.reset(new merck::Graph<MyData>);

  if (mygraph.get() == nullptr) {
    std::cerr << "Out of memory\n";
    return 0;
  }

  MyData data_(123, 567);

  // Add vertices
  data_.SetLength(99);
  data_.SetWidth(128);
  mygraph->AddVertex(12, data_);

  data_.SetLength(189);
  data_.SetWidth(283);
  mygraph->AddVertex(16, data_);

  // Dump vertices
  mygraph->DumpVertices();

  std::cout << "Done\n";
  return 0;
}
예제 #2
0
 /**
  * \brief Return a pointer to the beginning of a boundary condition face
  */
 BVal_t get_face(int group, int angle, Normal norm)
 {
     assert(angle < n_angle_);
     assert(group < n_group_);
     int off = bc_per_group_ * group + offset_(angle, (int)norm);
     return BVal_t(size_[angle][(int)norm], &data_(off));
 }
swakDataEntry<Type>::swakDataEntry(
    const word& entryName,
    const dictionary& dict,
    bool readEntryType
)
:
    DataEntry<Type>(entryName)
{
    if(readEntryType) {
        Istream& is(dict.lookup(entryName));
        word entryType(is);

        dictionary d(is);
        data_.set(
            new dictionary(
                dict,
                d
            )
        );
    } else {
        data_.set(
            new dictionary(
                dict,
                dict.subDict(entryName)
            )
        );
    }
    expression_=exprString(
        data_->lookup("expression"),
        data_()
    );
    independentVariableName_=word(data_->lookup("independentVariableName"));
}
예제 #4
0
NT2_TEST_CASE_TPL(transform_binary_bad_sized_unroll4, BOOST_SIMD_SIMD_TYPES )
{
  typedef typename boost::simd::input_iterator<T>   it_;
  typedef typename boost::simd::output_iterator<T> out_;
  typedef typename boost::simd::pack<T> p_t;
  static const std::size_t card = boost::simd::meta::cardinal_of<p_t>::value;
  std::vector<T, boost::simd::memory::allocator<T> >   data(19*card);
  std::vector<T, boost::simd::memory::allocator<T> >   data_(19*card);
  std::vector<T, boost::simd::memory::allocator<T> > result(19*card);
  it_ dbegin  = boost::simd::input_begin(&data[0]);
  it_ dbegin_ = boost::simd::input_begin(&data_[0]);
  it_ dend    = boost::simd::input_end(&data[0]+19*card);
  out_ rbegin = boost::simd::output_begin(&result[0]);

  for(size_t i=0; i<19*card; ++i) { data[i] = T(i%card); data_[i] = T(i%card); }

  boost::simd::transform( dbegin, dend, dbegin_, rbegin, sum_<p_t>()
                        , boost::simd::meta::unroll<4>());

  typename std::vector<T, boost::simd::memory::allocator<T> >::iterator i = result.begin();
  typename std::vector<T, boost::simd::memory::allocator<T> >::iterator j = data.begin();
  typename std::vector<T, boost::simd::memory::allocator<T> >::iterator j_ = data_.begin();

  for(i = result.begin(); i != result.end(); ++i, ++j, ++j_)
  {
    NT2_TEST_EQUAL( *i, (*j+*j_));
  }
}
예제 #5
0
파일: Feature.cpp 프로젝트: rvbust/Open3D
std::shared_ptr<Feature> ComputeFPFHFeature(const PointCloud &input,
        const KDTreeSearchParam &search_param/* = KDTreeSearchParamKNN()*/)
{
    auto feature = std::make_shared<Feature>();
    feature->Resize(33, (int)input.points_.size());
    if (input.HasNormals() == false) {
        PrintDebug("[ComputeFPFHFeature] Failed because input point cloud has no normal.\n");
        return feature;
    }
    KDTreeFlann kdtree(input);
    auto spfh = ComputeSPFHFeature(input, kdtree, search_param);
#ifdef _OPENMP
#pragma omp parallel for schedule(static)
#endif
    for (int i = 0; i < (int)input.points_.size(); i++) {
        const auto &point = input.points_[i];
        std::vector<int> indices;
        std::vector<double> distance2;
        if (kdtree.Search(point, search_param, indices, distance2) > 1) {
            double sum[3] = {0.0, 0.0, 0.0};
            for (size_t k = 1; k < indices.size(); k++) {
                // skip the point itself
                double dist = distance2[k];
                if (dist == 0.0)
                    continue;
                for (int j = 0; j < 33; j++) {
                    double val = spfh->data_(j, indices[k]) / dist;
                    sum[j / 11] += val;
                    feature->data_(j, i) += val;
                }
            }
            for (int j = 0; j < 3; j++)
                if (sum[j] != 0.0) sum[j] = 100.0 / sum[j];
            for (int j = 0; j < 33; j++) {
                feature->data_(j, i) *= sum[j / 11];
                // The commented line is the fpfh function in the paper.
                // But according to PCL implementation, it is skipped.
                // Our initial test shows that the full fpfh function in the
                // paper seems to be better than PCL implementation. Further
                // test required.
                feature->data_(j, i) += spfh->data_(j, i);
            }
        }
    }
    return feature;
}
예제 #6
0
 /**
  * \brief Return a pointer to the beginning of the boundary values for
  * the given group and angle. Includes all faces
  */
 BVal_t get_boundary(int group, int angle)
 {
     assert(angle < n_angle_);
     assert(group < n_group_);
     int size = size_[angle][0] + size_[angle][1] + size_[angle][2];
     int off  = bc_per_group_ * group + offset_(angle, 0);
     return BVal_t(size, &data_(off));
 }
예제 #7
0
void image_32::composite_pixel(unsigned op, int x,int y, unsigned c, unsigned cover, double opacity)
{
    using color_type = agg::rgba8;
    using value_type = color_type::value_type;
    using order_type = agg::order_rgba;
    using blender_type = agg::comp_op_adaptor_rgba<color_type,order_type>;

    if (checkBounds(x,y))
    {
        unsigned rgba = data_(x,y);
        unsigned ca = (unsigned)(((c >> 24) & 0xff) * opacity);
        unsigned cb = (c >> 16 ) & 0xff;
        unsigned cg = (c >> 8) & 0xff;
        unsigned cr = (c & 0xff);
        blender_type::blend_pix(op, (value_type*)&rgba, cr, cg, cb, ca, cover);
        data_(x,y) = rgba;
    }
}
예제 #8
0
 void push_back(uint64_t value) {
     uint64_t encoded = fib_.encode(value);
     uint64_t n_digits = core::Register(encoded).n_digits();
     if(data_.size() < tail_ + n_digits){
         data_.resize((tail_ + n_digits) * 2);
     }
     data_(tail_, tail_ + n_digits) = encoded;
     tail_ += n_digits;
 }
예제 #9
0
UBLASMatrix::UBLASMatrix( const std::vector<std::vector<double>>& mat)
	: data_(mat.size(), mat[0].size(), 0.0)
{
	for( unsigned int i = 0; i < mat.size(); ++i )
	{
		for( unsigned int j = 0; j < mat.size(); ++j )
			data_(i,j) = mat[i][j];
	};
};
예제 #10
0
StkFloat FileWvIn :: tick( unsigned int channel )
{
#if defined(_STK_DEBUG_)
  if ( channel >= data_.channels() ) {
    oStream_ << "FileWvIn::tick(): channel argument and soundfile data are incompatible!";
    handleError( StkError::FUNCTION_ARGUMENT );
  }
#endif

  if ( finished_ ) return 0.0;

  if ( time_ < 0.0 || time_ > (StkFloat) ( file_.fileSize() - 1.0 ) ) {
    for ( unsigned int i=0; i<lastFrame_.size(); i++ ) lastFrame_[i] = 0.0;
    finished_ = true;
    return 0.0;
  }

  StkFloat tyme = time_;
  if ( chunking_ ) {

    // Check the time address vs. our current buffer limits.
    if ( ( time_ < (StkFloat) chunkPointer_ ) ||
         ( time_ > (StkFloat) ( chunkPointer_ + chunkSize_ - 1 ) ) ) {

      while ( time_ < (StkFloat) chunkPointer_ ) { // negative rate
        chunkPointer_ -= chunkSize_ - 1; // overlap chunks by one frame
        if ( chunkPointer_ < 0 ) chunkPointer_ = 0;
      }
      while ( time_ > (StkFloat) ( chunkPointer_ + chunkSize_ - 1 ) ) { // positive rate
        chunkPointer_ += chunkSize_ - 1; // overlap chunks by one frame
        if ( chunkPointer_ + chunkSize_ > file_.fileSize() ) // at end of file
          chunkPointer_ = file_.fileSize() - chunkSize_;
      }

      // Load more data.
      file_.read( data_, chunkPointer_, normalizing_ );
    }

    // Adjust index for the current buffer.
    tyme -= chunkPointer_;
  }

  if ( interpolate_ ) {
    for ( unsigned int i=0; i<lastFrame_.size(); i++ )
      lastFrame_[i] = data_.interpolate( tyme, i );
  }
  else {
    for ( unsigned int i=0; i<lastFrame_.size(); i++ )
      lastFrame_[i] = data_( (size_t) tyme, i );
  }

  // Increment time, which can be negative.
  time_ += rate_;

  return lastFrame_[channel];
}
예제 #11
0
	JsonReader& data(Type& data, const std::string& name, Args... args){    	
		auto child = tree_.get_child_optional(name);
		if(child){
			data_(*child,data,name,IsStructure<Type>(),IsArray<Type>());
		} else {
			if(not optional_){
				STENCILA_THROW(Exception,"JSON does not include property.\n  name: "+name);
			}
		}
		return *this;
	}
CommonValueExpressionDriver &swakDataEntry<Type>::driver()
{
    if(!driver_.valid()) {
        driver_=CommonValueExpressionDriver::New(
            data_()
        );
        driver_->createWriterAndRead(
            "dataEntry_"+data_->name().name()+"_"+this->name()
        );
    }

    return driver_();
}
예제 #13
0
파일: FileLoop.cpp 프로젝트: thestk/stk
void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize, bool doInt2FloatScaling )
{
  // Call close() in case another file is already open.
  this->closeFile();

  // Attempt to open the file ... an error might be thrown here.
  file_.open( fileName, raw );

  // Determine whether chunking or not.
  if ( file_.fileSize() > chunkThreshold_ ) {
    chunking_ = true;
    chunkPointer_ = 0;
    data_.resize( chunkSize_ + 1, file_.channels() );
  }
  else {
    chunking_ = false;
    data_.resize( file_.fileSize() + 1, file_.channels() );
  }

  if ( doInt2FloatScaling )
    int2floatscaling_ = true;
  else
    int2floatscaling_ = false;

  // Load all or part of the data.
  file_.read( data_, 0, int2floatscaling_ );

  if ( chunking_ ) { // If chunking, save the first sample frame for later.
    firstFrame_.resize( 1, data_.channels() );
    for ( unsigned int i=0; i<data_.channels(); i++ )
      firstFrame_[i] = data_[i];
  }
  else {  // If not chunking, copy the first sample frame to the last.
    for ( unsigned int i=0; i<data_.channels(); i++ )
      data_( data_.frames() - 1, i ) = data_[i];
  }

  // Resize our lastOutputs container.
  lastFrame_.resize( 1, file_.channels() );

  // Close the file unless chunking
  fileSize_ = file_.fileSize();
  if ( !chunking_ ) file_.close();

  // Set default rate based on file sampling rate.
  this->setRate( data_.dataRate() / Stk::sampleRate() );

  if ( doNormalize & !chunking_ ) this->normalize();

  this->reset();
}
예제 #14
0
void Image32::set_rectangle(unsigned x0,unsigned y0,const ImageData32& data)
{
    if (x0>=width_ || y0>=height_) return;

    unsigned w=std::min(data.width(),width_-x0);
    unsigned h=std::min(data.height(),height_-y0);

    for (unsigned y=0; y<h; ++y)
    {
        for (unsigned x=0; x<w; ++x)
        {
            if ((data(x,y) & 0xff000000))
            {
                data_(x0+x,y0+y)=data(x,y);
            }
        }
    }
}
예제 #15
0
 Type const& operator[](size_t pos) const { return data_(size)[pos]; }
예제 #16
0
UBLASVector::UBLASVector( const std::vector<double>& vec)
{
	for( unsigned int i = 0; i < vec.size(); ++i )
		data_(i) = vec[i];
};
예제 #17
0
inline typename image_view<T>::pixel_type const& image_view<T>::operator() (std::size_t i, std::size_t j) const
{
    return data_(i + x_,j + y_);
}
예제 #18
0
 Type const& back() const { return data_(size_)[size_ - 1]; }
예제 #19
0
파일: Block.cpp 프로젝트: tamis-laan/thesis
	thrust::device_ptr<float>       Block::data(int t, int n, int c, int h)        {return data_(t,n,c,h);    }
예제 #20
0
 Type const& front() const { return data_(size_)[0]; }
예제 #21
0
 Type& back() { return data_(size_)[size_ - 1]; }
예제 #22
0
 Type const* data() const { return data_(size_); }
예제 #23
0
 Type& front() { return data_(size_)[0]; }
예제 #24
0
int main(int argc, const char *argv[])
{
    string ftx = "./data/test_x.txt";
    string fty = "./data/test_y.txt";
    int epoch = 100;
    int batch_size = 0;
    double gamma = 0.1; // learning rate
    int k = 1; //Contrastive Divergence k

    int hls[] = {500, 500, 900};
    int n_layers = sizeof(hls) / sizeof(hls[0]);
    int n_lables = 10;
    double lbd = 0.0002; // weight cost

    Conf conf(ftx, fty, epoch, batch_size, hls, k, gamma, n_layers, n_lables, lbd);
    Dataset data(conf);

    /*// test rbm
      RBM rbm(data.N, data.n_f, 400, NULL, NULL, NULL, lbd, 0);

      for(int i=0; i<epoch; i++)
      {
      cout << "epoch: " << i << endl;
      for(int j=0; j<data.N; j++)
      {
      double *x = new double[data.n_f];
      for(int f=0; f<data.n_f; f++)
      x[f] = data.X[j][f];
      rbm.train(x, gamma, k);
      delete[] x;


      }
      ofstream fout("./model/W1");
      for(int j=0; j<rbm.n_visible; j++)
      {
      for(int l=0; l<rbm.n_hidden; l++)
      {
      fout << rbm.W[l][j] << " ";
      }
      fout << endl;
      }
      fout << flush;
      fout.close();


      }
      */
    //test lr

    /*
       LR lr(data, conf);
       for(int i=0; i<epoch; i++)
       {
       cout << "epoch: " << i << endl;
       for(int j=0; j<data.N; j++)
       {
       double *x = new double[lr.n_features];
       for(int f=0; f<lr.n_features; f++)
       x[f] = data.X[j][f];
       int *y = new int[lr.n_labels];
       y[int(data.Y[j])] = 1;

       lr.train(x, y, gamma);
       delete[] x;
       delete[] y;
       }
       }
       for(int j=0; j<data.N; j++)
       {
       double *x = new double[lr.n_features];
       for(int f=0; f<lr.n_features; f++)
       x[f] = data.X[j][f];
       double *y = new double[lr.n_labels];

       lr.predict(x, y);
       cout <<data.Y[j]<<": ";
       for(int i=0; i<lr.n_labels; i++)
       cout <<y[i]<<" ";
       cout<<endl;
       delete[] y;
       }
       */


    DBN dbn(data, conf);
    dbn.pretrain(data, conf);
    for(int i=0; i<=n_layers; i++)
    {
        char str[] = "./model/W";
        char W_l[128];
        sprintf(W_l, "%s%d", str, (i+1));

        ofstream fout(W_l);
        if(i < n_layers)
        {
            for(int j=0; j<dbn.rbm_layers[i]->n_visible; j++)
            {
                for(int l=0; l<dbn.rbm_layers[i]->n_hidden; l++)
                {
                    fout << dbn.rbm_layers[i]->W[l][j] << " ";
                }
                fout << endl;
            }
        }
        else
        {
            for(int j=0; j<dbn.lr_layer->n_features; j++)
            {
                for(int l=0; l<dbn.lr_layer->n_labels; l++)
                {
                    fout << dbn.lr_layer->W[l][j] << " ";
                }
                fout << endl;
            }
        }

        fout << flush;
        fout.close();

    }
    dbn.finetune(data, conf);

    ftx = "./data/train_x.txt";
    fty = "./data/train_y.txt";

    Conf conf_(ftx, fty, epoch, batch_size, hls, k, gamma, n_layers, n_lables, lbd);
    Dataset data_(conf_);


    double acc_num = 0;
    for(int j=0; j<data_.N; j++)
    {
        double *x = new double[data_.n_f];
        for(int f=0; f<data_.n_f; f++)
            x[f] = data_.X[j][f];
        double *y = new double[conf.n_labels];
        int true_label = int(data_.Y[j]);

        if(dbn.predict(x, y, true_label) == 1)
            acc_num++;
        delete[] x;
        delete[] y;

        cout << j <<": Accuracy=" << acc_num/(j+1) <<endl;
    }

    return 0;
}
예제 #25
0
 Type* data() { return data_(size_); }
예제 #26
0
 Type& operator[](size_t pos) { return data_(size)[pos]; }
예제 #27
0
int main(void)
{
   int           c;
#ifdef ALLEGRO_H
   unsigned char ch;

   allegro_init();
   install_keyboard();
#endif
   dzcomm_init();


   /* Set up comm1 */

   if ((port1 = comm_port_init(_com1)) == NULL) {
      dz_print_comm_err();
      exit(1);
   }

   if (comm_port_load_settings(port1, "exterm1.ini") == 0) {
       dz_print_comm_err();
       exit(1);
   }

   if (!comm_port_install_handler(port1)) {
      dz_print_comm_err();
      exit(1);
   }

   cur_port = port1;

#ifdef ALLEGRO_H
   /* Set up comm2 */

   if ((port2 = comm_port_init(_com2)) == NULL) {
       dz_print_comm_err();
       exit(1);
   }

   if (comm_port_load_settings(port2, "exterm2.ini") == 0) {
       dz_print_comm_err();
       exit(1);
   }

   if (!comm_port_install_handler(port2)) {
      dz_print_comm_err();
      exit(1);
   }
#else
   port2 = port1;
#endif

#ifdef ALLEGRO_H
   initialise_screen();
#else
   printf("Press Ctrl-C for a messy quit.\n");
   printf("\nCurrent port is: %s.\n\n", cur_port->szName);
#endif

   while(1) {

#ifdef ALLEGRO_H
      if (keypressed()) {
         c  = readkey();
         ch = ascii_(c);
         if (ctrl_(c,'C'))  {
            return (0);
         }
	 else if (ctrl_(c,'B')) {
	    comm_port_send_break(cur_port, 500);
	 }
         else if (ctrl_(c,'M')) {
            if (cur_port == port2) cur_port = port1;
            else                   cur_port = port2;
	    inform_port_change();
         }
         else comm_port_out(cur_port, ch);
      }
#endif

      if ((c = comm_port_test(cur_port)) != -1) {
	 show_received_character(data_(c));
      }
   }

}
예제 #28
0
파일: FileLoop.cpp 프로젝트: thestk/stk
StkFloat FileLoop :: tick( unsigned int channel )
{
#if defined(_STK_DEBUG_)
  if ( channel >= data_.channels() ) {
    oStream_ << "FileLoop::tick(): channel argument and soundfile data are incompatible!";
    handleError( StkError::FUNCTION_ARGUMENT );
  }
#endif

  if ( finished_ ) return 0.0;

  // Check limits of time address ... if necessary, recalculate modulo
  // fileSize.
  while ( time_ < 0.0 )
    time_ += fileSize_;
  while ( time_ >= fileSize_ )
    time_ -= fileSize_;

  StkFloat tyme = time_;
  if ( phaseOffset_ ) {
    tyme += phaseOffset_;
    while ( tyme < 0.0 )
      tyme += fileSize_;
    while ( tyme >= fileSize_ )
      tyme -= fileSize_;
  }

  if ( chunking_ ) {

    // Check the time address vs. our current buffer limits.
    if ( ( time_ < (StkFloat) chunkPointer_ ) ||
         ( time_ > (StkFloat) ( chunkPointer_ + chunkSize_ - 1 ) ) ) {

      while ( time_ < (StkFloat) chunkPointer_ ) { // negative rate
        chunkPointer_ -= chunkSize_ - 1; // overlap chunks by one frame
        if ( chunkPointer_ < 0 ) chunkPointer_ = 0;
      }
      while ( time_ > (StkFloat) ( chunkPointer_ + chunkSize_ - 1 ) ) { // positive rate
        chunkPointer_ += chunkSize_ - 1; // overlap chunks by one frame
        if ( chunkPointer_ + chunkSize_ > fileSize_ ) { // at end of file
          chunkPointer_ = fileSize_ - chunkSize_ + 1; // leave extra frame at end of buffer
          // Now fill extra frame with first frame data.
          for ( unsigned int j=0; j<firstFrame_.channels(); j++ )
            data_( data_.frames() - 1, j ) = firstFrame_[j];
        }
      }

      // Load more data.
      file_.read( data_, chunkPointer_, int2floatscaling_ );
    }

    // Adjust index for the current buffer.
    tyme -= chunkPointer_;
  }

  if ( interpolate_ ) {
    for ( unsigned int i=0; i<lastFrame_.size(); i++ )
      lastFrame_[i] = data_.interpolate( tyme, i );
  }
  else {
    for ( unsigned int i=0; i<lastFrame_.size(); i++ )
      lastFrame_[i] = data_( (size_t) tyme, i );
  }

  // Increment time, which can be negative.
  time_ += rate_;

  return lastFrame_[channel];
}
예제 #29
0
파일: Block.cpp 프로젝트: tamis-laan/thesis
	thrust::device_reference<float> Block::data(int t, int n, int c, int h, int w) {return data_(t,n,c,h,w);  }
예제 #30
0
	JsonWriter& data(Type& data, const std::string& name, Args... args){    	
		data_(data,name,IsStructure<Type>(),IsArray<Type>());
		return *this;
	}