Matrix r4655
Loading...
Searching...
No Matches
Macros | Functions
subscript.c File Reference
#include "Mdefines.h"
#include "subscript.h"

Go to the source code of this file.

Macros

#define F_X(_X_)   (_X_)
 
#define F_ND(_X_)   ((_X_) ? 1 : 0)
 
#define F_NS(_X_)   1
 
#define AR21_UP(i, j, m)   i + j + ( j * ( j - 1)) / 2
 
#define AR21_LO(i, j, m)   i + (j * m + j * (m - j - 1)) / 2
 
#define SUB1_START(_SEXPTYPE_)
 
#define SUB1_START_EXTRA(_SEXPTYPE_)
 
#define SUB1_CASES(_SUB1_N_, _SUB1_X_, _F_N_, _F_X_)
 
#define SUB1_N(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_X(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_, _INT_)
 
#define SUB1_START(_SEXPTYPE_)
 
#define SUB1_START_EXTRA(_SEXPTYPE_)
 
#define SUB1_N(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SUB1_LOOP(_NA_SUBSCRIPT_, _NA_, _ZERO_, _ONE_, _F_)
 
#define SORT_LOOP(_MASK_)
 
#define SORT(_CTYPE_, _PTR_)
 
#define XIJ_GE( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)    *(_X_ + _J_ * _M_ + _I_)
 
#define XIJ_TR_U_N(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TR_U_U(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TR_L_N(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TR_L_U(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TP_U_N(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TP_U_U(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TP_L_N(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_TP_L_U(_X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_SY_U( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_SY_L( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_SP_U( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define XIJ_SP_L( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)
 
#define SUB2_START
 
#define SUB2_START_EXTRA(_E_, _R_, _Y_, _DENSE_)
 
#define SUB2_CASES(_SUB2_)
 
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)
 
#define SUB2_LOOP(_FOR_, _XIJ_, _JUMP1_, _JUMP2_, _NA_, _ZERO_, _ONE_)
 
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)
 
#define SUB2_FINISH
 
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)
 
#define SUB2_LOOP(_MASK_)
 
#define SUB2_LOOP(_MASK_)
 
#define SUB2_FINISH
 
#define SUB2_LOOP(_MASK_)
 
#define SUB2_LOOP(_MASK_)
 
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)
 
#define SUB2_WORK(_CTYPE_, _PTR_, _ISNZ_)
 
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)
 
#define ERROR_IF_ANYNA(_I_)
 

Functions

static SEXP unpackedMatrix_subscript_1ary (SEXP x, SEXP w, const char *cl)
 
static SEXP packedMatrix_subscript_1ary (SEXP x, SEXP w, const char *cl)
 
static SEXP CsparseMatrix_subscript_1ary (SEXP x, SEXP w, const char *cl)
 
static SEXP RsparseMatrix_subscript_1ary (SEXP x, SEXP w, const char *cl)
 
static SEXP diagonalMatrix_subscript_1ary (SEXP x, SEXP w, const char *cl)
 
static SEXP indMatrix_subscript_1ary (SEXP x, SEXP w)
 
SEXP R_subscript_1ary (SEXP x, SEXP i)
 
static SEXP unpackedMatrix_subscript_1ary_mat (SEXP x, SEXP w, const char *cl)
 
static SEXP packedMatrix_subscript_1ary_mat (SEXP x, SEXP w, const char *cl)
 
static SEXP CsparseMatrix_subscript_1ary_mat (SEXP x, SEXP w, const char *cl)
 
static SEXP RsparseMatrix_subscript_1ary_mat (SEXP x, SEXP w, const char *cl)
 
static SEXP diagonalMatrix_subscript_1ary_mat (SEXP x, SEXP w, const char *cl)
 
static SEXP indMatrix_subscript_1ary_mat (SEXP x, SEXP w)
 
SEXP R_subscript_1ary_mat (SEXP x, SEXP i)
 
static int keep_tr (int *pi, int *pj, int n, int upper, int nonunit, int checkNA)
 
static int keep_sy (int *pi, int *pj, int n, int upper, int checkNA)
 
