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


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

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


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

示例1: subsetCounts

// [[Rcpp::export]]
Rcpp::List subsetCounts(Rcpp::IntegerVector counts, Rcpp::IntegerVector start, Rcpp::IntegerVector width, Rcpp::LogicalVector strand){
	if (start.length() != width.length() || start.length() != strand.length()) Rcpp::stop("provided vectors have different lengths...");
	int nr = start.length();
	int len = counts.length();
	int tot = 0;
	int* S = start.begin(); int* W = width.begin();
	for (int i = 0; i < nr; ++i){
		int s = S[i] - 1;
		int w = W[i]; 
		if (s < 0) Rcpp::stop("negative start positions are invalid");
		if (s + w > len) Rcpp::stop("range exceeds the lengths of the counts vector");
		tot += w;
	}
	
	Rcpp::IntegerVector res(tot); 
	Rcpp::IntegerVector nstart(nr);
	Rcpp::IntegerVector nend(nr);
	int* R = res.begin(); int* C = counts.begin(); int* ST = strand.begin();
	int* NS = nstart.begin(); int* NE = nend.begin();
	int currpos = 0;
	for (int i = 0; i < nr; ++i){
		NS[i] = currpos + 1;
		int w = W[i];
		if (ST[i]) std::copy(C + S[i]-1, C + S[i]-1 + w, R + currpos);
		else std::reverse_copy(C + S[i]-1, C + S[i]-1 + w, R + currpos);
		currpos += w;
		NE[i] = currpos;
	}
	return List::create(_("counts")=res, _("starts")=nstart, _("ends")=nend);
}
开发者ID:al2na,项目名称:cmbr,代码行数:31,代码来源:bamsignals.cpp

示例2: seqC

// [[Rcpp::export]]
Rcpp::NumericVector seqC(double from_, double to_, double by_ = 1.0) {
  int adjust = std::pow(10, std::ceil(std::log10(10 / by_)) - 1);
  int from = adjust * from_;
  int to = adjust * to_;
  int by = adjust * by_;
  
  std::size_t n = ((to - from) / by) + 1;
  Rcpp::IntegerVector res = Rcpp::rep(from, n);
  add_multiple ftor(by);
  
  std::transform(res.begin(), res.end(), res.begin(), ftor);
  return Rcpp::NumericVector(res) / adjust;
}
开发者ID:BENR0,项目名称:satellite,代码行数:14,代码来源:SatelliteCppFun.cpp

示例3: quantileNorm

// [[Rcpp::export]]
Rcpp::IntegerMatrix quantileNorm(Rcpp::IntegerMatrix mat, Rcpp::IntegerVector ref, int nthreads=1, int seed=13){
    if (mat.nrow() != ref.length()) Rcpp::stop("incompatible arrays...");
    if (!std::is_sorted(ref.begin(), ref.end())) Rcpp::stop("ref must be sorted");
    int ncol = mat.ncol();
    int nrow = mat.nrow();
    //allocate new matrix
    Rcpp::IntegerMatrix res(nrow, ncol);
    Mat<int> oldmat = asMat(mat); 
    Mat<int> newmat = asMat(res);
    Vec<int> ref2 = asVec(ref);
    //allocate a seed for each column
    std::seed_seq sseq{seed};
    std::vector<std::uint32_t> seeds(ncol);
    sseq.generate(seeds.begin(), seeds.end());
    
    #pragma omp parallel num_threads(nthreads)
    {
        std::vector<std::pair<int, int> > storage(nrow);//pairs <value, index>
        #pragma omp for 
        for (int col = 0; col < ncol; ++col){
            std::mt19937 gen(seeds[col]);
            qtlnorm(oldmat.getCol(col), ref2, newmat.getCol(col), storage, gen);
        }
    }
    
    res.attr("dimnames") = mat.attr("dimnames");
    return res;
}
开发者ID:SamBuckberry,项目名称:epicseg,代码行数:29,代码来源:normalization.cpp

