Matrix r4655
Loading...
Searching...
No Matches
Macros | Functions | Variables
cholmod-common.c File Reference
#include "Mdefines.h"
#include "cholmod-common.h"

Go to the source code of this file.

Macros

#define MKMS(_FORMAT_, ...)   mkString(Matrix_sprintf(_FORMAT_, __VA_ARGS__))
 
#define FREE_THEN(_EXPR_)
 
#define FREE_THEN(_EXPR_)
 
#define FREE_THEN(_EXPR_)
 
#define FREE_THEN(_EXPR_)
 
#define SET_FRAME_FROM_MEMBER(_MEMBER_, _KIND_)
 
#define GET_MEMBER_FROM_FRAME(_MEMBER_, _KIND_)
 

Functions

SEXP checkpi (SEXP p, SEXP i, int m, int n)
 
cholmod_factor * sexp_as_cholmod_factor (cholmod_factor *L, SEXP from)
 Coerce from CHMfactor to (cholmod_factor *)
 
cholmod_sparse * sexp_as_cholmod_sparse (cholmod_sparse *A, SEXP from, Rboolean checkUnit, Rboolean sortInPlace)
 Coerce from CsparseMatrix to (cholmod_sparse *)
 
cholmod_triplet * sexp_as_cholmod_triplet (cholmod_triplet *A, SEXP from, Rboolean checkUnit)
 Coerce from TsparseMatrix to (cholmod_triplet *)
 
cholmod_dense * sexp_as_cholmod_dense (cholmod_dense *A, SEXP from)
 Coerce from [nlidz]geMatrix or vector to (cholmod_dense *)
 
cholmod_dense * numeric_as_cholmod_dense (cholmod_dense *A, double *data, int nrow, int ncol)
 Coerce from (double *) to (cholmod_dense *) with given dimensions.
 
SEXP cholmod_factor_as_sexp (cholmod_factor *L, int doFree)
 Coerce from (cholmod_factor *) to CHMfactor.
 
SEXP cholmod_sparse_as_sexp (cholmod_sparse *A, int doFree, int ttype, int doLogic, const char *diagString, SEXP dimnames)
 Coerce from (cholmod_sparse *) to CsparseMatrix.
 
SEXP cholmod_triplet_as_sexp (cholmod_triplet *A, int doFree, int ttype, int doLogic, const char *diagString, SEXP dimnames)
 Coerce from (cholmod_triplet *) to TsparseMatrix.
 
SEXP cholmod_dense_as_sexp (cholmod_dense *A, int doFree)
 Coerce from (cholmod_dense *) to [dz]geMatrix.
 
double cholmod_factor_ldetA (cholmod_factor *L)
 Log determinant from Cholesky factorization.
 
cholmod_factor * cholmod_factor_update (cholmod_factor *L, cholmod_sparse *A, double beta)
 Update a Cholesky factorization.
 
static void R_cholmod_error_handler (int status, const char *file, int line, const char *message)
 
int R_cholmod_start (cholmod_common *Common)
 
int R_cholmod_finish (cholmod_common *Common)
 
SEXP R_cholmod_common_envini (SEXP rho)
 
void R_cholmod_common_envset (void)
 
void R_cholmod_common_envget (void)
 

Variables

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

Macro Definition Documentation

◆ FREE_THEN [1/4]

#define FREE_THEN (   _EXPR_)
Value:
do { \
if (doFree != 0) { \
if (doFree < 0) \
R_Free(L); \
else if (L->itype == CHOLMOD_INT) \
cholmod_free_factor(&L, &c); \
else \
cholmod_l_free_factor(&L, &cl); \
_EXPR_; \
} \
} while (0)
cholmod_common c
Definition cholmod-etc.c:5
cholmod_common cl
Definition cholmod-etc.c:6

◆ FREE_THEN [2/4]

#define FREE_THEN (   _EXPR_)
Value:
do { \
if (doFree != 0) { \
if (doFree < 0) \
R_Free(A_); \
else if (A_->itype == CHOLMOD_INT) \
cholmod_free_sparse(&A_, &c); \
else \
cholmod_l_free_sparse(&A_, &cl); \
_EXPR_; \
} \
} while (0)

◆ FREE_THEN [3/4]

