I was trying to call the c function La_svd (which was used by R function
La.svd) from my c code (see below), but I keep getting the following error
message in the simple testing:
>
dyn.load("/u/j/y/jyan/ludwig/work/newgeese/feepack/src/feepack.so")
> x <- matrix(1:4, 2)
> .Call("try_svd", x)
Error: LAPACK routine DGESVD gave error code -1
I would appreciate if someone can point out what I am missing.
Thanks, --Jun
===================c code=======================#include <R.h>
#include <Rdefines.h>
SEXP La_svd(SEXP jobu, SEXP jobv, SEXP x, SEXP s, SEXP u, SEXP v, SEXP
method);
SEXP try_svd(SEXP x) {
int *xdims;
xdims = INTEGER(coerceVector(getAttrib(x, R_DimSymbol), INTSXP));
int p = xdims[1];
SEXP jobu, jobv, s, u, v, method, res;
jobu = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(jobu, 0, mkChar("A"));
jobv = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(jobv, 0, mkChar("A"));
s = PROTECT(allocVector(REALSXP, p));
u = PROTECT(allocMatrix(REALSXP, p, p));
v = PROTECT(allocMatrix(REALSXP, p, p));
method = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(jobu, 0, mkChar("dgesvd"));
res = PROTECT(La_svd(jobu, jobv, x, s, u, v, method));
UNPROTECT(7);
return res;
}