Matrix $Rev: 2718 $ at $LastChangedDate: 2011-10-06 11:45:17 +0200 (Thu, 06 Oct 2011) $
chm_common.c File Reference
#include "chm_common.h"
#include "Mutils.h"
Include dependency graph for chm_common.c:

Go to the source code of this file.

Defines

#define _AS_cholmod_dense_1
#define _AS_cholmod_dense_2
#define _i(I)   ( (int*) chx->i)[I]
#define _p(I)   ( (int*) chx->p)[I]
#define _x(I)   ((double*) chx->x)[I]

Functions

CHM_DN as_cholmod_dense (CHM_DN ans, SEXP x)
 Populate ans with the pointers from x and modify its scalar elements accordingly.
CHM_FR as_cholmod_factor (CHM_FR ans, SEXP x)
 Populate ans with the pointers from x and modify its scalar elements accordingly.
CHM_SP as_cholmod_sparse (CHM_SP ans, SEXP x, Rboolean check_Udiag, Rboolean sort_in_place)
 Populate ans with the pointers from x and modify its scalar elements accordingly.
CHM_TR as_cholmod_triplet (CHM_TR ans, SEXP x, Rboolean check_Udiag)
 Populate ans with the pointers from x and modify its scalar elements accordingly.
CHM_DN as_cholmod_x_dense (cholmod_dense *ans, SEXP x)
Rboolean check_sorted_chm (CHM_SP A)
static void chm2Ralloc (CHM_SP dest, CHM_SP src)
 Copy cholmod_sparse, to an R_alloc()ed version of it.
SEXP chm_dense_to_matrix (CHM_DN a, int dofree, SEXP dn)
 Copy the contents of a to a matrix object and, optionally, free a or free both a and its pointer to its contents.
SEXP chm_dense_to_SEXP (CHM_DN a, int dofree, int Rkind, SEXP dn)
 Copy the contents of a to an appropriate denseMatrix object and, optionally, free a or free both a and its pointer to its contents.
void chm_diagN2U (CHM_SP chx, int uploT, Rboolean do_realloc)
 Drop the (unit) diagonal entries from a cholmod_sparse matrix.
SEXP chm_factor_to_SEXP (CHM_FR f, int dofree)
 Copy the contents of f to an appropriate CHMfactor object and, optionally, free f or free both f and its pointer to its contents.
void CHM_restore_common ()
SEXP CHM_set_common_env (SEXP rho)
SEXP chm_sparse_to_SEXP (CHM_SP a, int dofree, int uploT, int Rkind, const char *diag, SEXP dn)
 Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free a or free both a and its the pointers to its contents.
void CHM_store_common ()
SEXP chm_triplet_to_SEXP (CHM_TR a, int dofree, int uploT, int Rkind, const char *diag, SEXP dn)
 Copy the contents of a to an appropriate TsparseMatrix object and, optionally, free a or free both a and its the pointers to its contents.
SEXP CHMfactor_validate (SEXP obj)
SEXP CHMsimpl_validate (SEXP obj)
SEXP CHMsuper_validate (SEXP obj)
static void chTr2Ralloc (CHM_TR dest, CHM_TR src)
 Copy cholmod_triplet to an R_alloc()ed version of it.
Rboolean isValid_Csparse (SEXP x)
 "Cheap" C version of Csparse_validate() - *not* sorting :
CHM_DN numeric_as_chm_dense (CHM_DN ans, double *v, int nr, int nc)
void R_cholmod_error (int status, const char *file, int line, const char *message)
static int R_cholmod_printf (const char *fmt,...)
int R_cholmod_start (CHM_CM c)
 Initialize the CHOLMOD library and replace the print and error functions by R-specific versions.
static void * RallocedREAL (SEXP x)
static int stype (int ctype, SEXP x)
static void * xpt (int ctype, SEXP x)
static int xtype (int ctype)

Variables

cholmod_common c
SEXP chm_common_env
cholmod_common cl
static SEXP dboundSym
static SEXP final_asisSym
static SEXP final_llSym
static SEXP final_monotonicSym
static SEXP final_packSym
static SEXP final_resymbolSym
static SEXP final_superSym
static SEXP grow0Sym
static SEXP grow1Sym
static SEXP grow2Sym
static SEXP m0_ordSym
static SEXP maxrankSym
static SEXP nmethodsSym
static SEXP postorderSym
static SEXP prefer_upperSym
static SEXP prefer_zomplexSym
static SEXP quick_return_if_not_posdefSym
static SEXP supernodal_switchSym
static SEXP supernodalSym

