[Rd] F77_CALL(dgetrs) C++ call in R-devel
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Tue Dec 20 14:09:16 CET 2022
On 20 December 2022 at 12:33, Lars Relund wrote:
| In my package, I have the method:
|
| /** Solve equations transpose(P)w = r. */
| int LASolveT(MatSimple<double> &P, MatSimple<double> &w, const
| MatSimple<double> &r) {
| int rows = P.rows;
| int nrhs = 1;
| int lda = rows;
| int ldb = rows;
| int info = -1;
| MatSimple<int> ipivot(1,rows);
| w.Inject(r); // copy r to w;
| F77_CALL(dgetrf)(&rows, &rows, &P(0,0), &lda, &ipivot(0,0), &info);
| if (info!=0) {
| cout << "Error in LASolve (dgetrf). Info=" << info << endl;
| return 1;
| }
| F77_CALL(dgetrs)("T", &rows, &nrhs, &P(0,0), &lda, &ipivot(0,0),
| &w(0,0), &ldb, &info);("T", &rows, &nrhs, &P(0,0), &lda, &ipivot(0,0),
| &w(0,0), &ldb, &info);
| if (info!=0) {
| cout << "Error in LASolve (dgetrs). Info=" << info << endl;
| return 1;
| }
| return 0;
| }
|
| When compiling the package on using R-devel the error for F77_CALL(dgetrs)
| occur:
|
| matalg.h:67:25: error: too few arguments to function ‘void dgetrs_(const
| char*, const int*, const int*, const double*, const int*, const int*,
| double*, const int*, int*, size_t)’
| 67 | F77_CALL(dgetrs)("T", &rows, &nrhs, &P(0,0), &lda,
| &ipivot(0,0), &w(0,0), &ldb, &info);
|
| It works in R-release and I guess it have something to do with
| https://cran.r-project.org/doc/manuals/r-devel/NEWS.html and LAPACK.
|
| Any hints on how to get it to work for both R-release and R-devel.
I can offer you two answers. The first, and narrower, is in Writing R
Extensions and concerns FC_LEN. R now 'automagically' injects additional
parameters for a better, more stringent, control of character variable
length. See eg
https://rstudio.github.io/r-manuals/r-exts/The-R-API.html#fortran-character-strings
and related. (And this isn't new per se, those of use with packages with
Fortran interfaces have been keeping this up.)
The second, more pragmatic answer, is of course 'to not do that' but to rely
on the decade of tuning and bazillion of test and runs a higher-end Linear
Algebra package like (Rcpp)Armadillo offers by wrapping around LAPACK and
BLAS for you. You already are in C++, so there os essentially no switching
cost. And (Rcpp)Armadillo is header-only and hence free of added
complications.
Dirk
--
dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
More information about the R-devel
mailing list