示例4: Getmk

// Calculate mk = sum_i I(M(ti)=k), k=1, ..., M with m0=0;
// where h=(h0, h1, ..., hM) with h0=0 and d=(d0, d1, ..., dM) with d0=0, dM=R_PosInf
void Getmk(Rcpp::IntegerVector& mk, const Rcpp::IntegerVector& Mt){
  int n = Mt.size();
  std::fill(mk.begin(), mk.end(), 0);
  for (int i=0; i<n; ++i){
    int k = Mt[i];
    mk[k] +=1;
  }
}
开发者ID:cran,项目名称:spBayesSurv,代码行数:10,代码来源:spSurv_Coxph_tools.cpp

示例5: countInSubset

// [[Rcpp::export]]
Rcpp::IntegerVector countInSubset(Rcpp::IntegerVector counts, Rcpp::IntegerVector start, Rcpp::IntegerVector width){
	if (start.length() != width.length()) Rcpp::stop("provided vectors have different lengths...");
	int nr = start.length();
	int len = counts.length();
	Rcpp::IntegerVector res(nr); 
	int* R = res.begin(); int* C = counts.begin();
	int* S = start.begin(); int* W = width.begin();
	for (int i = 0; i < nr; ++i){
		int s = S[i] - 1;
		int w = W[i]; 
		if (s < 0) Rcpp::stop("negative start positions are invalid");
		if (s + w > len) Rcpp::stop("range exceeds the lengths of the counts vector");
		R[i] = sum(C + s, w);
	}
	
	return res;
}
开发者ID:al2na,项目名称:cmbr,代码行数:18,代码来源:bamsignals.cpp

示例6: runtime_error

    Permutation::Permutation(Rcpp::IntegerVector &vv)
	: d_perm(vv),
	  n(vv.size()) {
	int *vpt = vv.begin();
	std::vector<bool> chk(n);
	std::fill(chk.begin(), chk.end(), false);
	for (int i = 0; i < n; i++) {
	    int vi = vpt[i];
	    if (vi < 0 || n <= vi)
		throw runtime_error("permutation elements must be in [0,n)");
	    if (chk[vi])
		throw runtime_error("permutation is not a permutation");
	    chk[vi] = true;
	}
    }
开发者ID:rforge,项目名称:lme4,代码行数:15,代码来源:Permutation.cpp

示例7: countPreClusterMarkers

R_xlen_t countPreClusterMarkers(SEXP preClusterResults_, bool& noDuplicates)
{
	Rcpp::List preClusterResults = preClusterResults_;
	std::vector<int> markers;
	for(Rcpp::List::iterator i = preClusterResults.begin(); i != preClusterResults.end(); i++)
	{
		Rcpp::IntegerVector Rmarkers = *i;
		for(Rcpp::IntegerVector::iterator j = Rmarkers.begin(); j != Rmarkers.end(); j++)
		{
			markers.push_back(*j);
		}
	}
	R_xlen_t nMarkers1 = markers.size();
	std::sort(markers.begin(), markers.end());
	std::vector<int>::iterator lastUnique = std::unique(markers.begin(), markers.end());
	R_xlen_t nMarkers2 = std::distance(markers.begin(), lastUnique);
	noDuplicates = nMarkers1 == nMarkers2;
	return nMarkers1;
}
开发者ID:btmoyers,项目名称:mpMap2,代码行数:19,代码来源:hclustMatrices.cpp

示例8: constructDissimilarityMatrixInternal