Define Documentation

#define _AS_cholmod_dense_1
Value:
static const char *valid[] = { MATRIX_VALID_dense, ""};         \
    int dims[2], ctype = Matrix_check_class_etc(x, valid), nprot = 0;   \
                                                                        \
    if (ctype < 0) {            /* not a classed matrix */              \
        if (isMatrix(x)) Memcpy(dims, INTEGER(getAttrib(x, R_DimSymbol)), 2); \
        else {dims[0] = LENGTH(x); dims[1] = 1;}                        \
        if (isInteger(x)) {                                             \
            x = PROTECT(coerceVector(x, REALSXP));                      \
            nprot++;                                                    \
        }                                                               \
        ctype = (isReal(x) ? 0 :                                        \
                 (isLogical(x) ? 2 : /* logical -> default to "l", not "n" */ \
                  (isComplex(x) ? 6 : -1)));                            \
    } else Memcpy(dims, INTEGER(GET_SLOT(x, Matrix_DimSym)), 2);        \
    if (ctype < 0) error(_("invalid class of object to as_cholmod_dense")); \
    memset(ans, 0, sizeof(cholmod_dense)); /* zero the struct */        \
                                                                        \
    ans->dtype = CHOLMOD_DOUBLE; /* characteristics of the system */    \
    ans->x = ans->z = (void *) NULL;                                    \
                                /* dimensions and nzmax */              \
    ans->d = ans->nrow = dims[0];                                       \
    ans->ncol = dims[1];                                                \
    ans->nzmax = dims[0] * dims[1];                                     \
                                /* set the xtype and any elements */    \
    switch(ctype / 2) {                                                 \
    case 0: /* "d" */                                                   \
        ans->xtype = CHOLMOD_REAL;                                      \
        ans->x = (void *) REAL((ctype % 2) ? GET_SLOT(x, Matrix_xSym) : x); \
        break

Referenced by as_cholmod_dense(), and as_cholmod_x_dense().

#define _AS_cholmod_dense_2
Value:
case 3: /* "z" */                                                       \
        ans->xtype = CHOLMOD_COMPLEX;                                   \
        ans->x = (void *) COMPLEX((ctype % 2) ? GET_SLOT(x, Matrix_xSym) : x); \
        break;                                                          \
    }                                                                   \
    UNPROTECT(nprot);                                                   \
    return ans

Referenced by as_cholmod_dense(), and as_cholmod_x_dense().

#define _i (   I)    ( (int*) chx->i)[I]

Referenced by chm_diagN2U().

#define _p (   I)    ( (int*) chx->p)[I]

Referenced by chm_diagN2U().

#define _x (   I)    ((double*) chx->x)[I]

Referenced by chm_diagN2U().


Function Documentation

CHM_DN as_cholmod_dense ( CHM_DN  ans,
SEXP  x 
)

Populate ans with the pointers from x and modify its scalar elements accordingly.

Note that later changes to the contents of ans will change the contents of the SEXP.

In most cases this function is called through the macro AS_CHM_DN. It is unusual to call it directly.

Parameters:
ansa CHM_DN pointer.
xpointer to an object that inherits from (denseMatrix ^ generalMatrix)
Returns:
ans containing pointers to the slots of x.

Definition at line 593 of file chm_common.c.

References _AS_cholmod_dense_1, _AS_cholmod_dense_2, Matrix_xSym, and RallocedREAL().

Referenced by R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

CHM_FR as_cholmod_factor ( CHM_FR  ans,
SEXP  x 
)

Populate ans with the pointers from x and modify its scalar elements accordingly.

Note that later changes to the contents of ans will change the contents of the SEXP.

In most cases this function is called through the macro AS_CHM_FR. It is unusual to call it directly.

Parameters:
ansan CHM_FR object
xpointer to an object that inherits from CHMfactor
Returns:
ans containing pointers to the slots of x.