static int keep_di (int *pi, int *pj, int n, int nonunit, int checkNA, int lwork)
 
static void sort_cr (SEXP obj, const char *cl)
 
static SEXP unpackedMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
static SEXP packedMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
static SEXP CsparseMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
static SEXP RsparseMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
static SEXP diagonalMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
static SEXP indMatrix_subscript_2ary (SEXP x, SEXP i, SEXP j, const char *cl)
 
SEXP R_subscript_2ary (SEXP x, SEXP i, SEXP j)
 

Macro Definition Documentation

◆ AR21_LO

#define AR21_LO (   i,
  j,
 
)    i + (j * m + j * (m - j - 1)) / 2

Definition at line 9 of file subscript.c.

◆ AR21_UP

#define AR21_UP (   i,
  j,
 
)    i + j + ( j * ( j - 1)) / 2

Definition at line 8 of file subscript.c.

◆ ERROR_IF_ANYNA

#define ERROR_IF_ANYNA (   _I_)
Value:
do { \
if ((_I_) != R_NilValue) { \
SETCADR(call, _I_); \
PROTECT(value = eval(call, R_BaseEnv)); \
if (asLogical(value)) \
error(_("NA subscripts in %s not supported for '%s' inheriting from %s"), \
"x[i,j]", "x", "sparseMatrix"); \
UNPROTECT(1); \
} \
} while (0)
#define _(String)
Definition Mdefines.h:44

◆ F_ND

#define F_ND (   _X_)    ((_X_) ? 1 : 0)

Definition at line 5 of file subscript.c.

◆ F_NS

#define F_NS (   _X_)    1

Definition at line 6 of file subscript.c.

◆ F_X

#define F_X (   _X_)    (_X_)

Definition at line 4 of file subscript.c.

◆ SORT

#define SORT (   _CTYPE_,
  _PTR_ 
)
Value:
do { \
_CTYPE_ *px = _PTR_(x), *workD; \
Matrix_Calloc(workD, nnz, _CTYPE_); \
SORT_LOOP(SHOW); \
Matrix_Free(workD, nnz); \
} while (0)
#define SHOW(...)
Definition Mdefines.h:201

◆ SORT_LOOP

#define SORT_LOOP (   _MASK_)

◆ SUB1_CASES

#define SUB1_CASES (   _SUB1_N_,
  _SUB1_X_,
  _F_N_,
  _F_X_ 
)
Value:
do { \
switch (cl[0]) { \
case 'n': \
_SUB1_N_(int, LOGICAL, NA_LOGICAL, 0, 1, _F_N_); \
break; \
case 'l': \
_SUB1_X_(int, LOGICAL, NA_LOGICAL, 0, 1, _F_X_); \
break; \
case 'i': \
_SUB1_X_(int, INTEGER, NA_INTEGER, 0, 1, _F_X_); \
break; \
case 'd': \
_SUB1_X_(double, REAL, NA_REAL, 0.0, 1.0, _F_X_); \
break; \
case 'z': \
_SUB1_X_(Rcomplex, COMPLEX, \
break; \
default: \
break; \
} \
} while (0)
cholmod_common cl
Definition cholmod-etc.c:6
Rcomplex Matrix_zna
Definition init.c:26
Rcomplex Matrix_zone
Definition init.c:26
Rcomplex Matrix_zzero
Definition init.c:26

◆ SUB1_LOOP [1/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else { \
i_ = pw0[l] - 1; \
j_ = pw1[l] - 1; \
if (ge) \
pres[l] = _F_(px[j_ * m + i_]); \
else if (tr) { \
if ((upper) ? i_ > j_ : i_ < j_) \
pres[l] = _ZERO_; \
else if (!nonunit && i_ == j_) \
pres[l] = _ONE_; \
else \
pres[l] = _F_(px[j_ * m + i_]); \
} else { \
if ((upper) ? i_ > j_ : i_ < j_) \
pres[l] = _F_(px[i_ * m + j_]); \
else \
pres[l] = _F_(px[j_ * m + i_]); \
} \
} \
} \
} while (0)

◆ SUB1_LOOP [2/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)

◆ SUB1_LOOP [3/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)

