Matrix r5059
Loading...
Searching...
No Matches
updown.c
Go to the documentation of this file.
1/* C implementation of methods for updown, update */
2
3#include "cholmod-etc.h"
4#include "Mdefines.h"
5#include "M5.h"
6
7SEXP sparseCholesky_updown(SEXP s_trf, SEXP s_obj, SEXP s_update)
8{
9 cholmod_factor *L = M2CHF(s_trf, 1);
10 cholmod_sparse *A = M2CHS(s_obj, 1);
11
12 L = cholmod_copy_factor(L, &c);
13 cholmod_updown(Rf_asLogical(s_update) != 0, A, L, &c);
14
15#define UPDOWN_FINISH \
16 do { \
17 SEXP dimnames = PROTECT(DIMNAMES(s_trf, 0)); \
18 PROTECT(s_trf = CHF2M(L, 1)); \
19 cholmod_free_factor(&L, &c); \
20 if (TYPEOF(s_trf) == CHARSXP) \
21 Rf_error("%s", CHAR(s_trf)); \
22 SET_DIMNAMES(s_trf, 0, dimnames); \
23 UNPROTECT(2); \
24 } while (0)
25
27 return s_trf;
28}
29
30SEXP sparseCholesky_update(SEXP s_trf, SEXP s_obj, SEXP s_beta)
31{
32 Rcomplex beta = Rf_asComplex(s_beta);
33 if (!R_FINITE(beta.r) || !R_FINITE(beta.i))
34 Rf_error(_("'%s' is not a number or not finite"), "beta");
35
36 cholmod_factor *L = M2CHF(s_trf, 1);
37 cholmod_sparse *A = M2CHS(s_obj, 1);
38 double b[2]; b[0] = beta.r; b[1] = beta.i;
39
40 /* defined in ./objects.c : */
41 char Matrix_shape(SEXP);
42 if (Matrix_shape(s_obj) == 's')
43 A->stype = (UPLO(s_obj) == 'U') ? 1 : -1;
44
45 L = cholmod_copy_factor(L, &c);
46
47 c.final_asis = 0;
48 c.final_ll = L->is_ll;
49 c.final_super = L->is_super;
50 c.final_pack = 1;
51 c.final_monotonic = 1;
52
53 cholmod_factorize_p(A, b, NULL, 0, L, &c);
54 cholmod_defaults(&c);
55
57 return s_trf;
58}
#define _(String)
Definition Mdefines.h:66
#define UPLO(x)
Definition Mdefines.h:101
cholmod_factor * M2CHF(SEXP obj, int values)
Definition cholmod-etc.c:39
cholmod_sparse * M2CHS(SEXP obj, int values)
cholmod_common c
Definition cholmod-etc.c:5
char Matrix_shape(SEXP obj, int mode)
Definition objects.c:146
SEXP sparseCholesky_updown(SEXP s_trf, SEXP s_obj, SEXP s_update)
Definition updown.c:7
#define UPDOWN_FINISH
SEXP sparseCholesky_update(SEXP s_trf, SEXP s_obj, SEXP s_beta)
Definition updown.c:30