Matrix r5059
Loading...
Searching...
No Matches
matmult.c File Reference
#include "Lapack-etc.h"
#include "cholmod-etc.h"
#include "Mdefines.h"
#include "M5.h"
#include "idz.h"
#include "coerce.h"

Go to the source code of this file.

Macros

#define CONJ2(_X_, _M_, _N_)
 
#define CONJ1(_X_, _N_)
 
#define DO_S3(_A_, _TRANS_, _PID_, _ISV_)
 
#define DO_AS(_A_, _CLASS_, _TRANS_, _PID_)
 
#define DO_TR
 
#define ASMODE(_TRANS_)
 
#define DO_S3(_A_, _TRANS_, _PID_, _ISV_)
 
#define DO_AS(_A_, _CLASS_, _TRANS_, _PID_)
 
#define zSCALE(x, y)
 
#define dSCALE(x, y)
 
#define lSCALE(x, y)
 
#define SCALE3(t, index)
 
#define SCALE(c, index)
 
#define SCALE(c, index)
 
#define SCALE(c, index)
 
#define DO_S3(_A_, _TRANS_, _PID_, _ISV_)
 
#define DO_AS(_A_, _CLASS_, _TRANS_, _PID_)
 

Functions

SEXP dense_transpose (SEXP, const char *, char)
 
SEXP sparse_transpose (SEXP, const char *, char, int)
 
SEXP sparse_dropzero (SEXP, const char *, double)
 
SEXP sparse_diag_U2N (SEXP, const char *)
 
static void matmultDim (SEXP x, SEXP y, char *xtrans, char *ytrans, char *ztrans, int *m, int *n, int *v)
 
static void matmultDN (SEXP dest, SEXP asrc, int ai, SEXP bsrc, int bi)
 
static SEXP geMatrix_matmult (SEXP a, SEXP b, char atrans, char btrans)
 
static SEXP syMatrix_matmult (SEXP a, SEXP b, char atrans, char btrans, char aside)
 
static SEXP spMatrix_matmult (SEXP a, SEXP b, char atrans, char btrans, char aside)
 
static SEXP trMatrix_matmult (SEXP a, SEXP b, char atrans, char btrans, char aside, int triangular)
 
static SEXP tpMatrix_matmult (SEXP a, SEXP b, char atrans, char btrans, char aside, int triangular)
 
SEXP R_dense_matmult (SEXP s_x, SEXP s_y, SEXP s_xtrans, SEXP s_ytrans)
 
static SEXP gCgCMatrix_matmult (SEXP x, SEXP y, char xtrans, char ytrans, char ztrans, int triangular, int boolean)
 
static SEXP gCgeMatrix_matmult (SEXP x, SEXP y, int xtrans, char ytrans, char ztrans, int triangular, int symmetric)
 
SEXP R_sparse_matmult (SEXP s_x, SEXP s_y, SEXP s_xtrans, SEXP s_ytrans, SEXP s_ztrans, SEXP s_boolean)
 
static void dense_colscale (SEXP obj, SEXP d, int m, int n, char ul, char nu)
 
static void dense_rowscale (SEXP obj, SEXP d, int m, int n, char ul, char nu)
 
static void Csparse_colscale (SEXP obj, SEXP d)
 
static void Csparse_rowscale (SEXP obj, SEXP d, SEXP iSym)
 
static void Tsparse_rowscale (SEXP obj, SEXP d, SEXP iSym)
 
SEXP R_diagonal_matmult (SEXP s_x, SEXP s_y, SEXP s_xtrans, SEXP s_ytrans, SEXP s_boolean)
 

Variables

static const char * valid_matmult []
 

Macro Definition Documentation

◆ ASMODE

#define ASMODE ( _TRANS_)
Value:
((boolean) ? 0 : (((_TRANS_) != 'C') ? 1 : 2))

Referenced by gCgCMatrix_matmult().

◆ CONJ1