SEXP constructDissimilarityMatrixInternal(unsigned char* data, std::vector<double>& levels, int size, SEXP clusters_, int start, const std::vector<int>& currentPermutation)
{
	Rcpp::IntegerVector clusters = Rcpp::as<Rcpp::IntegerVector>(clusters_);
	int minCluster = *std::min_element(clusters.begin(), clusters.end()), maxCluster = *std::max_element(clusters.begin(), clusters.end());
	if(minCluster != 1)
	{
		throw std::runtime_error("Clusters must have consecutive indices starting at 1");
	}
	std::vector<std::vector<int> > groupIndices(maxCluster);
	for(int i = 0; i < clusters.size(); i++)
	{
		groupIndices[clusters[i]-1].push_back(currentPermutation[i + start]);
	}

	std::vector<int> table(levels.size());

	Rcpp::NumericMatrix result(maxCluster, maxCluster);
	for(int rowCluster = 1; rowCluster <= maxCluster; rowCluster++)
	{
		for(int columnCluster = 1; columnCluster <= rowCluster; columnCluster++)
		{
			const std::vector<int>& columnIndices = groupIndices[columnCluster-1];
			const std::vector<int>& rowIndices = groupIndices[rowCluster-1];
			std::fill(table.begin(), table.end(), 0);
			for(std::vector<int>::const_iterator columnMarker = columnIndices.begin(); columnMarker != columnIndices.end(); columnMarker++)
			{
				for(std::vector<int>::const_iterator rowMarker = rowIndices.begin(); rowMarker != rowIndices.end(); rowMarker++)
				{
					int x = *rowMarker, y = *columnMarker;
					if(x < y) std::swap(x, y);
					int byte = data[x *(x + (R_xlen_t)1)/(R_xlen_t)2 + y];
					if(byte == 255) throw std::runtime_error("Values of NA not allowed");
					table[byte]++;
				}
			}
			double sum = 0;
			for(int i = 0; i < table.size(); i++) sum += table[i] * levels[i];
			result(rowCluster-1, columnCluster-1) = result(columnCluster-1, rowCluster-1) = sum / (columnIndices.size() * rowIndices.size());
		}
	}
	return result;
}
开发者ID:btmoyers,项目名称:mpMap2,代码行数:42,代码来源:rawSymmetricMatrix.cpp

示例9: avg_rank

// [[Rcpp::export]]
NumericVector avg_rank(Rcpp::NumericVector x)
{
    R_xlen_t sz = x.size();
    Rcpp::IntegerVector w = Rcpp::seq(0, sz - 1);
    std::sort(w.begin(), w.end(), Comparator(x));

    Rcpp::NumericVector r = Rcpp::no_init_vector(sz);
    R_xlen_t n;
    #pragma omp parallel for
    for (int i = 0; i < sz; i += n) {
        n = 1;
        while (i + n < sz && x[w[i]] == x[w[i + n]]) ++n;
        #pragma omp parallel for
        for (R_xlen_t k = 0; k < n; k++) {
            r[w[i + k]] = i + (n + 1) / 2.;
        }
    }

    return r;
}
开发者ID:JackStat,项目名称:ModelMetrics,代码行数:21,代码来源:auc_.cpp

示例10: read_body_gz

