0

Since RcppEigen version 3.3.3.0 the MappedSpareMatrixT has been deprecated. For some reason when compiling functions with this new type I get errors.

For example (based on this question);

EDIT: with suggestions from coatless - still getting same errors.

#include <RcppEigen.h>

typedef Eigen::Map<Eigen::SparseMatrix<double> > mappedSparseMatrix;
typedef Eigen::Map<Eigen::VectorXd> mappedVector;

// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::export]]
Eigen::VectorXd cgSparse(const mappedSparseMatrix A, const mappedVector b) {
  Eigen::ConjugateGradient< mappedSparseMatrix, Eigen::Lower > cg(A);
  return cg.solve(b);
}

I have tried different things, even copied the type from the Rcppeigen unitTests;

typedef Eigen::Map<Eigen::SparseMatrix<double, Eigen::ColMajor> > MapMat;

In both cases I get the following errors;

errors

SessionInfo() here:

R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppEigen_0.3.3.3.0  RevoUtilsMath_10.0.0

loaded via a namespace (and not attached):
[1] compiler_3.4.0   Matrix_1.2-9     RevoUtils_10.0.4 tools_3.4.0      Rcpp_0.12.10     grid_3.4.0      
[7] lattice_0.20-35 

With the mentioned changes - how can I map my sparse matrices? For example, in the above function sparseCG? (NB: I am C++ newbie)

tstev
  • 607
  • 1
  • 10
  • 20

1 Answers1

0

There is a note in the files RcppEigenForward.h and RcppEigenWrap.h that the mappedSparseMatrix was deprecated upstream starting with Eigen 3.3.0.

If I change it to

typedef Eigen::SparseMatrix< double > mappedSparseMatrix;

ie use an outright sparse matrix (as opposed to a map to it) then it compiles.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 2
    `MappedSparseMatrix` -> `Map` class – coatless Jul 10 '17 at 13:03
  • Yes, that is true. However I was under the impression that mapping was more memory efficient (i.e. [it maps rather than copies](https://github.com/RcppCore/rcpp-gallery/blob/gh-pages/src/2013-01-11-eigen-eigenvalues.cpp#L22)). My datasets can get very large - therefore I thought it best to avoid creating a copy each time. On top of that, not sure it means that is deprecated upstream? So it will slowly be phased out in future? – tstev Jul 10 '17 at 13:12
  • All questions for upstream. Was not our decision. – Dirk Eddelbuettel Jul 10 '17 at 13:13
  • Maybe I should rephrase my question then (?) - how with the upstream changes can I still 'map' my sparse matrices? – tstev Jul 10 '17 at 13:22
  • Using the `Map>` syntax as I initially mentioned above. See definitions in the [`RcppEigenForward.h`](https://github.com/RcppCore/RcppEigen/blob/c03cd8a7c657a15872025a93dcc7e9e7b314dd76/inst/include/RcppEigenForward.h#L53-L56) file. – coatless Jul 10 '17 at 13:27
  • @coatless, I am under the impression I already did as you said. Like mentioned in the post - i directly copied the definitions from the unit tests. – tstev Jul 10 '17 at 13:54
  • 1
    I just played with your example. It looks like the routine [`ConjugateGradient`](https://eigen.tuxfamily.org/dox/classEigen_1_1ConjugateGradient.html) does not _support_ MappedSparseMatrices. So, trying to put a mapped sparse in blows it up. The exporters are fine (@eddelbuettel: unit test should be moved away from `cxxfunction`...) This should be filed as a bug with the Eigen project. – coatless Jul 10 '17 at 14:06
  • @coatless, Thanks a lot for the effort and explanation! – tstev Jul 10 '17 at 14:07