void append( List fillVecs) { // "append" fill oldmat w/ // we will loop through cols, filling retmat in with the vectors in list // then update retmat_size to index the next free // newLenths isn't used, added for compatibility std::size_t sizeOld, sizeAdd, sizeNew, icol; NumericVector fillTmp; // check that number of vectors match if ( nvec != fillVecs.size()) { throw std::range_error("In append(): dimension mismatch"); } for (icol = 0; icol<nvec; icol++){ // vector to append fillTmp = fillVecs[icol]; // compute lengths sizeOld = lengths[icol]; sizeAdd = fillTmp.size(); sizeNew = sizeOld + sizeAdd; // grow data matrix as needed if ( sizeNew > allocLen) { grow(sizeNew); } // iterator for col to fill NumericMatrix::Column dataCol = data(_, icol); // fill row of return matrix, starting at first non-zero elem std::copy( fillTmp.begin(), fillTmp.end(), dataCol.begin() + sizeOld); // update size of retmat lengths[icol] = sizeNew; } }
// [[Rcpp::export]] double runit_NumericMatrix_column( NumericMatrix m ){ NumericMatrix::Column col = m.column(0) ; return std::accumulate( col.begin(), col.end(), 0.0 ) ; }