Definition at line 865 of file chm_common.c.

References _, c, Matrix_check_class_etc(), Matrix_iSym, Matrix_permSym, Matrix_pSym, MATRIX_VALID_CHMfactor, and Matrix_xSym.

Referenced by R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

CHM_SP as_cholmod_sparse ( CHM_SP  ans,
SEXP  x,
Rboolean  check_Udiag,
Rboolean  sort_in_place 
)

Populate ans with the pointers from x and modify its scalar elements accordingly.

Note that later changes to the contents of ans will change the contents of the SEXP.

In most cases this function is called through the macros AS_CHM_SP() or AS_CHM_SP__(). It is unusual to call it directly.

Parameters:
ansa CHM_SP pointer
xpointer to an object that inherits from CsparseMatrix
check_Udiagboolean - should a check for (and consequent expansion of) a unit diagonal be performed.
sort_in_placeboolean - if the i and x slots are to be sorted should they be sorted in place? If the i and x slots are pointers to an input SEXP they should not be modified.
Returns:
ans containing pointers to the slots of x, *unless* check_Udiag and x is unitriangular.

Definition at line 217 of file chm_common.c.

References _, c, check_sorted_chm(), chm2Ralloc(), diag_P, isValid_Csparse(), Matrix_check_class_etc(), Matrix_DimSym, Matrix_iSym, Matrix_pSym, stype(), xpt(), and xtype().

Referenced by Csparse_validate_(), and R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

CHM_TR as_cholmod_triplet ( CHM_TR  ans,
SEXP  x,
Rboolean  check_Udiag 
)

Populate ans with the pointers from x and modify its scalar elements accordingly.

Note that later changes to the contents of ans will change the contents of the SEXP.

In most cases this function is called through the macros AS_CHM_TR() or AS_CHM_TR__(). It is unusual to call it directly.

Parameters:
ansa CHM_TR pointer
xpointer to an object that inherits from TsparseMatrix
check_Udiagboolean - should a check for (and consequent expansion of) a unit diagonal be performed.
Returns:
ans containing pointers to the slots of x, *unless* check_Udiag and x is unitriangular.

Definition at line 410 of file chm_common.c.

References _, c, chTr2Ralloc(), diag_P, Matrix_check_class_etc(), Matrix_DimSym, Matrix_iSym, Matrix_jSym, MATRIX_VALID_Tsparse, stype(), xpt(), and xtype().

Here is the call graph for this function:

CHM_DN as_cholmod_x_dense ( cholmod_dense *  ans,
SEXP  x 
)

Definition at line 652 of file chm_common.c.

References _AS_cholmod_dense_1, _AS_cholmod_dense_2, Matrix_xSym, and RallocedREAL().

Here is the call graph for this function:

Rboolean check_sorted_chm ( CHM_SP  A)

Definition at line 141 of file chm_common.c.

Referenced by as_cholmod_sparse().

Here is the caller graph for this function:

static void chm2Ralloc ( CHM_SP  dest,
CHM_SP  src 
) [static]

Copy cholmod_sparse, to an R_alloc()ed version of it.

Definition at line 158 of file chm_common.c.

References c.

Referenced by as_cholmod_sparse().

Here is the caller graph for this function:

SEXP chm_dense_to_matrix ( CHM_DN  a,
int  dofree,
SEXP  dn 
)

Copy the contents of a to a matrix object and, optionally, free a or free both a and its pointer to its contents.

Parameters:
acholmod_dense structure to be converted
dofree0 - don't free a; > 0 cholmod_free a; < 0 Free a
dneither R_NilValue or an SEXP suitable for the Dimnames slot.
Returns:
SEXP containing a copy of a as a matrix object

Definition at line 809 of file chm_common.c.

References _, and c.

Referenced by Csparse_to_matrix().

Here is the caller graph for this function:

SEXP chm_dense_to_SEXP ( CHM_DN  a,
int  dofree,
int  Rkind,
SEXP  dn 
)

Copy the contents of a to an appropriate denseMatrix object and, optionally, free a or free both a and its pointer to its contents.

Parameters:
amatrix to be converted
dofree0 - don't free a; > 0 cholmod_free a; < 0 Free a
Rkindtype of R matrix to be generated (special to this function)
dn-- dimnames [list(.,.) or NULL]
Returns:
SEXP containing a copy of a