◆ SUB1_LOOP [4/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)

◆ SUB1_LOOP [5/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else if (pw0[l] != pw1[l]) \
pres[l] = _ZERO_; \
else if (!nonunit) \
pres[l] = _ONE_; \
else \
pres[l] = _F_(px[pw0[l] - 1]); \
} \
} while (0)

◆ SUB1_LOOP [6/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else if (!mg) \
pres[l] = pw1[l] == pperm[pw0[l] - 1]; \
else \
pres[l] = pw0[l] == pperm[pw1[l] - 1]; \
} \
} while (0)

◆ SUB1_LOOP [7/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)
Value:
do { \
_INT_ index, i_, j_; \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else { \
index = (_INT_) pw[l] - 1; \
if (ge) \
pres[l] = _F_(px[index]); \
else { \
i_ = index % m; \
j_ = index / m; \
if (tr) { \
if ((upper) ? i_ > j_ : i_ < j_) \
pres[l] = _ZERO_; \
else if (!nonunit && i_ == j_) \
pres[l] = _ONE_; \
else \
pres[l] = _F_(px[index]); \
} else { \
if ((upper) ? i_ > j_ : i_ < j_) \
pres[l] = _F_(px[i_ * m + j_]); \
else \
pres[l] = _F_(px[index]); \
} \
} \
} \
} \
} while (0)

◆ SUB1_LOOP [8/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)

◆ SUB1_LOOP [9/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)

◆ SUB1_LOOP [10/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)

◆ SUB1_LOOP [11/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)
Value:
do { \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else if ((index = (Matrix_int_fast64_t) pw[l] - 1) % n1a != 0) \
pres[l] = _ZERO_; \
else if (!nonunit) \
pres[l] = _ONE_; \
else \
pres[l] = _F_(px[index / n1a]); \
} \
} while (0)
long long Matrix_int_fast64_t
Definition Mdefines.h:27

◆ SUB1_LOOP [12/12]

#define SUB1_LOOP (   _NA_SUBSCRIPT_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_,
  _INT_ 
)
Value:
do { \
_INT_ index; \
for (l = 0; l < len; ++l) { \
if (_NA_SUBSCRIPT_) \
pres[l] = _NA_; \
else { \
index = (_INT_) pw[l] - 1; \
i_ = (int) (index % m); \
j_ = (int) (index / m); \
if (!mg) \
pres[l] = j_ == pperm[i_] - 1; \
else \
pres[l] = i_ == pperm[j_] - 1; \
} \
} \
} while (0)

◆ SUB1_N [1/2]

#define SUB1_N (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
_CTYPE_ *pres = _PTR_(res); \
if (TYPEOF(w) == INTSXP) { \
int *pw = INTEGER(w); \
if (mn64 >= INT_MAX) { \
/* index is never out of bounds */ \
SUB1_LOOP((pw[l] == NA_INTEGER), \
_NA_, _ZERO_, _ONE_, _F_, Matrix_int_fast64_t); \
} else { \
int mn = m * n; \
SUB1_LOOP((pw[l] == NA_INTEGER || pw[l] > mn), \
_NA_, _ZERO_, _ONE_, _F_, int); \
} \
} else { \
double *pw = REAL(w); \
if (mn64 >= 0x1.0p+53) \
/* m*n may not be exactly representable as double */ \
/* but it does not exceed INT_MAX * INT_MAX */ \
SUB1_LOOP((ISNAN(pw[l]) || pw[l] >= 0x1.0p+62 || \
(Matrix_int_fast64_t) pw[l] > mn64), \
_NA_, _ZERO_, _ONE_, _F_, Matrix_int_fast64_t); \
else { \
double mn1a = (double) m * n + 1.0; \
SUB1_LOOP((ISNAN(pw[l]) || pw[l] >= mn1a), \
_NA_, _ZERO_, _ONE_, _F_, Matrix_int_fast64_t); \
} \
} \
} while (0)

◆ SUB1_N [2/2]

#define SUB1_N (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
_CTYPE_ *pres = _PTR_(res); \
SUB1_LOOP((pw0[l] == NA_INTEGER || pw1[l] == NA_INTEGER), \
_NA_, _ZERO_, _ONE_, _F_); \
} while (0)