#define CONJ1 ( _X_,
_N_ )
Value:
do { \
size_t n = (size_t) _N_, xlen = PACKED_LENGTH(n); \
Rcomplex *x = (Rcomplex *) _X_; \
Rcomplex *y = (Rcomplex *) R_alloc(xlen, sizeof(Rcomplex)); \
zvconj(x, y, xlen); \
_X_ = y; \
} while (0)
#define PACKED_LENGTH(n)
Definition Mdefines.h:132

Definition at line 161 of file matmult.c.

Referenced by spMatrix_matmult(), and tpMatrix_matmult().

◆ CONJ2

#define CONJ2 ( _X_,
_M_,
_N_ )
Value:
do { \
size_t m = (size_t) _M_, n = (size_t) _N_, xlen = m * n; \
Rcomplex *x = (Rcomplex *) _X_; \
Rcomplex *y = (Rcomplex *) R_alloc(xlen, sizeof(Rcomplex)); \
zvconj(x, y, xlen); \
_X_ = y; \
} while (0)

Definition at line 152 of file matmult.c.

Referenced by gCgeMatrix_matmult(), spMatrix_matmult(), and syMatrix_matmult().

◆ DO_AS [1/3]

#define DO_AS ( _A_,
_CLASS_,
_TRANS_,
_PID_ )
Value:
do { \
if (_CLASS_[0] != kind) { \
REPROTECT(_A_ = dense_as_kind(_A_, _CLASS_, kind, 0), _PID_); \
_CLASS_ = Matrix_class(_A_, valid, 6, __func__); \
} \
} while (0)
SEXP dense_as_kind(SEXP, const char *, char, int)
Definition coerce.c:2000
const char * Matrix_class(SEXP, const char **, int, const char *)
Definition objects.c:112

Referenced by R_dense_matmult(), R_diagonal_matmult(), and R_sparse_matmult().

◆ DO_AS [2/3]

#define DO_AS ( _A_,
_CLASS_,
_TRANS_,
_PID_ )
Value:
do { \
if (_CLASS_[2] != 'C' && _TRANS_ != 'N') { \
if (_CLASS_[2] != 'R' && _CLASS_[2] != 'T') { \
REPROTECT(_A_ = dense_as_sparse(_A_, _CLASS_, 'R'), _PID_); \
_CLASS_ = Matrix_class(_A_, valid, 6, __func__); \
} \
REPROTECT(_A_ = sparse_transpose(_A_, _CLASS_, _TRANS_, 1), _PID_); \
_CLASS_ = Matrix_class(_A_, valid, 6, __func__); \
_TRANS_ = 'N'; \
} \
if (_CLASS_[2] != 'C') { \
if (_CLASS_[2] != 'R' && _CLASS_[2] != 'T') \
REPROTECT(_A_ = dense_as_sparse(_A_, _CLASS_, 'C'), _PID_); \
else \
REPROTECT(_A_ = sparse_as_Csparse(_A_, _CLASS_), _PID_); \
_CLASS_ = Matrix_class(_A_, valid, 6, __func__); \
} \
if (_TRANS_ != 'N' && _CLASS_[1] == 's' && \
(_CLASS_[0] != 'z' || TRANS(_A_) == _TRANS_)) \
_TRANS_ = 'N'; \
if (_CLASS_[0] != kind) { \
if (boolean) \
REPROTECT(_A_ = sparse_dropzero(_A_, _CLASS_, 0.0), _PID_); \
else { \
REPROTECT(_A_ = sparse_as_kind(_A_, _CLASS_, kind), _PID_); \
_CLASS_ = Matrix_class(_A_, valid, 6, __func__); \
} \
} \
} while (0)
SEXP sparse_as_kind(SEXP, const char *, char)
Definition coerce.c:2076
SEXP sparse_as_Csparse(SEXP, const char *)
Definition coerce.c:2731
#define TRANS(x)
Definition Mdefines.h:106
SEXP dense_as_sparse(SEXP from, const char *class, char repr)
Definition coerce.c:1351
SEXP sparse_transpose(SEXP, const char *, char, int)
Definition t.c:52
SEXP sparse_dropzero(SEXP, const char *, double)
Definition dropzero.c:4

