#ifndef RATICATE_CSPARSEMATRIX_HPP #define RATICATE_CSPARSEMATRIX_HPP #include "utils.hpp" #include "tatami/tatami.hpp" #include "tatami/ext/ArrayView.hpp" namespace raticate { template Parsed parse_CSparseMatrix(Rcpp::RObject seed, const V& val) { auto dims = parse_dims(seed.slot("Dim")); Rcpp::IntegerVector p(seed.slot("p")); tatami::ArrayView pview(static_cast(p.begin()), p.size()); Rcpp::IntegerVector i(seed.slot("i")); tatami::ArrayView iview(static_cast(i.begin()), i.size()); typedef typename std::remove_const::type>::type Value; tatami::ArrayView vview(static_cast(val.begin()), val.size()); Parsed output; output.matrix.reset( new tatami::CompressedSparseMatrix( dims.first, dims.second, std::move(vview), std::move(iview), std::move(pview) ) ); output.contents = Rcpp::List::create(i, val, p); // protect views from GC of the underlying memory. return output; } template Parsed parse_dgCMatrix(Rcpp::RObject seed) { Rcpp::NumericVector y(seed.slot("x")); return parse_CSparseMatrix(seed, y); } template Parsed parse_lgCMatrix(Rcpp::RObject seed) { Rcpp::LogicalVector y(seed.slot("x")); return parse_CSparseMatrix(seed, y); } } #endif