◆ SUB1_START [1/2]

#define SUB1_START (   _SEXPTYPE_)
Value:
SEXPTYPE typ = _SEXPTYPE_; \
R_xlen_t l = 0, len = XLENGTH(w); \
SEXP res = allocVector(typ, len); \
if (len == 0) \
return res; \
PROTECT(res); \
\
SEXP dim = PROTECT(GET_SLOT(x, Matrix_DimSym)); \
int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1]; \
UNPROTECT(1);
#define GET_SLOT(x, what)
Definition Mdefines.h:85
SEXP Matrix_DimSym
Definition Msymbols.h:3

◆ SUB1_START [2/2]

#define SUB1_START (   _SEXPTYPE_)
Value:
SEXPTYPE typ = _SEXPTYPE_; \
int l = 0, len = (int) (XLENGTH(w) / 2); \
SEXP res = allocVector(typ, len); \
if (len == 0) \
return res; \
PROTECT(res); \
int *pw0 = INTEGER(w), *pw1 = pw0 + len;

◆ SUB1_START_EXTRA [1/2]

#define SUB1_START_EXTRA (   _SEXPTYPE_)
Value:
SUB1_START(_SEXPTYPE_); \
\
int ge = cl[1] == 'g', tr = cl[1] == 't', upper = 1, nonunit = 1; \
if (!ge) { \
SEXP uplo = PROTECT(GET_SLOT(x, Matrix_uploSym)); \
upper = *CHAR(STRING_ELT(uplo, 0)) == 'U'; \
UNPROTECT(1); \
if (tr) { \
SEXP diag = PROTECT(GET_SLOT(x, Matrix_diagSym)); \
nonunit = *CHAR(STRING_ELT(diag, 0)) == 'N'; \
UNPROTECT(1); \
} \
}
SEXP Matrix_diagSym
Definition Msymbols.h:11
SEXP Matrix_uploSym
Definition Msymbols.h:21
#define SUB1_START(_SEXPTYPE_)

◆ SUB1_START_EXTRA [2/2]

#define SUB1_START_EXTRA (   _SEXPTYPE_)
Value:
SUB1_START(_SEXPTYPE_); \
\
SEXP dim = PROTECT(GET_SLOT(x, Matrix_DimSym)); \
int m = INTEGER(dim)[0]; \
UNPROTECT(1); \
\
int ge = cl[1] == 'g', tr = cl[1] == 't', upper = 1, nonunit = 1; \
if (!ge) { \
SEXP uplo = PROTECT(GET_SLOT(x, Matrix_uploSym)); \
upper = *CHAR(STRING_ELT(uplo, 0)) == 'U'; \
UNPROTECT(1); \
if (tr) { \
SEXP diag = PROTECT(GET_SLOT(x, Matrix_diagSym)); \
nonunit = *CHAR(STRING_ELT(diag, 0)) == 'N'; \
UNPROTECT(1); \
} \
}

◆ SUB1_X

#define SUB1_X (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_,
  _F_ 
)
Value:
do { \
PROTECT(x = GET_SLOT(x, Matrix_xSym)); \
_CTYPE_ *px = _PTR_(x); \
SUB1_N(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_, _F_); \
UNPROTECT(1); \
} while (0)
SEXP Matrix_xSym
Definition Msymbols.h:22

◆ SUB2 [1/5]

#define SUB2 (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_ 
)

◆ SUB2 [2/5]

#define SUB2 (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_ 
)

◆ SUB2 [3/5]

#define SUB2 (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_ 
)
Value:
do { \
_CTYPE_ *px0 = _PTR_(x0), *px1 = _PTR_(x1); \
SUB2_LOOP(SHOW); \
} while (0)

◆ SUB2 [4/5]

#define SUB2 (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_ 
)
Value:
do { \
_CTYPE_ *px0 = _PTR_(x0), *px1 = _PTR_(x1); \
while (ni--) \
*(px1++) = \
(*(pi++) != (j_ = *(pj++))) \
? _ZERO_ \
: ((nonunit) ? px0[j_ - 1] : _ONE_); \
} while (0)