Definition at line 736 of file chm_common.c.

References _, ALLOC_SLOT(), c, cl, Matrix_DimNamesSym, Matrix_DimSym, and Matrix_xSym.

Referenced by CHMfactor_solve(), Csparse_dense_crossprod(), Csparse_dense_prod(), Csparse_to_dense(), and dsCMatrix_matrix_solve().

Here is the call graph for this function:

Here is the caller graph for this function:

void chm_diagN2U ( CHM_SP  chx,
int  uploT,
Rboolean  do_realloc 
)

Drop the (unit) diagonal entries from a cholmod_sparse matrix.

Parameters:
chxcholmod_sparse matrix. Note that the matrix "slots" are modified _in place_
uploTinteger code (= +/- 1) indicating if chx is upper (+1) or lower (-1) triangular
do_reallocRboolean indicating, if a cholmod_sprealloc() should finalize the procedure; not needed, e.g. when the result is converted to a SEXP immediately afterwards.

Definition at line 1019 of file chm_common.c.

References _, _i, _p, _x, and c.

Referenced by Csparse_Csparse_crossprod(), Csparse_Csparse_prod(), and Csparse_diagN2U().

Here is the caller graph for this function:

SEXP chm_factor_to_SEXP ( CHM_FR  f,
int  dofree 
)

Copy the contents of f to an appropriate CHMfactor object and, optionally, free f or free both f and its pointer to its contents.

Parameters:
fcholmod_factor object to be converted
dofree0 - don't free a; > 0 cholmod_free a; < 0 Free a
Returns:
SEXP containing a copy of a

Definition at line 940 of file chm_common.c.

References _, ALLOC_SLOT(), c, chm_factor_ok(), Matrix_iSym, Matrix_pSym, Matrix_xSym, and xtype().

Referenced by CHMfactor_update(), destructive_CHM_update(), dgCMatrix_cholsol(), dsCMatrix_Cholesky(), internal_chm_factor(), and R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

SEXP chm_sparse_to_SEXP ( CHM_SP  a,
int  dofree,
int  uploT,
int  Rkind,
const char *  diag,
SEXP  dn 
)

Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free a or free both a and its the pointers to its contents.

Parameters:
a(cholmod_sparse) matrix to be converted
dofree0 - don't free a; > 0 cholmod_free a; < 0 Free a
uploT0 - not triangular; > 0 upper triangular; < 0 lower
Rkind- vector type to store for a->xtype == CHOLMOD_REAL, 0 - REAL; 1 - LOGICAL
diagcharacter string suitable for the diag slot of a triangular matrix (not accessed if uploT == 0).
dneither R_NilValue or an SEXP suitable for the Dimnames slot.
Returns:
SEXP containing a copy of a

Definition at line 311 of file chm_common.c.

References _, ALLOC_SLOT(), c, cl, Matrix_diagSym, Matrix_DimNamesSym, Matrix_DimSym, Matrix_iSym, Matrix_pSym, Matrix_uploSym, and Matrix_xSym.

Referenced by CHMfactor_spsolve(), CHMfactor_to_sparse(), Csparse_band(), Csparse_crossprod(), Csparse_Csparse_crossprod(), Csparse_Csparse_prod(), Csparse_diagN2U(), Csparse_diagU2N(), Csparse_drop(), Csparse_general_to_symmetric(), Csparse_horzcat(), Csparse_submatrix(), Csparse_symmetric_to_general(), Csparse_to_nz_pattern(), Csparse_transpose(), Csparse_vertcat(), dense_to_Csparse(), dsCMatrix_chol(), dsCMatrix_Csparse_solve(), R_init_Matrix(), Tsparse_to_Csparse(), and Tsparse_to_tCsparse().

Here is the call graph for this function:

Here is the caller graph for this function:

SEXP chm_triplet_to_SEXP ( CHM_TR  a,
int  dofree,
int  uploT,
int  Rkind,
const char *  diag,
SEXP  dn 
)

Copy the contents of a to an appropriate TsparseMatrix object and, optionally, free a or free both a and its the pointers to its contents.

