10#define DO_FREE(_T_, _S_, _N_, _P_) \
13 _T_ = Matrix_cs_spfree(_T_); \
15 _S_ = Matrix_cs_sfree (_S_); \
17 _N_ = Matrix_cs_nfree (_N_); \
19 _P_ = Matrix_cs_free (_P_); \
23#define DO_SORT(_A_, _T_) \
25 Matrix_cs_dropzeros(_A_); \
26 _T_ = Matrix_cs_transpose(_A_, 1); \
29 _A_ = Matrix_cs_spfree(_A_); \
30 _A_ = Matrix_cs_transpose(_T_, 1); \
33 _T_ = Matrix_cs_spfree(_T_); \
36SEXP
sparse_qr(SEXP obj,
const char *
class,
int warn,
int order)
39 PROTECT_WITH_INDEX(obj, &pid);
40 if (
class[0] !=
'z' &&
class[0] !=
'd') {
44 if (
class[1] !=
'g') {
48 if (
class[2] !=
'C') {
57 Rf_error(
_(
"sparse QR factorization of m-by-n matrix requires m >= n"));
71 char cl[] =
".sparseQR";
78 SEXP V = PROTECT(
CXS2M(N->
L, 1,
'g')),
79 R = PROTECT(
CXS2M(N->
U, 1,
'g'));
84 SEXP beta = PROTECT(Rf_allocVector(REALSXP, A->
n));
85 memcpy(REAL(beta), N->
B,
sizeof(
double) * (
size_t) A->
n);
89 SEXP p = PROTECT(Rf_allocVector(INTSXP, S->
m2));
90 memcpy(INTEGER(p), P,
sizeof(
int) * (
size_t) S->
m2);
95 SEXP q = PROTECT(Rf_allocVector(INTSXP, A->
n));
96 memcpy(INTEGER(q), S->
q,
sizeof(
int) * (
size_t) A->
n);
108 Rf_error (
_(
"sparse QR factorization failed: out of memory"));
110 Rf_warning(
_(
"sparse QR factorization failed: out of memory"));
118 int order = Rf_asInteger(s_order);
119 if (order < 0 || order > 3)
122 (
class[1] ==
'g' ||
class[1] ==
's') &&
123 (
class[0] ==
'z' ||
class[0] ==
'd');
124 const char *nm = (order == 0) ?
"sparseQR-" :
"sparseQR+";
125 SEXP ans = (cache) ?
get_factor(s_obj, nm) : R_NilValue;
126 if (ans == R_NilValue) {
127 int warn = Rf_asLogical(s_warn);
128 ans =
sparse_qr(s_obj,
class, warn, order);
#define SET_DIMNAMES(x, mode, value)
const char * Matrix_class(SEXP, const char **, int, const char *)
#define DIMNAMES(x, mode)
SEXP newObject(const char *)
const char * valid_sparse[]
#define SET_SLOT(x, name, value)
SEXP get_factor(SEXP obj, const char *nm)
void set_factor(SEXP obj, const char *nm, SEXP val)
Matrix_csn * Matrix_cs_qr(const Matrix_cs *A, const Matrix_css *S)
SEXP CXS2M(Matrix_cs *A, int values, char shape)
int * Matrix_cs_pinv(const int *p, int n)
Matrix_css * Matrix_cs_sqr(int order, const Matrix_cs *A, int qr)
Matrix_cs * M2CXS(SEXP obj, int values)
#define CXSPARSE_XTYPE_SET(_VALUE_)
SEXP sparse_as_general(SEXP, const char *)
#define DO_FREE(_T_, _S_, _N_, _P_)
SEXP sparse_as_kind(SEXP, const char *, char)
#define DO_SORT(_A_, _T_)
SEXP sparse_qr(SEXP obj, const char *class, int warn, int order)
SEXP R_sparse_qr(SEXP s_obj, SEXP s_warn, SEXP s_order)
SEXP sparse_as_Csparse(SEXP, const char *)