◆ SUB2 [5/5]

#define SUB2 (   _CTYPE_,
  _PTR_,
  _NA_,
  _ZERO_,
  _ONE_ 
)
Value:
do { \
_CTYPE_ *px0 = _PTR_(x0), *px1 = _PTR_(x1); \
for (kj = 0; kj < nj; ++kj) { \
j_ = (mj) ? kj : pj[kj] - 1; \
if (!nonunit || work[j_]) { \
for (ki = 0; ki < ni; ++ki) { \
if (((mi) ? ki : pi[ki] - 1) == j_) { \
*(pi1++) = ki; \
*(px1++) = (nonunit) ? px0[j_] : _ONE_; \
} \
} \
} \
} \
} while (0)

◆ SUB2_CASES

#define SUB2_CASES (   _SUB2_)
Value:
do { \
switch (cl[0]) { \
case 'n': \
case 'l': \
_SUB2_(int, LOGICAL, NA_LOGICAL, 0, 1); \
break; \
case 'i': \
_SUB2_(int, INTEGER, NA_INTEGER, 0, 1); \
break; \
case 'd': \
_SUB2_(double, REAL, NA_REAL, 0.0, 1.0); \
break; \
case 'z': \
_SUB2_(Rcomplex, COMPLEX, \
break; \
default: \
break; \
} \
} while (0)

◆ SUB2_FINISH [1/2]

#define SUB2_FINISH
Value:
if (nnz > INT_MAX) \
error(_("%s too dense for %s; would have more than %s nonzero entries"), \
"x[i,j]", "[CR]sparseMatrix", "2^31-1"); \
\
PROTECT(i1 = allocVector(INTSXP, (R_xlen_t) nnz)); \
pi1 = INTEGER(i1); \
\
if (cl[0] == 'n') \
SUB2_LOOP(HIDE); \
else { \
SEXP x0 = PROTECT(GET_SLOT(x, Matrix_xSym)), \
x1 = PROTECT(allocVector(TYPEOF(x0), (R_xlen_t) nnz)); \
SUB2_CASES(SUB2); \
SET_SLOT(res, Matrix_xSym, x1); \
UNPROTECT(2); /* x1, x0 */ \
}
#define HIDE(...)
Definition Mdefines.h:202
#define SUB2(_CTYPE_, _PTR_, _NA_, _ZERO_, _ONE_)

◆ SUB2_FINISH [2/2]

#define SUB2_FINISH
Value:
if (nnz > INT_MAX) \
error(_("%s too dense for %s; would have more than %s nonzero entries"), \
"x[i,j]", "[CR]sparseMatrix", "2^31-1"); \
\
PROTECT(j1 = allocVector(INTSXP, (R_xlen_t) nnz)); \
pj1 = INTEGER(j1); \
\
if (cl[0] == 'n') \
SUB2_LOOP(HIDE); \
else { \
SEXP x0 = PROTECT(GET_SLOT(x, Matrix_xSym)), \
x1 = PROTECT(allocVector(TYPEOF(x0), (R_xlen_t) nnz)); \
SUB2_CASES(SUB2); \
SET_SLOT(res, Matrix_xSym, x1); \
UNPROTECT(2); /* x1, x0 */ \
}

◆ SUB2_LOOP [1/5]

#define SUB2_LOOP (   _FOR_,
  _XIJ_,
  _JUMP1_,
  _JUMP2_,
  _NA_,
  _ZERO_,
  _ONE_ 
)

◆ SUB2_LOOP [2/5]

#define SUB2_LOOP (   _MASK_)
Value:
do { \
for (kj = 0; kj < nj; ++kj) { \
k = pp0[pj[kj] - 1]; \
kend = pp0[pj[kj]]; \
d = kend - k; \
if (d) { \
Matrix_memcpy(pi1, pi0 + k, d, sizeof(int)); \
pi1 += d; \
_MASK_(Matrix_memcpy(px1, px0 + k, d, sizeof(*px1))); \
_MASK_(px1 += d); \
} \
} \
} while (0)
void * Matrix_memcpy(void *dest, const void *src, R_xlen_t length, size_t size)
Definition utils.c:70