Parameters:
amatrix to be converted
dofree0 - don't free a; > 0 cholmod_free a; < 0 Free a
uploT0 - not triangular; > 0 upper triangular; < 0 lower
Rkind- vector type to store for a->xtype == CHOLMOD_REAL, 0 - REAL; 1 - LOGICAL
diagcharacter string suitable for the diag slot of a triangular matrix (not accessed if uploT == 0).
dneither R_NilValue or an SEXP suitable for the Dimnames slot.
Returns:
SEXP containing a copy of a

Definition at line 503 of file chm_common.c.

References _, ALLOC_SLOT(), c, cl, Matrix_diagSym, Matrix_DimNamesSym, Matrix_DimSym, Matrix_iSym, Matrix_jSym, Matrix_uploSym, and Matrix_xSym.

Referenced by Csparse_to_Tsparse(), dsCMatrix_to_dgTMatrix(), and R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

SEXP CHMfactor_validate ( SEXP  obj)

Definition at line 1087 of file chm_common.c.

SEXP CHMsimpl_validate ( SEXP  obj)

Definition at line 1092 of file chm_common.c.

SEXP CHMsuper_validate ( SEXP  obj)

Definition at line 1097 of file chm_common.c.

static void chTr2Ralloc ( CHM_TR  dest,
CHM_TR  src 
) [static]

Copy cholmod_triplet to an R_alloc()ed version of it.

Definition at line 180 of file chm_common.c.

Referenced by as_cholmod_triplet().

Here is the caller graph for this function:

Rboolean isValid_Csparse ( SEXP  x)

"Cheap" C version of Csparse_validate() - *not* sorting :

Definition at line 8 of file Csparse.c.

Referenced by as_cholmod_sparse().

Here is the caller graph for this function:

CHM_DN numeric_as_chm_dense ( CHM_DN  ans,
double *  v,
int  nr,
int  nc 
)

Definition at line 841 of file chm_common.c.

Referenced by R_init_Matrix().

Here is the caller graph for this function:

void R_cholmod_error ( int  status,
const char *  file,
int  line,
const char *  message 
)

Definition at line 668 of file chm_common.c.

References _, and CHM_restore_common().

Referenced by R_cholmod_start().

Here is the call graph for this function:

Here is the caller graph for this function:

static int R_cholmod_printf ( const char *  fmt,
  ... 
) [static]

Definition at line 691 of file chm_common.c.

Referenced by R_cholmod_start().

Here is the caller graph for this function:

int R_cholmod_start ( CHM_CM  c)

Initialize the CHOLMOD library and replace the print and error functions by R-specific versions.

Parameters:
cpointer to a cholmod_common structure to be initialized
Returns:
TRUE if successful

Definition at line 709 of file chm_common.c.

References _, R_cholmod_error(), and R_cholmod_printf().

Referenced by R_init_Matrix().

Here is the call graph for this function:

Here is the caller graph for this function:

static void* RallocedREAL ( SEXP  x) [static]

Definition at line 113 of file chm_common.c.

Referenced by as_cholmod_dense(), as_cholmod_x_dense(), and xpt().

Here is the caller graph for this function:

static int stype ( int  ctype,
SEXP  x 
) [static]

Definition at line 92 of file chm_common.c.

References uplo_P.

Referenced by as_cholmod_sparse(), and as_cholmod_triplet().

Here is the caller graph for this function:

static void* xpt ( int  ctype,
SEXP  x 
) [static]

Definition at line 126 of file chm_common.c.

References Matrix_xSym, and RallocedREAL().

Referenced by as_cholmod_sparse(), as_cholmod_triplet(), and lapack_qr().

Here is the call graph for this function:

Here is the caller graph for this function:

static int xtype ( int  ctype) [static]

Definition at line 98 of file chm_common.c.

Referenced by as_cholmod_sparse(), as_cholmod_triplet(), chm_factor_to_SEXP(), and create_Csparse().

Here is the caller graph for this function:


Variable Documentation

Definition at line 9 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP dboundSym [static]

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP grow0Sym

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP grow1Sym

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP grow2Sym

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP m0_ordSym

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

SEXP maxrankSym

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().

Definition at line 10 of file chm_common.c.

Referenced by CHM_restore_common(), CHM_set_common_env(), and CHM_store_common().