◆ DO_AS [3/3]

#define DO_AS ( _A_,
_CLASS_,
_TRANS_,
_PID_ )

◆ DO_S3 [1/3]

#define DO_S3 ( _A_,
_TRANS_,
_PID_,
_ISV_ )
Value:
do { \
if (TYPEOF(_A_) != OBJSXP) { \
REPROTECT(_A_ = matrix_as_dense(_A_, ",ge", '\0', '\0', '\0', (_TRANS_ != 'N') ? 0 : 1, 0), _PID_); \
if (_ISV_) { \
/* Vector: discard names and don't transpose again */ \
SET_VECTOR_ELT(DIMNAMES(_A_, 0), \
(_TRANS_ != 'N') ? 1 : 0, R_NilValue); \
_TRANS_ = 'N'; \
} \
} \
} while (0)
#define DIMNAMES(x, mode)
Definition Mdefines.h:96
#define TYPEOF(s)
Definition Mdefines.h:123
SEXP matrix_as_dense(SEXP from, const char *zzz, char ul, char ct, char nu, int mg, int new)
Definition coerce.c:262

Referenced by R_dense_matmult(), R_diagonal_matmult(), and R_sparse_matmult().

◆ DO_S3 [2/3]

#define DO_S3 ( _A_,
_TRANS_,
_PID_,
_ISV_ )
Value:
do { \
if (TYPEOF(_A_) != OBJSXP) { \
if (boolean == NA_LOGICAL || !boolean) \
REPROTECT(_A_ = matrix_as_dense (_A_, ",ge", '\0', '\0', '\0', (_TRANS_ != 'N') ? 0 : 1, 0), _PID_); \
else if (_TRANS_ != 'N') \
REPROTECT(_A_ = matrix_as_sparse(_A_, "ngR", '\0', '\0', '\0', 0), _PID_); \
else \
REPROTECT(_A_ = matrix_as_sparse(_A_, "ngC", '\0', '\0', '\0', 0), _PID_); \
if (_ISV_) { \
/* Discard names and don't transpose again */ \
SET_VECTOR_ELT(DIMNAMES(_A_, 0), \
(_TRANS_ != 'N') ? 1 : 0, R_NilValue); \
_TRANS_ = 'N'; \
} \
} \
} while (0)
SEXP matrix_as_sparse(SEXP from, const char *zzz, char ul, char ct, char nu, int mg)
Definition coerce.c:1295

◆ DO_S3 [3/3]

#define DO_S3 ( _A_,
_TRANS_,
_PID_,
_ISV_ )
Value:
do { \
if (TYPEOF(_A_) != OBJSXP) { \
if (boolean == NA_LOGICAL || !boolean) \
REPROTECT(_A_ = matrix_as_dense(_A_, ",ge", '\0', '\0', '\0', (_TRANS_ != 'N') ? 0 : 1, 2), _PID_); \
else \
REPROTECT(_A_ = matrix_as_dense(_A_, "nge", '\0', '\0', '\0', (_TRANS_ != 'N') ? 0 : 1, 2), _PID_); \
if (_ISV_) { \
/* Vector: discard names and don't transpose again */ \
SET_VECTOR_ELT(DIMNAMES(_A_, 0), \
(_TRANS_ != 'N') ? 1 : 0, R_NilValue); \
_TRANS_ = 'N'; \
} \
} \
} while (0)

◆ DO_TR