◆ SUB2_LOOP [3/5]

#define SUB2_LOOP (   _MASK_)
Value:
do { \
for (kj = 0; kj < nj; ++kj) { \
j_ = (mj) ? kj : pj[kj] - 1; \
k = pp0[j_]; \
kend = pp0[j_ + 1]; \
while (k < kend) { \
i_ = pi0[k]; \
d = workA[i_]; \
ki = workB[i_]; \
while (d--) { \
*(pi1++) = ki; \
_MASK_(*(px1++) = px0[k]); \
ki = workC[ki]; \
} \
++k; \
} \
} \
} while (0)

◆ SUB2_LOOP [4/5]

#define SUB2_LOOP (   _MASK_)
Value:
do { \
for (ki = 0; ki < ni; ++ki) { \
k = pp0[pi[ki] - 1]; \
kend = pp0[pi[ki]]; \
d = kend - k; \
if (d) { \
Matrix_memcpy(pj1, pj0 + k, d, sizeof(int)); \
pj1 += d; \
_MASK_(Matrix_memcpy(px1, px0 + k, d, sizeof(*px1))); \
_MASK_(px1 += d); \
} \
} \
} while (0)

◆ SUB2_LOOP [5/5]

#define SUB2_LOOP (   _MASK_)
Value:
do { \
for (ki = 0; ki < ni; ++ki) { \
i_ = (mi) ? ki : pi[ki] - 1; \
k = pp0[i_]; \
kend = pp0[i_ + 1]; \
while (k < kend) { \
j_ = pj0[k]; \
d = workA[j_]; \
kj = workB[j_]; \
while (d--) { \
*(pj1++) = kj; \
_MASK_(*(px1++) = px0[k]); \
kj = workC[kj]; \
} \
++k; \
} \
} \
} while (0)

◆ SUB2_START

#define SUB2_START
Value:
SEXP dim = PROTECT(GET_SLOT(x, Matrix_DimSym)); \
int *pdim = INTEGER(dim), m = pdim[0], n = pdim[1]; \
UNPROTECT(1); /* dim */ \
\
int ki, kj, \
mi = i == R_NilValue, \
mj = j == R_NilValue, \
ni = (mi) ? m : LENGTH(i), \
nj = (mj) ? n : LENGTH(j), \
*pi = (mi) ? NULL : INTEGER(i), \
*pj = (mj) ? NULL : INTEGER(j);

◆ SUB2_START_EXTRA

#define SUB2_START_EXTRA (   _E_,
  _R_,
  _Y_,
  _DENSE_ 
)

◆ SUB2_WORK

#define SUB2_WORK (   _CTYPE_,
  _PTR_,
  _ISNZ_ 
)
Value:
do { \
_CTYPE_ *px0 = _PTR_(x0); \
for (j_ = 0; j_ < n; ++j_) \
work[j_] = _ISNZ_(px0[j_]); \
} while (0)

◆ XIJ_GE

#define XIJ_GE (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)     *(_X_ + _J_ * _M_ + _I_)

Definition at line 1092 of file subscript.c.

◆ XIJ_SP_L

#define XIJ_SP_L (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ >= _J_) \
? *(_X_ + AR21_LO(_I_, _J_, _M_)) \
: *(_X_ + AR21_LO(_J_, _I_, _M_)))
#define AR21_LO(i, j, m)
Definition subscript.c:9

Definition at line 1150 of file subscript.c.

◆ XIJ_SP_U

#define XIJ_SP_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ <= _J_) \
? *(_X_ + AR21_UP(_I_, _J_, _M_)) \
: *(_X_ + AR21_UP(_J_, _I_, _M_)))
#define AR21_UP(i, j, m)
Definition subscript.c:8

Definition at line 1145 of file subscript.c.

◆ XIJ_SY_L

#define XIJ_SY_L (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ >= _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: XIJ_GE(_X_, _J_, _I_, _M_, _ZERO_, _ONE_))
#define XIJ_GE( _X_, _I_, _J_, _M_, _ZERO_, _ONE_)
Definition subscript.c:1092