// [[Rcpp::export]]
Rcpp::CharacterMatrix read_body_gz(std::string x,
                                   Rcpp::NumericVector stats,
                                   int nrows = -1,
                                   int skip = 0,
                                   Rcpp::IntegerVector cols = 0,
                                   int convertNA = 1,
                                   int verbose = 1) {

  // NA matrix for unexpected results.
  Rcpp::StringMatrix na_matrix(1,1);
  na_matrix(0,0) = NA_STRING;
  
  
  /*
   * Manage cols vector.
   * The first eight (1-based) columns are mandatory.
   * We can ensure they are there by adding them,
   * sorting and removing adjacent non-identical values.
   */
//  for( int i=9; i >= 1; i-- ){
  for( int i=8; i >= 1; i-- ){
    cols.push_front(i);
  }
  cols.sort();

  // Remove duplicate values using a set.
  std::set<int> s( cols.begin(), cols.end() );
  cols.assign( s.begin(), s.end() );

  cols = cols - 1; // R is 1-based, C is 0-based.

  
  // Initialize matrix for body data.
  // old: Rcpp::CharacterMatrix gt(stats[2], stats[3]);
  int row_num = 0;
  

  if( ( nrows == -1 ) & ( skip == 0 ) ){
    nrows = stats[2];
  } else if ( ( nrows != -1 ) & ( skip == 0 ) ){
    // nrows = nrows;
  } else if ( ( nrows == -1 ) & ( skip > 0) ){
    nrows = stats[2] - skip;
  } else if ( ( nrows != -1 ) & ( skip > 0) ){
    // nrows = nrows;
  } else {
    Rcpp::Rcerr << "failed to calculate return matrix geometry.";
    return na_matrix;
  }
  Rcpp::CharacterMatrix gt( nrows, cols.size() );
  
//  if ( nrows > -1 & skip == 0 ){
//    row_num = nrows;
//  } else if ( nrows == -1 & skip > 0 ){
//    row_num = stats[2] - skip;
//  } else {
//    row_num = stats[2];    
//  }
//  Rcpp::CharacterMatrix gt( row_num, cols.size() );

  row_num = 0;
  
  if( verbose == 1 ){
    Rcpp::Rcout << "Character matrix gt created.\n";
    Rcpp::Rcout << "Character matrix gt rows: ";  Rcpp::Rcout << gt.rows();
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "Character matrix gt cols: ";  Rcpp::Rcout << gt.cols();
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "skip: ";  Rcpp::Rcout << skip;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "nrows: ";  Rcpp::Rcout << nrows;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "row_num: ";  Rcpp::Rcout << row_num;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "\n";
  }

  
  // Create filehandle and open.
  gzFile file;
  file = gzopen (x.c_str(), "r");
  if (! file) {
    Rcpp::Rcerr << "gzopen of " << x << " failed: " << strerror (errno) << ".\n";
    return na_matrix;
  }


  // Because the last line may be incomplete,
  // We'll typically omit it from processing and
  // concatenate it to the first line.
  // But first we'll have to initialize it.
  std::string lastline = "";
  
  // String vector to store the header (^#CHROM...).
  std::vector<std::string> header_vec;
  
  // variant counter.  
  int var_num = 0;

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例11: sample_int

// [[Rcpp::export]]
Rcpp::IntegerVector sample_int(int n, int min, int max) {
    Rcpp::IntegerVector pool = Rcpp::seq(min, max);
    std::random_shuffle(pool.begin(), pool.end());
    return pool[Rcpp::Range(0, n - 1)];
}
开发者ID:bomin8319,项目名称:SU16,代码行数:6,代码来源:IPTM_rcpp.cpp

示例12: nRoots

//[[Rcpp::export]]
int nRoots (Rcpp::IntegerVector ances) {
    int ans = std::count (ances.begin(), ances.end(), 0);
    return ans;
}
开发者ID:rforge,项目名称:phylobase,代码行数:5,代码来源:checkPhylo4.cpp

示例13: getAllNodesSafe

//[[Rcpp::export]]
Rcpp::IntegerVector getAllNodesSafe (Rcpp::IntegerMatrix edge) {
    Rcpp::IntegerVector ans = Rcpp::as_vector(edge);
    Rcpp::IntegerVector tmp = Rcpp::unique(ans);
    std::sort(tmp.begin(), tmp.end());
    return tmp;
}
开发者ID:rforge,项目名称:phylobase,代码行数:7,代码来源:checkPhylo4.cpp

示例14: stl_sort

Rcpp::IntegerVector stl_sort(Rcpp::IntegerVector x) {
  //http://gallery.rcpp.org/articles/sorting/
  Rcpp::IntegerVector y = clone(x);
  std::sort(y.begin(), y.end());
  return y;
}
开发者ID:justinpenz,项目名称:mrgsolve,代码行数:6,代码来源:mrgsolve.cpp

示例15: index

int index(const int val, Rcpp::IntegerVector vec) {
	int ind = std::find(vec.begin(), vec.end(), val) - vec.begin();
	return ind;
}
开发者ID:nverno,项目名称:allometry,代码行数:4,代码来源:maxneb_disc.cpp


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