#define DO_TR
Value:
do { \
char xul = UPLO(s_x), xnu = DIAG(s_x), \
yul = UPLO(s_y), ynu = DIAG(s_y); \
if (xtrans != 'N') \
xul = (xul == 'U') ? 'L' : 'U'; \
if (ytrans != 'N') \
yul = (yul == 'U') ? 'L' : 'U'; \
triangular = (xul != yul) ? 0 : ((xnu != ynu || xnu == 'N') ? 1 : 2); \
if (xul != 'U') \
triangular = -triangular; \
} while (0)
#define DIAG(x)
Definition Mdefines.h:111
#define UPLO(x)
Definition Mdefines.h:101

Referenced by R_dense_matmult(), and R_sparse_matmult().

◆ dSCALE

#define dSCALE ( x,
y )
Value:
(x) = (x) * (y)

Definition at line 1158 of file matmult.c.

◆ lSCALE

#define lSCALE ( x,
y )
Value:
(x) = (x) && (y)

Definition at line 1160 of file matmult.c.

◆ SCALE [1/3]

#define SCALE ( c,
index )

◆ SCALE [2/3]

#define SCALE ( c,
index )
Value:
do { \
c##TYPE *px = c##PTR(x), *pd = c##PTR(d); \
for (j = 0, k = 0; j < n; ++j) { \
kend = pp[j]; \
while (k < kend) { \
c##SCALE(*px, *pd); \
++px; \
++k; \
} \
++pd; \
} \
} while (0)
cholmod_common c
Definition cholmod-etc.c:5
#define SCALE(c, index)

◆ SCALE [3/3]

#define SCALE ( c,
index )
Value:
do { \
c##TYPE *px = c##PTR(x), *pd = c##PTR(d); \
for (k = 0; k < kend; ++k) { \
c##SCALE(*px, pd[*pi]); \
++px; \
++pi; \
} \
} while (0)

◆ SCALE3

#define SCALE3 ( t,
index )
Value:
do { \
switch (t) { \
case CPLXSXP: SCALE(z, index); break; \
case REALSXP: SCALE(d, index); break; \
case LGLSXP: SCALE(l, index); break; \
default: break; \
} \
} while (0)

Definition at line 1163 of file matmult.c.

Referenced by Csparse_colscale(), Csparse_rowscale(), dense_colscale(), dense_rowscale(), and Tsparse_rowscale().

◆ zSCALE

#define zSCALE ( x,
y )
Value:
do { \
Rcomplex tmp = (x); \
(x).r = tmp.r * (y).r - tmp.i * (y).i; \
(x).i = tmp.r * (y).i + tmp.i * (y).r; \
} while (0)

Definition at line 1152 of file matmult.c.

Function Documentation

◆ Csparse_colscale()

static void Csparse_colscale ( SEXP obj,
SEXP d )
static

Definition at line 1238 of file matmult.c.

References GET_SLOT, Matrix_pSym, Matrix_xSym, SCALE3, and TYPEOF.

Referenced by R_diagonal_matmult().

◆ Csparse_rowscale()

static void Csparse_rowscale ( SEXP obj,
SEXP d,
SEXP iSym )
static

Definition at line 1269 of file matmult.c.

References GET_SLOT, Matrix_pSym, Matrix_xSym, SCALE3, and TYPEOF.

Referenced by R_diagonal_matmult().

◆ dense_colscale()

static void dense_colscale ( SEXP obj,
SEXP d,
int m,
int n,
char ul,
char nu )
static

Definition at line 1174 of file matmult.c.

References GET_SLOT, Matrix_xSym, SCALE3, and TYPEOF.

Referenced by R_diagonal_matmult().

◆ dense_rowscale()

static void dense_rowscale ( SEXP obj,
SEXP d,
int m,
int n,
char ul,
char nu )
static

Definition at line 1224 of file matmult.c.

References GET_SLOT, Matrix_xSym, SCALE3, and TYPEOF.

Referenced by R_diagonal_matmult().

◆ dense_transpose()

SEXP dense_transpose ( SEXP from,
const char * class,
char op_ct )

◆ gCgCMatrix_matmult()