Definition at line 1140 of file subscript.c.

◆ XIJ_SY_U

#define XIJ_SY_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ <= _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: XIJ_GE(_X_, _J_, _I_, _M_, _ZERO_, _ONE_))

Definition at line 1135 of file subscript.c.

◆ XIJ_TP_L_N

#define XIJ_TP_L_N (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ >= _J_) \
? *(_X_ + AR21_LO(_I_, _J_, _M_)) \
: _ZERO_)

Definition at line 1125 of file subscript.c.

◆ XIJ_TP_L_U

#define XIJ_TP_L_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ > _J_) \
? *(_X_ + AR21_LO(_I_, _J_, _M_)) \
: ((_I_ == _J_) ? _ONE_ : _ZERO_))

Definition at line 1130 of file subscript.c.

◆ XIJ_TP_U_N

#define XIJ_TP_U_N (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ <= _J_) \
? *(_X_ + AR21_UP(_I_, _J_, _M_)) \
: _ZERO_)

Definition at line 1115 of file subscript.c.

◆ XIJ_TP_U_U

#define XIJ_TP_U_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ < _J_) \
? *(_X_ + AR21_UP(_I_, _J_, _M_)) \
: ((_I_ == _J_) ? _ONE_ : _ZERO_))

Definition at line 1120 of file subscript.c.

◆ XIJ_TR_L_N

#define XIJ_TR_L_N (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ >= _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: _ZERO_)

Definition at line 1105 of file subscript.c.

◆ XIJ_TR_L_U

#define XIJ_TR_L_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ > _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: ((_I_ == _J_) ? _ONE_ : _ZERO_))

Definition at line 1110 of file subscript.c.

◆ XIJ_TR_U_N

#define XIJ_TR_U_N (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ <= _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: _ZERO_)

Definition at line 1095 of file subscript.c.

◆ XIJ_TR_U_U

#define XIJ_TR_U_U (   _X_,
  _I_,
  _J_,
  _M_,
  _ZERO_,
  _ONE_ 
)
Value:
((_I_ < _J_) \
? XIJ_GE(_X_, _I_, _J_, _M_, _ZERO_, _ONE_) \
: ((_I_ == _J_) ? _ONE_ : _ZERO_))

Definition at line 1100 of file subscript.c.

Function Documentation

◆ CsparseMatrix_subscript_1ary()

static SEXP CsparseMatrix_subscript_1ary ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 203 of file subscript.c.

References cl, F_NS, F_X, GET_SLOT, kindToType(), Matrix_iSym, Matrix_pSym, SUB1_CASES, SUB1_N, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary().

◆ CsparseMatrix_subscript_1ary_mat()

static SEXP CsparseMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 596 of file subscript.c.

References cl, F_NS, F_X, GET_SLOT, kindToType(), Matrix_iSym, Matrix_pSym, SUB1_CASES, SUB1_N, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary_mat().

◆ CsparseMatrix_subscript_2ary()

static SEXP CsparseMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

◆ diagonalMatrix_subscript_1ary()

static SEXP diagonalMatrix_subscript_1ary ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 337 of file subscript.c.

References cl, F_ND, F_X, GET_SLOT, kindToType(), Matrix_diagSym, SUB1_CASES, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary().

◆ diagonalMatrix_subscript_1ary_mat()

static SEXP diagonalMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 722 of file subscript.c.

References cl, F_ND, F_X, GET_SLOT, kindToType(), Matrix_diagSym, SUB1_CASES, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary_mat().

◆ diagonalMatrix_subscript_2ary()

static SEXP diagonalMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

◆ indMatrix_subscript_1ary()

static SEXP indMatrix_subscript_1ary ( SEXP  x,
SEXP  w 
)
static

Definition at line 370 of file subscript.c.

References GET_SLOT, Matrix_marginSym, Matrix_permSym, SUB1_N, and SUB1_START.

Referenced by R_subscript_1ary().

◆ indMatrix_subscript_1ary_mat()

static SEXP indMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w 
)
static

Definition at line 753 of file subscript.c.

