Matrix  $Rev: 3071 $ at $LastChangedDate: 2015-03-26 15:35:47 +0100 (Thu, 26 Mar 2015) $
sparseQR.c File Reference
#include "sparseQR.h"
Include dependency graph for sparseQR.c:

Go to the source code of this file.

Macros

#define EXIT_sparseQR_
 
#define INIT_sparseQR_(_DM_NMS_)
 

Functions

SEXP sparseQR_coef (SEXP qr, SEXP y)
 
static void sparseQR_Qmult (cs *V, SEXP dmns, double *beta, int *p, int trans, SEXP ans)
 Apply Householder transformations and the row permutation P to y. More...
 
SEXP sparseQR_qty (SEXP qr, SEXP y, SEXP trans, SEXP keep_dimnames)
 Given a sparse QR decomposition and y, compute Q y or Q'y. More...
 
SEXP sparseQR_resid_fitted (SEXP qr, SEXP y, SEXP want_resid)
 Compute qr.resid(qr, y) or qr.fitted(qr, y) More...
 
SEXP sparseQR_validate (SEXP x)
 

Macro Definition Documentation

#define EXIT_sparseQR_
Value:
/* remove the extra rows from ans */ \
d_a[0] = m;/* -> @Dim is ok; @Dimnames (i.e. colnames) still are */ \
double *yy = REAL( GET_SLOT(ans, Matrix_xSym)); /* is M x n */ \
double *xx = REAL(ALLOC_SLOT(aa, Matrix_xSym, REALSXP, m * n)); \
for(int j = 0; j < n; j++) { /* j-th column */ \
Memcpy(xx + j*m, yy + j*M, m); /* copy x[ 1:m, j ] := yy[,j] */ \
} \
ans = duplicate(aa); /* m x n finally */ \
UNPROTECT(1)
SEXP Matrix_xSym
Definition: Syms.h:2
static R_INLINE SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
Allocate an SEXP of given type and length, assign it as slot nm in the object, and return the SEXP...
Definition: Mutils.h:240

Referenced by sparseQR_coef(), sparseQR_qty(), and sparseQR_resid_fitted().

#define INIT_sparseQR_ (   _DM_NMS_)
Value:
SEXP V_ = GET_SLOT(qr, Matrix_VSym); \
CSP V = AS_CSP__(V_); \
R_CheckStack(); \
SEXP ans, aa, dnms = R_NilValue; \
if(_DM_NMS_) dnms = GET_SLOT(V_, Matrix_DimNamesSym); \
PROTECT_INDEX ipx; \
PROTECT_WITH_INDEX(ans = dup_mMatrix_as_dgeMatrix(y), &ipx); \
int *ydims = INTEGER(GET_SLOT(ans, Matrix_DimSym)), \
m = ydims[0], n = ydims[1], M = V->m, *d_a; \
Rboolean rank_def = (m < M); \
if(rank_def) { /* must add 0-rows to y, i.e. ans, and remove them *before* return */ \
aa = PROTECT(NEW_OBJECT(MAKE_CLASS("dgeMatrix"))); \
d_a = INTEGER(GET_SLOT(aa, Matrix_DimSym)); d_a[0] = M; d_a[1] = n; \
SEXP dn = GET_SLOT(aa, Matrix_DimNamesSym); \
SET_VECTOR_ELT(dn, 1, \
duplicate(VECTOR_ELT(GET_SLOT(ans, Matrix_DimNamesSym), 1))); \
SET_SLOT(aa, Matrix_DimNamesSym, dn); \
double *yy = REAL( GET_SLOT(ans, Matrix_xSym)); /* m * n */ \
double *xx = REAL(ALLOC_SLOT(aa, Matrix_xSym, REALSXP, M * n)); \
for(int j = 0; j < n; j++) { /* j-th column */ \
Memcpy(xx + j*M, yy + j*m, m); /* copy x[ 1:m , j ] := yy[,j] */ \
for(int i = m; i < M; i++) xx[i + j*M] = 0.;/* x[(m+1):M, j ] := 0 */ \
} \
REPROTECT(ans = duplicate(aa), ipx); /* is M x n now */ \
}
SEXP Matrix_DimSym
Definition: Syms.h:2
#define AS_CSP__(x)
Definition: cs_utils.h:13
SEXP Matrix_xSym
Definition: Syms.h:2
SEXP Matrix_DimNamesSym
Definition: Syms.h:2
SEXP dup_mMatrix_as_dgeMatrix(SEXP A)
Definition: Mutils.c:852
static R_INLINE SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
Allocate an SEXP of given type and length, assign it as slot nm in the object, and return the SEXP...
Definition: Mutils.h:240
SEXP Matrix_VSym
Definition: Syms.h:2

Referenced by sparseQR_coef(), sparseQR_qty(), and sparseQR_resid_fitted().

Function Documentation

SEXP sparseQR_coef ( SEXP  qr,
SEXP  y 
)
static void sparseQR_Qmult ( cs V,
SEXP  dmns,
double *  beta,
int *  p,
int  trans,
SEXP  ans 
)
static

Apply Householder transformations and the row permutation P to y.

Parameters
Vsparse matrix containing the vectors defining the Householder transformations
dmns== dimnames(V) or "NULL" (R_NilValue)
betascaling factors for the Householder transformations
p0-based permutation vector of length V->m
translogical value - if TRUE create Q'y[p] otherwise Qy[p]
ans: both function argument and result ("input and output")

Definition at line 37 of file sparseQR.c.

References _, C_or_Alloca_TO, cs_happly(), cs_ipvec(), cs_pvec(), cs_sparse::m, Matrix_DimNamesSym, Matrix_DimSym, Matrix_xSym, cs_sparse::n, and SMALL_4_Alloca.

Referenced by sparseQR_coef(), sparseQR_qty(), and sparseQR_resid_fitted().

Here is the call graph for this function:

Here is the caller graph for this function:

SEXP sparseQR_qty ( SEXP  qr,
SEXP  y,
SEXP  trans,
SEXP  keep_dimnames 
)

Given a sparse QR decomposition and y, compute Q y or Q'y.

Parameters
qra "sparseQR" object
ya (dense) Matrix
translogical, if TRUE compute Q'y else Q y
Returns
Q'y ("qty") or Qy ("qy")

Definition at line 84 of file sparseQR.c.

References _, EXIT_sparseQR_, INIT_sparseQR_, Matrix_betaSym, Matrix_pSym, and sparseQR_Qmult().

Here is the call graph for this function:

SEXP sparseQR_resid_fitted ( SEXP  qr,
SEXP  y,
SEXP  want_resid 
)

Compute qr.resid(qr, y) or qr.fitted(qr, y)

Definition at line 186 of file sparseQR.c.

References _, EXIT_sparseQR_, INIT_sparseQR_, Matrix_betaSym, Matrix_pSym, Matrix_xSym, and sparseQR_Qmult().

Here is the call graph for this function:

SEXP sparseQR_validate ( SEXP  x)

Definition at line 3 of file sparseQR.c.

References _, AS_CSP__, cs_sparse::m, Matrix_betaSym, Matrix_pSym, Matrix_VSym, and cs_sparse::n.