当前位置: 首页>>代码示例>>C++>>正文


C++ IntegerVector::push_back方法代码示例

本文整理汇总了C++中rcpp::IntegerVector::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ IntegerVector::push_back方法的具体用法?C++ IntegerVector::push_back怎么用?C++ IntegerVector::push_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rcpp::IntegerVector的用法示例。


在下文中一共展示了IntegerVector::push_back方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetAllPoints

RcppExport SEXP GetAllPoints(SEXP x,SEXP n,SEXP c) {

    try {
	Rcpp::XPtr< flann::Index<flann::L2<float> >  > index(x);
	Rcpp::NumericVector npoints(n);
	Rcpp::NumericVector cn(c);
	int colNum = cn[0];

	float *data = new float[colNum];
	
	for(int i=0;i<colNum;i++) {
	    data[i] = 0;
	    i++;
	}

	flann::Matrix<float> dataset = flann::Matrix<float>(data,1,colNum);

	delete [] data;

	std::vector< std::vector<int> > indices;
	std::vector< std::vector<float> > dists;

	index->knnSearch(dataset,indices,dists,npoints[0],flann::SearchParams(-1));

	std::sort (indices[0].begin(), indices[0].end()); 

	Rcpp::NumericMatrix results(indices[0].size(), colNum);
	Rcpp::IntegerVector rownames;

	int num = indices[0].size();

	//#pragma omp parallel for ordered schedule(dynamic)
	for(int i=0;i<num;i++) {
	    float* indexPoint = index->getPoint(indices[0][i]);
	    for(int j=0;j<colNum;j++) {
		results(i,j)=(*(indexPoint+j));
	    }

	    //#pragma omp ordered
	    rownames.push_back(indices[0][i]);
	}

	Rcpp::List dimnms = Rcpp::List::create(rownames, Rcpp::Range(1,colNum));
	results.attr("dimnames") = dimnms;

	return results;

    } catch( std::exception &ex ) {		// or use END_RCPP macro
	forward_exception_to_r( ex );
    } catch(...) {
	::Rf_error( "c++ exception (unknown reason)" );
    }
    return R_NilValue; // -Wall
}
开发者ID:rforge,项目名称:clusterds,代码行数:54,代码来源:FLANN.cpp

示例2: r_classify

Rcpp::IntegerVector r_classify(const treetree::tree<T>& tr,
                               const std::vector<std::string>& labels) {
  treetree::tree<forest::node<int> > tmp = classify(tr, labels);
  Rcpp::IntegerVector ret;
  std::vector<std::string> names;
  names.reserve(tr.size());
  for (treetree::tree<forest::node<int> >::const_pre_iterator
         it = tmp.begin(); it != tmp.end(); ++it) {
    ret.push_back(it->data_);
    names.push_back(it->label_);
  }
  ret.attr("names") = names;
  return ret;
}
开发者ID:richfitz,项目名称:forest,代码行数:14,代码来源:misc_post_rcpp.hpp

示例3: rank_variants

// [[Rcpp::export]]
Rcpp::DataFrame rank_variants(Rcpp::DataFrame variants,
                              Rcpp::NumericVector ends,
                              Rcpp::NumericVector score){
  // Rank variants by window and by a vector of scores.
  // Input is a DataFrame of variant information which includes
  // the chromosomal position of each variant.
  // This may be originally derived from a vcf file.  
  // It should also contain information on whether each variant has been masked.
  // Also input is a vector of window ending positions and a vector of scores for each
  // variant.  The scores may be extracted from a vcf file, such
  // as the genotype quality filed (GQ), or any sort of composite score.
  // The variants with the greatest score are given the lowest
  // rank order.
  
  // Sorting on pairs from:
  // http://stackoverflow.com/a/1577627
  
  Rcpp::NumericVector pos = variants["POS"];
  Rcpp::LogicalVector mask = variants["mask"];
  
  Rcpp::NumericVector win_num(score.size());  // Vector of window numbers.
  Rcpp::NumericVector win_rank(score.size()); // Vector to be returned as per window rank.
//  Rcpp::NumericVector rank;   // Vector to hold information for a single 
                              // window which will be sorted.

  // Create a vector of vectors of pairs.
  // There will be a vector of windows,
  // where each window will be a vector of
  // a pair containing a variant's score and position in the window.
//  std::vector< std::vector< std::pair< int, int > > > vec_vec_pair;
  // or
  std::vector< std::pair< float, int > > vec_pair;
  std::vector< std::pair< int, int > > rank_pair;
//  std::vector < int > ranks;
  Rcpp::IntegerVector ranks;
  
  int win = 0;
  int i = 0;  // Variant counter.
  int j = -1;  // Variant within window counter.

  // Iterate to first window.
  while(pos(0) > ends(win)){
    win++;
    }

  for(i=0; i<score.size(); i++){
//    Rcout << "Counter: " << i << " Position: " << pos(i) << "\n";
    Rcpp::checkUserInterrupt();
    if( pos(i) < ends(win) ){
      // Position is within current window.
      win_num(i) = win;
      j++;
      // Handle missing data.
      if(score(i) == NA_REAL || mask(i) == FALSE){
        vec_pair.push_back( std::make_pair( na_int, j) );
      } else {
        vec_pair.push_back( std::make_pair( score(i), j) );
      }

    } else {
      // Begin a new window.

      // Sort vector of pairs for present window.
      // vec_pair contains score and position.
      std::sort(vec_pair.begin(), vec_pair.end(), comparator);
      
      // Rank within the window.
      unsigned int k = 0;
      for(k=0; k<vec_pair.size(); k++){
//        Rcout << "Window number: " << win << ", pair1: " << vec_pair[k].first << ", pair2: " << vec_pair[k].second  << "\n";
          rank_pair.push_back( std::make_pair( vec_pair[k].second, k + 1 ) );
//        Rcout << "Window number: " << win << ", Rpair1: " << rank_pair[k].first << ", Rpair2: " << rank_pair[k].second  << "\n";
      }
      
      // Restore original order.
      // rank_pair contains position and rank.
      std::sort(rank_pair.begin(), rank_pair.end(), minimize);
      
      for(k=0; k<vec_pair.size(); k++){
//        Rcout << "Window number: " << win << ", Rpair1: " << rank_pair[k].first << ", Rpair2: " << rank_pair[k].second  << "\n";
//        Rcout << "Window number: " << win << " Pair number: " << k;
//        Rcout << " Rpair1: " << rank_pair[k].first << " Rpair2: " << rank_pair[k].second << "\n";
//        Rcout << "Pair: " << rank_pair[k].second << "\n";
        if( rank_pair[k].second == na_int ){
          ranks.push_back( NA_INTEGER );
        } else {
          ranks.push_back( rank_pair[k].second );
        }
      }
//      Rcout << "\n";
      // Increment to next window.
      while(pos(i) > ends(win)){win++;}
      win_num(i) = win;
      rank_pair.erase(rank_pair.begin(), rank_pair.end());
      vec_pair.erase(vec_pair.begin(), vec_pair.end());
      j = 0;
      vec_pair.push_back( std::make_pair( score(i), j) );
    }
//    Rcout << "Counter: " << i << " Window: " << win_num(i) << " Position:" << pos(i) << " Score: " << score(i);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的rcpp::IntegerVector::push_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。