本文整理汇总了C++中rcpp::IntegerVector::end方法的典型用法代码示例。如果您正苦于以下问题:C++ IntegerVector::end方法的具体用法?C++ IntegerVector::end怎么用?C++ IntegerVector::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcpp::IntegerVector
的用法示例。
在下文中一共展示了IntegerVector::end方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
//.........这里部分代码省略.........
示例8: 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)];
}
示例9: nRoots
//[[Rcpp::export]]
int nRoots (Rcpp::IntegerVector ances) {
int ans = std::count (ances.begin(), ances.end(), 0);
return ans;
}
示例10: 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;
}
示例11: 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;
}
示例12: index
int index(const int val, Rcpp::IntegerVector vec) {
int ind = std::find(vec.begin(), vec.end(), val) - vec.begin();
return ind;
}