static SEXP gCgCMatrix_matmult ( SEXP x,
SEXP y,
char xtrans,
char ytrans,
char ztrans,
int triangular,
int boolean )
static

Definition at line 848 of file matmult.c.

References _, ASMODE, c, CHS2M(), DIMNAMES, M2CHS(), matmultDN(), SET_DIAG, SET_TRANS, SET_UPLO, sparse_transpose(), and symDN().

Referenced by R_sparse_matmult().

◆ gCgeMatrix_matmult()

static SEXP gCgeMatrix_matmult ( SEXP x,
SEXP y,
int xtrans,
char ytrans,
char ztrans,
int triangular,
int symmetric )
static

◆ geMatrix_matmult()

static SEXP geMatrix_matmult ( SEXP a,
SEXP b,
char atrans,
char btrans )
static

◆ matmultDim()

static void matmultDim ( SEXP x,
SEXP y,
char * xtrans,
char * ytrans,
char * ztrans,
int * m,
int * n,
int * v )
static

Definition at line 20 of file matmult.c.

References _, GET_SLOT, Matrix_DimSym, SWAP, and TYPEOF.

Referenced by R_dense_matmult(), R_diagonal_matmult(), and R_sparse_matmult().

◆ matmultDN()

static void matmultDN ( SEXP dest,
SEXP asrc,
int ai,
SEXP bsrc,
int bi )
static

◆ R_dense_matmult()

SEXP R_dense_matmult ( SEXP s_x,
SEXP s_y,
SEXP s_xtrans,
SEXP s_ytrans )

◆ R_diagonal_matmult()

◆ R_sparse_matmult()

SEXP R_sparse_matmult ( SEXP s_x,
SEXP s_y,
SEXP s_xtrans,
SEXP s_ytrans,
SEXP s_ztrans,
SEXP s_boolean )

◆ sparse_diag_U2N()

SEXP sparse_diag_U2N ( SEXP from,
const char * class )

Definition at line 621 of file diag.c.

References DIAG, and R_sparse_diag_set().

Referenced by R_sparse_diag_U2N(), and R_sparse_matmult().

◆ sparse_dropzero()

SEXP sparse_dropzero ( SEXP from,
const char * class,
double tol )

◆ sparse_transpose()

SEXP sparse_transpose ( SEXP from,
const char * class,
char op_ct,
int lazy )

Definition at line 52 of file t.c.

Referenced by gCgCMatrix_matmult(), and R_sparse_transpose().

◆ spMatrix_matmult()

static SEXP spMatrix_matmult ( SEXP a,
SEXP b,
char atrans,
char btrans,
char aside )
static

◆ syMatrix_matmult()

static SEXP syMatrix_matmult ( SEXP a,
SEXP b,
char atrans,
char btrans,
char aside )
static

◆ tpMatrix_matmult()

static SEXP tpMatrix_matmult ( SEXP a,
SEXP b,
char atrans,
char btrans,
char aside,
int triangular )
static

◆ trMatrix_matmult()

static SEXP trMatrix_matmult ( SEXP a,
SEXP b,
char atrans,
char btrans,
char aside,
int triangular )
static

◆ Tsparse_rowscale()

static void Tsparse_rowscale ( SEXP obj,
SEXP d,
SEXP iSym )
static

Definition at line 1294 of file matmult.c.

References GET_SLOT, Matrix_xSym, SCALE3, and TYPEOF.

Referenced by R_diagonal_matmult().

Variable Documentation

◆ valid_matmult

const char* valid_matmult[]
static
Initial value:
= {
#define VALID_DENSE
Definition Mdefines.h:230
#define VALID_SPARSE
Definition Mdefines.h:257
#define VALID_DIAGONAL
Definition Mdefines.h:260

Definition at line 15 of file matmult.c.

Referenced by R_dense_matmult(), R_diagonal_matmult(), and R_sparse_matmult().