[Rcpp-devel] efficient ingestion of "sparse csv"

Serguei Sokol serguei.sokol at gmail.com
Wed May 26 17:18:34 CEST 2021


Le 26/05/2021 à 16:36, Vincent Carey a écrit :
> On this theme, the following proved sufficient to ingest and
> convert sparse csv without column headers or row names:
Nice to share your final solution which could be further shorten to smth 
like:

#include "RcppArmadillo.h"
using namespace Rcpp;
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::sp_mat parse_sparse_csv_short(std::string fname) {
    arma::sp_mat D;
    D.load(fname, arma::csv_ascii);
    return D;
}

Best,
Serguei.

> 
> #include "RcppArmadillo.h"
> 
> using namespace Rcpp;
> 
> // [[Rcpp::depends(RcppArmadillo)]]
> // [[Rcpp::export]]
> 
> List parse_sparse_csv_impl(SEXP fname) {
> using namespace Rcpp;
> std::string v = Rcpp::as<std::string>(fname);
> arma::sp_mat D;
> D.load(v, arma::csv_ascii);
> return Rcpp::List::create(Rcpp::Named("sp")=D);
> }
> 
> On Mon, May 10, 2021 at 11:19 PM Dirk Eddelbuettel <edd at debian.org 
> <mailto:edd at debian.org>> wrote:
> 
> 
>     Vincent,
> 
>     In the broad terms of the question the best answer may be a simple
>     "sure".
>     More seriously, there have been many approaches.  Consider for
>     example the
>     recent Rcpp Gallery post lead by Zach (with some edits by me):
>     https://gallery.rcpp.org/articles/sparse-matrix-class/
>     <https://gallery.rcpp.org/articles/sparse-matrix-class/>
> 
>     It's focus on not copying <i,p,x> again if we already have them as R
>     vectors,
>     which is a fair point. If the goal is to get to SuperLU via
>     (Rcpp)Armadillo
>     then I do not think you can avoid the (internal) copies.  As always, the
>     answer may be "it depends".
> 
>     Hope this helps, happy to refine,  Dirk
> 
>     -- 
>     https://dirk.eddelbuettel.com <https://dirk.eddelbuettel.com> |
>     @eddelbuettel | edd at debian.org <mailto:edd at debian.org>
> 
> 
> The information in this e-mail is intended only for the person to whom it is
> addressed. If you believe this e-mail was sent to you in error and the 
> e-mail
> contains patient information, please contact the Partners 
> Compliance HelpLine at
> http://www.partners.org/complianceline 
> <http://www.partners.org/complianceline> . If the e-mail was sent to you 
> in error
> but does not contain patient information, please contact the sender and 
> properly
> dispose of the e-mail.
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> 



More information about the Rcpp-devel mailing list