References GET_SLOT, Matrix_marginSym, Matrix_permSym, SUB1_N, and SUB1_START.

Referenced by R_subscript_1ary_mat().

◆ indMatrix_subscript_2ary()

static SEXP indMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

◆ keep_di()

static int keep_di ( int *  pi,
int *  pj,
int  n,
int  nonunit,
int  checkNA,
int  lwork 
)
static

Definition at line 946 of file subscript.c.

References Matrix_Calloc, and Matrix_Free.

Referenced by diagonalMatrix_subscript_2ary().

◆ keep_sy()

static int keep_sy ( int *  pi,
int *  pj,
int  n,
int  upper,
int  checkNA 
)
static

Definition at line 915 of file subscript.c.

◆ keep_tr()

static int keep_tr ( int *  pi,
int *  pj,
int  n,
int  upper,
int  nonunit,
int  checkNA 
)
static

Definition at line 843 of file subscript.c.

◆ packedMatrix_subscript_1ary()

static SEXP packedMatrix_subscript_1ary ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 147 of file subscript.c.

References cl, F_ND, F_X, kindToType(), SUB1_CASES, SUB1_START_EXTRA, and SUB1_X.

Referenced by R_subscript_1ary().

◆ packedMatrix_subscript_1ary_mat()

static SEXP packedMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 540 of file subscript.c.

References cl, F_ND, F_X, kindToType(), SUB1_CASES, SUB1_START_EXTRA, and SUB1_X.

Referenced by R_subscript_1ary_mat().

◆ packedMatrix_subscript_2ary()

static SEXP packedMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

Definition at line 1410 of file subscript.c.

References _, GET_SLOT, Matrix_xSym, SET_SLOT, SUB2, SUB2_CASES, and SUB2_START_EXTRA.

Referenced by R_subscript_2ary().

◆ R_subscript_1ary()

SEXP R_subscript_1ary ( SEXP  x,
SEXP  i 
)

◆ R_subscript_1ary_mat()

SEXP R_subscript_1ary_mat ( SEXP  x,
SEXP  i 
)

◆ R_subscript_2ary()

SEXP R_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j 
)

◆ RsparseMatrix_subscript_1ary()

static SEXP RsparseMatrix_subscript_1ary ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 270 of file subscript.c.

References cl, F_NS, F_X, GET_SLOT, kindToType(), Matrix_jSym, Matrix_pSym, SUB1_CASES, SUB1_N, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary().

◆ RsparseMatrix_subscript_1ary_mat()

static SEXP RsparseMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 659 of file subscript.c.

References cl, F_NS, F_X, GET_SLOT, kindToType(), Matrix_jSym, Matrix_pSym, SUB1_CASES, SUB1_N, SUB1_START, and SUB1_X.

Referenced by R_subscript_1ary_mat().

◆ RsparseMatrix_subscript_2ary()

static SEXP RsparseMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

◆ sort_cr()

static void sort_cr ( SEXP  obj,
const char *  cl 
)
static

◆ unpackedMatrix_subscript_1ary()

static SEXP unpackedMatrix_subscript_1ary ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 12 of file subscript.c.

References cl, F_ND, F_X, kindToType(), SUB1_CASES, SUB1_START_EXTRA, and SUB1_X.

Referenced by R_subscript_1ary().

◆ unpackedMatrix_subscript_1ary_mat()

static SEXP unpackedMatrix_subscript_1ary_mat ( SEXP  x,
SEXP  w,
const char *  cl 
)
static

Definition at line 462 of file subscript.c.

References cl, F_ND, F_X, kindToType(), SUB1_CASES, SUB1_START_EXTRA, and SUB1_X.

Referenced by R_subscript_1ary_mat().

◆ unpackedMatrix_subscript_2ary()

static SEXP unpackedMatrix_subscript_2ary ( SEXP  x,
SEXP  i,
SEXP  j,
const char *  cl 
)
static

Definition at line 1156 of file subscript.c.

References _, GET_SLOT, Matrix_xSym, SET_SLOT, SUB2, SUB2_CASES, and SUB2_START_EXTRA.

Referenced by R_subscript_2ary().