Git Product home page Git Product logo

Comments (7)

thirdwing avatar thirdwing commented on June 1, 2024 4

@ivan-krukov After enabling ARMA_USE_SUPERLU, you also need to pass the -lsuperlu option to R.

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace Rcpp ;
using namespace arma;

// [[Rcpp::export]]
void test () {
  sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1);

  vec b = randu<vec>(1000);
  mat B = randu<mat>(1000, 5);

  vec x = spsolve(A, b);  // solve one system
  mat X = spsolve(A, B);  // solve several systems

  bool status = spsolve(x, A, b);  // use default solver
  if(status == false)  { cout << "no solution" << endl; }

  spsolve(x, A, b, "lapack");   // use LAPACK  solver
  spsolve(x, A, b, "superlu");  // use SuperLU solver

}

In R:

> Sys.setenv("PKG_LIBS"="-lsuperlu")
> Rcpp::sourceCpp("test.cpp")

If you didn't pass -lsuperlu, you might get some errors like undefined symbol: set_default_options.

from rcpparmadillo.

eddelbuettel avatar eddelbuettel commented on June 1, 2024 2

I wrote this up as a new piece on the Rcpp Gallery.

from rcpparmadillo.

eddelbuettel avatar eddelbuettel commented on June 1, 2024

Good question. I am not sure.

Context, as you may know: RcppArmadillo takes a plain copy, no cmake, no options. Works great with basic BLAS and LAPACK which we get from R.

Extensions are harder. We are learning that now with MLPACK (over here) which uses linking against external Boost (as it needs serialization) and Armadillo (as that is how it is build).

You could try something narrower and half way. Ie define the required tokens in your source file (or src/Makevars), then load RcppArmadillo to have them take effect. Then you "only" need to make sure you supply SUPERLU itself.

There are a few people interested in better sparse support, maybe time to discuss on rcpp-devel, or here.

from rcpparmadillo.

eddelbuettel avatar eddelbuettel commented on June 1, 2024

Just checked, and Conrad's documentation leans the same way:

ARMA_USE_SUPERLU Enable use of SuperLU, which is used by spsolve() for finding the solutions of sparse systems; you will need to link with the superlu library, for example -lsuperlu
Caveat: Armadillo 6.x requires SuperLU 4.3, while Armadillo 7.x requires SuperLU 5.2

from rcpparmadillo.

eddelbuettel avatar eddelbuettel commented on June 1, 2024

Perfect, was just thinking I should write an Rcpp Gallery post along those line.

The default libsuperlu-dev on Ubuntu is currenty behind, the one in Debian is good enough so easy enough to test in a Docker container, or a locally rebuilt packager for superlu.

from rcpparmadillo.

eddelbuettel avatar eddelbuettel commented on June 1, 2024

It should all be headers ... until the call to superlu is made at which point object code is needed.

Not any different from when LAPACK is called, which get for free from R which is why it seems so seamless.

from rcpparmadillo.

ivan-krukov avatar ivan-krukov commented on June 1, 2024

Just checked everything works, no need to recompile RcppArmadillo.

This is excellent. Thank you!

from rcpparmadillo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.