9 values = values && (
class[0] ==
'd' ||
class[0] ==
'z');
10 char trans = (
class[2] ==
'C') ?
'N' :
'C';
17 A->
m = INTEGER(dim)[(trans ==
'N') ? 0 : 1];
18 A->
n = INTEGER(dim)[(trans ==
'N') ? 1 : 1];
45 char class[] =
"..CMatrix";
51 p = PROTECT(Rf_allocVector(INTSXP, (R_xlen_t) A->
n + 1)),
52 i = PROTECT(Rf_allocVector(INTSXP, nnz));
53 INTEGER(dim)[0] = A->
m;
54 INTEGER(dim)[1] = A->
n;
55 memcpy(INTEGER(p), A->
p,
sizeof(
int) * ((
size_t) A->
n + 1));
56 memcpy(INTEGER(i), A->
i,
sizeof(
int) * (
size_t) nnz);
62 PROTECT(x = Rf_allocVector(REALSXP, nnz));
63 memcpy(REAL(x), A->
x,
sizeof(
double) * (
size_t) nnz);
65 PROTECT(x = Rf_allocVector(CPLXSXP, nnz));
66 memcpy(COMPLEX(x), A->
x,
sizeof(Rcomplex) * (
size_t) nnz);
81 return (
Matrix_csd *) cs_ci_dfree((cs_cid *) D);
83 return (
Matrix_csd *) cs_di_dfree((cs_did *) D);
93 return (
Matrix_csd *) cs_ci_dmperm((cs_ci *) A, seed);
95 return (
Matrix_csd *) cs_di_dmperm((cs_di *) A, seed);
97 return (
Matrix_csd *) cs_dmperm((cs *) A, seed);
105 return cs_ci_dropzeros((cs_ci *) A);
107 return cs_di_dropzeros((cs_di *) A);
109 return cs_dropzeros((cs *) A);
117 return cs_ci_free(p);
119 return cs_di_free(p);
129 return cs_ci_happly((cs_ci *) V, i, beta, (
double _Complex *) x);
131 return cs_di_happly((cs_di *) V, i, beta, (
double *) x);
133 return cs_happly((cs *) V, i, beta, (
double *) x);
141 return cs_ci_ipvec(p, (
double _Complex *) b, (
double _Complex *) x, n);
143 return cs_di_ipvec(p, (
double *) b, (
double *) x, n);
145 return cs_ipvec(p, (
double *) b, (
double *) x, n);
153 return cs_ci_lsolve((cs_ci *) L, (
double _Complex *) x);
155 return cs_di_lsolve((cs_di *) L, (
double *) x);
157 return cs_lsolve((cs *) L, (
double *) x);
165 return (
Matrix_csn *) cs_ci_lu((cs_ci *) A, (cs_cis *) S, tol);
167 return (
Matrix_csn *) cs_di_lu((cs_di *) A, (cs_dis *) S, tol);
169 return (
Matrix_csn *) cs_lu((cs *) A, (css *) S, tol);
177 return cs_ci_lusol(order, (cs_ci *) A, (
double _Complex *) b, tol);
179 return cs_di_lusol(order, (cs_di *) A, (
double *) b, tol);
181 return cs_lusol(order, (cs *) A, (
double *) b, tol);
189 return (
Matrix_csn *) cs_ci_nfree((cs_cin *) N);
191 return (
Matrix_csn *) cs_di_nfree((cs_din *) N);
202 cs_ci *tmp = cs_ci_permute((cs_ci *) A, pinv, q, values);
204 memcpy(B, tmp,
sizeof(cs_ci));
205 tmp = cs_ci_free(tmp);
207 cs_di *tmp = cs_di_permute((cs_di *) A, pinv, q, values);
209 memcpy(B, tmp,
sizeof(cs_di));
210 tmp = cs_di_free(tmp);
213 cs *tmp = cs_permute((cs *) A, pinv, q, values);
215 memcpy(B, tmp,
sizeof(cs ));
226 return cs_ci_pinv(p, n);
228 return cs_di_pinv(p, n);
230 return cs_pinv(p, n);
238 return cs_ci_pvec(p, (
double _Complex *) b, (
double _Complex *) x, n);
240 return cs_di_pvec(p, (
double *) b, (
double *) x, n);
242 return cs_pvec(p, (
double *) b, (
double *) x, n);
250 return (
Matrix_csn *) cs_ci_qr((cs_ci *) A, (cs_cis *) S);
252 return (
Matrix_csn *) cs_di_qr((cs_di *) A, (cs_dis *) S);
254 return (
Matrix_csn *) cs_qr((cs *) A, (css *) S);
262 return cs_ci_qrsol(order, (cs_ci *) A, (
double _Complex *) b);
264 return cs_di_qrsol(order, (cs_di *) A, (
double *) b);
266 return cs_qrsol(order, (cs *) A, (
double *) b);
274 return (
Matrix_css *) cs_ci_sfree((cs_cis *) S);
276 return (
Matrix_css *) cs_di_sfree((cs_dis *) S);
287 cs_ci *tmp = cs_ci_spalloc(m, n, nzmax, values, triplet);
289 memcpy(B, tmp,
sizeof(cs_ci));
290 tmp = cs_ci_free(tmp);
292 cs_di *tmp = cs_di_spalloc(m, n, nzmax, values, triplet);
294 memcpy(B, tmp,
sizeof(cs_di));
295 tmp = cs_di_free(tmp);
298 cs *tmp = cs_spalloc(m, n, nzmax, values, triplet);
300 memcpy(B, tmp,
sizeof(cs ));
309 int k, d = (m < n) ? m : n;
313 int *B__p = B->
p, *B__i = B->
i;
314 for (k = 0; k < d; ++k)
315 B__p[k] = B__i[k] = k;
317 for (k = d; k <= n; ++k)
322 double _Complex *B__x = (
double _Complex *) B->
x;
323 for (k = 0; k < d; ++k)
327 double *B__x = (
double *) B->
x;
328 for (k = 0; k < d; ++k)
341 return (
Matrix_cs *) cs_ci_spfree((cs_ci *) A);
343 return (
Matrix_cs *) cs_di_spfree((cs_di *) A);
345 return (
Matrix_cs *) cs_spfree((cs *) A);
353 return cs_ci_sprealloc((cs_ci *) A, nzmax);
355 return cs_di_sprealloc((cs_di *) A, nzmax);
357 return cs_sprealloc((cs *) A, nzmax);
365 return cs_ci_spsolve((cs_ci *) L, (cs_ci *) B, k, xi, (
double _Complex *) x, pinv, lo);
367 return cs_di_spsolve((cs_di *) L, (cs_di *) B, k, xi, (
double *) x, pinv, lo);
369 return cs_spsolve((cs *) L, (cs *) B, k, xi, (
double *) x, pinv, lo);
377 return (
Matrix_css *) cs_ci_sqr(order, (cs_ci *) A, qr);
379 return (
Matrix_css *) cs_di_sqr(order, (cs_di *) A, qr);
381 return (
Matrix_css *) cs_sqr(order, (cs *) A, qr);
390 cs_ci *tmp = cs_ci_transpose((cs_ci *) A, values);
392 memcpy(B, tmp,
sizeof(cs_ci));
393 tmp = cs_ci_free(tmp);
395 cs_di *tmp = cs_di_transpose((cs_di *) A, values);
397 memcpy(B, tmp,
sizeof(cs_di));
398 tmp = cs_di_free(tmp);
401 cs *tmp = cs_transpose((cs *) A, values);
403 memcpy(B, tmp,
sizeof(cs ));
414 return cs_ci_usolve((cs_ci *) U, (
double _Complex *) x);
416 return cs_di_usolve((cs_di *) U, (
double *) x);
418 return cs_usolve((cs *) U, (
double *) x);
const char * Matrix_class(SEXP, const char **, int, const char *)
#define GET_SLOT(x, name)
SEXP newObject(const char *)
const char * valid_sparse_compressed[]
#define SET_SLOT(x, name, value)
int Matrix_cs_lsolve(const Matrix_cs *L, void *x)
Matrix_cs * Matrix_cs_transpose(const Matrix_cs *A, int values)
Matrix_cs * Matrix_cs_spfree(Matrix_cs *A)
Matrix_csn * Matrix_cs_lu(const Matrix_cs *A, const Matrix_css *S, double tol)
int Matrix_cs_usolve(const Matrix_cs *U, void *x)
int Matrix_cs_qrsol(int order, const Matrix_cs *A, void *b)
void * Matrix_cs_free(void *p)
int Matrix_cs_ipvec(const int *p, const void *b, void *x, int n)
Matrix_cs * Matrix_cs_permute(const Matrix_cs *A, const int *pinv, const int *q, int values)
Matrix_csn * Matrix_cs_qr(const Matrix_cs *A, const Matrix_css *S)
Matrix_csd * Matrix_cs_dmperm(const Matrix_cs *A, int seed)
SEXP CXS2M(Matrix_cs *A, int values, char shape)
int Matrix_cs_lusol(int order, const Matrix_cs *A, void *b, double tol)
Matrix_csd * Matrix_cs_dfree(Matrix_csd *D)
int Matrix_cs_happly(const Matrix_cs *V, int i, double beta, void *x)
Matrix_css * Matrix_cs_sfree(Matrix_css *S)
Matrix_cs * Matrix_cs_speye(int m, int n, int values, int triplet)
int * Matrix_cs_pinv(const int *p, int n)
int Matrix_cs_sprealloc(Matrix_cs *A, int nzmax)
Matrix_cs * Matrix_cs_spalloc(int m, int n, int nzmax, int values, int triplet)
int Matrix_cs_dropzeros(Matrix_cs *A)
int Matrix_cs_spsolve(Matrix_cs *L, const Matrix_cs *B, int k, int *xi, void *x, const int *pinv, int lo)
Matrix_css * Matrix_cs_sqr(int order, const Matrix_cs *A, int qr)
Matrix_cs * M2CXS(SEXP obj, int values)
Matrix_csn * Matrix_cs_nfree(Matrix_csn *N)
int Matrix_cs_pvec(const int *p, const void *b, void *x, int n)
#define CXSPARSE_XTYPE_GET()