#define FREE_THEN (   _EXPR_)
Value:
do { \
if (doFree != 0) { \
if (doFree < 0) \
R_Free(A); \
else if (A->itype == CHOLMOD_INT) \
cholmod_free_triplet(&A, &c); \
else \
cholmod_l_free_triplet(&A, &cl); \
_EXPR_; \
} \
} while (0)

◆ FREE_THEN [4/4]

#define FREE_THEN (   _EXPR_)
Value:
do { \
if (doFree != 0) { \
if (doFree < 0) \
R_Free(A); \
else \
cholmod_free_dense(&A, &c); \
_EXPR_; \
} \
} while (0)

◆ GET_MEMBER_FROM_FRAME

#define GET_MEMBER_FROM_FRAME (   _MEMBER_,
  _KIND_ 
)
Value:
do { \
PROTECT(tmp = findVarInFrame(rho, _MEMBER_ ## Sym)); \
c. _MEMBER_ = as ## _KIND_(tmp); \
UNPROTECT(1); \
} while (0)

◆ MKMS

#define MKMS (   _FORMAT_,
  ... 
)    mkString(Matrix_sprintf(_FORMAT_, __VA_ARGS__))

◆ SET_FRAME_FROM_MEMBER

#define SET_FRAME_FROM_MEMBER (   _MEMBER_,
  _KIND_ 
)
Value:
do { \
PROTECT(tmp = Scalar ## _KIND_(c. _MEMBER_)); \
defineVar(_MEMBER_ ## Sym, tmp, rho); \
UNPROTECT(1); \
} while (0)

Function Documentation

◆ checkpi()

SEXP checkpi ( SEXP  p,
SEXP  i,
int  m,
int  n 
)

Definition at line 5 of file cholmod-common.c.

References _, and MKMS.

Referenced by CsparseMatrix_validate_maybe_sorting(), and sexp_as_cholmod_sparse().

◆ cholmod_dense_as_sexp()

SEXP cholmod_dense_as_sexp ( cholmod_dense *  A,
int  doFree 
)

Coerce from (cholmod_dense *) to [dz]geMatrix.

Allocates an S4 object of class [dz]geMatrix and copies into the slots from members of a pointed-to cholmod_dense struct. The specific class of the result is determined by struct member xtype.

Parameters
Aa pointer to a cholmod_dense struct.
doFreea flag indicating if and how to free A before returning. (0) don't free, (>0) free with cholmod_free_dense, (<0) free with R_Free.
Returns
A [dz]geMatrix.

Definition at line 954 of file cholmod-common.c.

References _, FREE_THEN, GET_SLOT, Matrix_DimSym, Matrix_xSym, newObject(), and SET_SLOT.

Referenced by R_init_Matrix().

◆ cholmod_factor_as_sexp()

SEXP cholmod_factor_as_sexp ( cholmod_factor *  L,
int  doFree 
)

Coerce from (cholmod_factor *) to CHMfactor.

Allocates an S4 object inheriting from virtual class CHMfactor and copies into the slots from members of a pointed-to cholmod_factor struct. The specific class of the result is determined by struct members xtype and is_super.

Parameters
La pointer to a cholmod_factor struct.
doFreea flag indicating if and how to free L before returning. (0) don't free, (>0) free with cholmod_free_factor, (<0) free with R_Free.
Returns
A CHMfactor.

Definition at line 584 of file cholmod-common.c.

References _, FREE_THEN, GET_SLOT, Matrix_DimSym, Matrix_iSym, Matrix_permSym, Matrix_pSym, Matrix_xSym, newObject(), and SET_SLOT.

Referenced by R_init_Matrix().

◆ cholmod_factor_ldetA()

double cholmod_factor_ldetA ( cholmod_factor *  L)

Log determinant from Cholesky factorization.

Computes log(det(A)) given the Cholesky factorization of A as P1 * A * P1' = L1 * D * L1' = L * L', L = L1 * sqrt(D). The result is computed as sum(log(diag(D))) or 2*sum(log(diag(L))), depending on members is_super and is_ll of the supplied struct. Note that CHOLMOD does not require diag(D) to be positive and that this routine does not check (FIXME).

Parameters
La pointer to a cholmod_factor struct. It is assumed that L->xtype=CHOLMOD_REAL.

Definition at line 1017 of file cholmod-common.c.

References _.

Referenced by R_init_Matrix().

◆ cholmod_factor_update()

cholmod_factor * cholmod_factor_update ( cholmod_factor *  L,
cholmod_sparse *  A,
double  beta 
)

Update a Cholesky factorization.

Updates in-place the Cholesky factorization of a symmetric matrix X+alpha*I with the Cholesky factorization of (1) A+beta*I, where A is a symmetric matrix sharing the nonzero pattern of X, or (2) A*A'+beta*I, where A is a general matrix sharing the nonzero pattern of Y, assuming that X = Y*Y'.

Parameters
La pointer to a cholmod_factor struct, to be modified in-place.
Aa pointer to a cholmod_sparse struct.
betaa multiplier, typically positive, to guarantee strict diagonal dominance.
Returns
L.

Definition at line 1064 of file cholmod-common.c.

References _, and c.

Referenced by R_init_Matrix().

◆ cholmod_sparse_as_sexp()

SEXP cholmod_sparse_as_sexp ( cholmod_sparse *  A,
int  doFree,
int  ttype,
int  doLogic,
const char *  diagString,
SEXP  dimnames 
)

Coerce from (cholmod_sparse *) to CsparseMatrix.

Allocates an S4 object inheriting from virtual class CsparseMatrix and copies into the slots from members of a pointed-to cholmod_sparse struct. The specific class of the result is determined by struct members xtype and stype and by arguments ttype and doLogic.

Parameters
Aa pointer to a cholmod_sparse struct.
doFreea flag indicating if and how to free A before returning. (0) don't free, (>0) free with cholmod_free_sparse, (<0) free with R_Free.
ttypea flag indicating if the result should be a .tCMatrix. (0) not .tCMatrix, (>0) .tCMatrix with uplo="U", (<0) .tCMatrix with uplo="L". If ttype=0, then the result is a .gCMatrix or .sCMatrix depending on stype. (0) .gCMatrix, (>0) .sCMatrix with uplo="U", (<0) .sCMatrix with uplo="L".
doLogica flag indicating if the result should be a l.CMatrix if xtype=CHOLMOD_REAL.
diagStringa null-terminated string or NULL. The diag slot of a .tCMatrix result is "N" if and only if diagString is NULL or diagString[0] is 'N'.
dimnamesan R object specifying the Dimnames slot of the result, unused if not a list of length 2.
Returns
A CsparseMatrix.

Definition at line 732 of file cholmod-common.c.

References _, c, FREE_THEN, GET_SLOT, Matrix_diagSym, Matrix_DimNamesSym, Matrix_DimSym, Matrix_iSym, Matrix_pSym, Matrix_uploSym, Matrix_xSym, newObject(), and SET_SLOT.

Referenced by R_init_Matrix().

◆ cholmod_triplet_as_sexp()

SEXP cholmod_triplet_as_sexp ( cholmod_triplet *  A,
int  doFree,
int  ttype,
int  doLogic,
const char *  diagString,
SEXP  dimnames 
)

Coerce from (cholmod_triplet *) to TsparseMatrix.

Allocates an S4 object inheriting from virtual class TsparseMatrix and copies into the slots from members of a pointed-to cholmod_triplet struct. The specific class of the result is determined by struct members xtype and stype and by arguments ttype and doLogic.

Parameters
Aa pointer to a cholmod_triplet struct.
doFreea flag indicating if and how to free A before returning. (0) don't free, (>0) free with cholmod_free_triplet, (<0) free with R_Free.
ttypea flag indicating if the result should be a .tTMatrix. (0) not .tTMatrix, (>0) .tTMatrix with uplo="U", (<0) .tTMatrix with uplo="L". If ttype=0, then the result is a .gTMatrix or .sTMatrix depending on stype. (0) .gTMatrix, (>0) .sTMatrix with uplo="U", (<0) .sTMatrix with uplo="L".
doLogica flag indicating if the result should be an l.TMatrix if xtype=CHOLMOD_REAL.
diagStringa null-terminated string or NULL. The diag slot of a .tTMatrix result is "N" if and only if diagString is NULL or diagString[0] is 'N'.
dimnamesan R object specifying the Dimnames slot of the result, unused if not a list of length 2.
Returns
A TsparseMatrix.

Definition at line 848 of file cholmod-common.c.

References _, FREE_THEN, GET_SLOT, Matrix_diagSym, Matrix_DimNamesSym, Matrix_DimSym, Matrix_iSym, Matrix_jSym, Matrix_uploSym, Matrix_xSym, newObject(), and SET_SLOT.

Referenced by R_init_Matrix().

◆ numeric_as_cholmod_dense()

cholmod_dense * numeric_as_cholmod_dense ( cholmod_dense *  A,
double *  data,
int  nrow,
int  ncol 
)

Coerce from (double *) to (cholmod_dense *) with given dimensions.

An analogue of base::matrix(data, nrow, ncol), where typeof(data)=="double" and length(data)==nrow*ncol.

Parameters
Aa pointer to a cholmod_dense struct, to be modified in-place.
dataa pointer to an nrow*ncol*sizeof(double) block of memory.
nrowthe desired number of rows.
ncolthe desired number of columns.
Returns
A.

Definition at line 554 of file cholmod-common.c.

Referenced by R_init_Matrix().

◆ R_cholmod_common_envget()

void R_cholmod_common_envget ( void  )

Definition at line 1217 of file cholmod-common.c.

References c, cholmod_common_env, GET_MEMBER_FROM_FRAME, and m0_ordSym.

Referenced by dpCMatrix_trf_(), and R_cholmod_error_handler().

◆ R_cholmod_common_envini()

SEXP R_cholmod_common_envini ( SEXP  rho)

◆ R_cholmod_common_envset()

void R_cholmod_common_envset ( void  )

Definition at line 1181 of file cholmod-common.c.

References c, cholmod_common_env, m0_ordSym, and SET_FRAME_FROM_MEMBER.

Referenced by dpCMatrix_trf_(), and R_cholmod_common_envini().

◆ R_cholmod_error_handler()

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

Definition at line 1092 of file cholmod-common.c.

References _, and R_cholmod_common_envget().

Referenced by R_cholmod_start().

◆ R_cholmod_finish()

int R_cholmod_finish ( cholmod_common *  Common)

Definition at line 1122 of file cholmod-common.c.

References _.

Referenced by R_unload_Matrix().

◆ R_cholmod_start()

int R_cholmod_start ( cholmod_common *  Common)

Definition at line 1104 of file cholmod-common.c.

References _, and R_cholmod_error_handler().

Referenced by R_init_Matrix().

◆ sexp_as_cholmod_dense()

cholmod_dense * sexp_as_cholmod_dense ( cholmod_dense *  A,
SEXP  from 
)

Coerce from [nlidz]geMatrix or vector to (cholmod_dense *)

Sets the members of a pointed-to cholmod_dense struct, using "data" obtained from slots of a [nlidz]geMatrix. The result should not be freed using cholmod_free_dense, as the resulting members point to memory controlled by R, not by CHOLMOD.

Parameters
Aa pointer to a cholmod_dense struct, to be modified in-place.
froman S4 object inheriting from class [nlidz]geMatrix or a traditional vector of type "logical", "integer", "double", or "complex" (to be handled as a 1-column matrix if not a matrix).
Returns
A.

Definition at line 470 of file cholmod-common.c.

References ERROR_INVALID_TYPE, GET_SLOT, Matrix_DimSym, Matrix_xSym, and valid.

Referenced by R_init_Matrix().

◆ sexp_as_cholmod_factor()

cholmod_factor * sexp_as_cholmod_factor ( cholmod_factor *  L,
SEXP  from 
)

Coerce from CHMfactor to (cholmod_factor *)

Sets the members of a pointed-to cholmod_factor struct, using "data" obtained from slots of a CHMfactor. The result should not be freed using cholmod_free_factor, as the resulting members point to memory controlled by R, not by CHOLMOD.

Parameters
La pointer to a cholmod_factor struct, to be modified in-place.
froman S4 object inheriting from virtual class CHMfactor.
Returns
L.

Definition at line 80 of file cholmod-common.c.

References _, c, ERROR_INVALID_CLASS, ERROR_INVALID_TYPE, GET_SLOT, Matrix_DimSym, Matrix_iSym, Matrix_permSym, Matrix_pSym, Matrix_xSym, and valid.

Referenced by R_init_Matrix().

◆ sexp_as_cholmod_sparse()

cholmod_sparse * sexp_as_cholmod_sparse ( cholmod_sparse *  A,
SEXP  from,
Rboolean  checkUnit,
Rboolean  sortInPlace 
)

Coerce from CsparseMatrix to (cholmod_sparse *)

Sets the members of a pointed-to cholmod_sparse struct, using "data" obtained from slots of a CsparseMatrix. The result should not be freed using cholmod_free_sparse, as the resulting members point to memory controlled by R, not by CHOLMOD.

Parameters
Aa pointer to a cholmod_sparse struct, to be modified in-place.
froman S4 object inheriting from virtual class CsparseMatrix.
checkUnita boolean indicating if the unit diagonal of formally unit triangular CsparseMatrix should be allocated.
sortInPlacea boolean indicating if unsorted CsparseMatrix should be sorted in place to avoid an allocation.
Returns
A.

Definition at line 188 of file cholmod-common.c.

References _, c, checkpi(), ERROR_INVALID_CLASS, GET_SLOT, Matrix_diagSym, Matrix_DimSym, Matrix_iSym, Matrix_pSym, Matrix_uploSym, Matrix_xSym, and valid.

Referenced by R_init_Matrix().

◆ sexp_as_cholmod_triplet()

cholmod_triplet * sexp_as_cholmod_triplet ( cholmod_triplet *  A,
SEXP  from,
Rboolean  checkUnit 
)

Coerce from TsparseMatrix to (cholmod_triplet *)

Sets the members of a pointed-to cholmod_triplet struct, using "data" obtained from slots of a TsparseMatrix. The result should not be freed using cholmod_free_sparse, as the resulting members point to memory controlled by R, not by CHOLMOD.

Parameters
Aa pointer to a cholmod_triplet struct, to be modified in-place.
froman S4 object inheriting from virtual class TsparseMatrix.
checkUnita boolean indicating if the unit diagonal of formally unit triangular TsparseMatrix should be allocated.
Returns
A.

Definition at line 340 of file cholmod-common.c.

References ERROR_INVALID_CLASS, GET_SLOT, Matrix_diagSym, Matrix_DimSym, Matrix_iSym, Matrix_pSym, Matrix_uploSym, Matrix_xSym, Matrix_zone, and valid.

Referenced by R_init_Matrix().

Variable Documentation

◆ cholmod_common_env

SEXP cholmod_common_env

◆ dboundSym

SEXP dboundSym
static

Definition at line 1134 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_asisSym

SEXP final_asisSym
static

Definition at line 1141 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_llSym

SEXP final_llSym
static

Definition at line 1143 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_monotonicSym

SEXP final_monotonicSym
static

Definition at line 1145 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_packSym

SEXP final_packSym
static

Definition at line 1144 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_resymbolSym

SEXP final_resymbolSym
static

Definition at line 1146 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ final_superSym

SEXP final_superSym
static

Definition at line 1142 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ grow0Sym

SEXP grow0Sym
static

Definition at line 1135 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ grow1Sym

SEXP grow1Sym
static

Definition at line 1136 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ grow2Sym

SEXP grow2Sym
static

Definition at line 1137 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ m0_ordSym

SEXP m0_ordSym
static

◆ maxrankSym

SEXP maxrankSym
static

Definition at line 1138 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ nmethodsSym

SEXP nmethodsSym
static

Definition at line 1150 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ postorderSym

SEXP postorderSym
static

Definition at line 1151 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ prefer_upperSym

SEXP prefer_upperSym
static

Definition at line 1148 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ prefer_zomplexSym

SEXP prefer_zomplexSym
static

Definition at line 1147 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ quick_return_if_not_posdefSym

SEXP quick_return_if_not_posdefSym
static

Definition at line 1149 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ supernodal_switchSym

SEXP supernodal_switchSym
static

Definition at line 1139 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().

◆ supernodalSym

SEXP supernodalSym
static

Definition at line 1140 of file cholmod-common.c.

Referenced by R_cholmod_common_envini().