|
32 | 32 |
|
33 | 33 | #include <Eigen/CholmodSupport> |
34 | 34 |
|
35 | | -namespace Rcpp { |
36 | | - |
37 | | - namespace RcppEigen { |
38 | | - |
39 | | - template<typename T> |
40 | | - SEXP Eigen_cholmod_wrap(const Eigen::CholmodDecomposition<Eigen::SparseMatrix<T>> &obj) { |
41 | | - const cholmod_factor *f = obj.factor(); |
42 | | - if (f->minor < f->n) |
43 | | - throw std::runtime_error("CHOLMOD factorization was unsuccessful"); |
44 | | - S4 ans(std::string((f->is_super) ? "dCHMsuper" : "dCHMsimpl")); |
45 | | - IntegerVector dd(2); |
46 | | - IntegerVector tt((f->is_super) ? 6 : 4); |
47 | | - dd[0] = dd[1] = f->n; |
48 | | - tt[0] = f->ordering; |
49 | | - tt[1] = f->is_ll; |
50 | | - tt[2] = f->is_super; |
51 | | - tt[3] = f->is_monotonic; |
52 | | - ans.slot("Dim") = dd; |
53 | | - ans.slot("type") = tt; |
54 | | - ans.slot("colcount") = ::Rcpp::wrap((int *) f->ColCount, (int *) f->ColCount + f->n); |
55 | | - ans.slot("perm") = ::Rcpp::wrap((int *) f->Perm, (int *) f->Perm + f->n); |
56 | | - if (f->is_super) { |
57 | | - tt[4] = f->maxcsize; |
58 | | - tt[5] = f->maxesize; |
59 | | - ans.slot("super") = ::Rcpp::wrap((int *) f->super, (int *) f->super + f->nsuper + 1); |
60 | | - ans.slot("pi") = ::Rcpp::wrap((int *) f->pi, (int *) f->pi + f->nsuper + 1); |
61 | | - ans.slot("px") = ::Rcpp::wrap((int *) f->px, (int *) f->px + f->nsuper + 1); |
62 | | - ans.slot("s") = ::Rcpp::wrap((int *) f->s, (int *) f->s + f->ssize); |
63 | | - ans.slot("x") = ::Rcpp::wrap((T *) f->x, (T *) f->x + f->xsize); |
64 | | - } else { |
65 | | - ans.slot("nxt") = ::Rcpp::wrap((int *) f->next, (int *) f->next + f->n + 2); |
66 | | - ans.slot("prv") = ::Rcpp::wrap((int *) f->prev, (int *) f->prev + f->n + 2); |
67 | | - ans.slot("nz") = ::Rcpp::wrap((int *) f->nz, (int *) f->nz + f->n); |
68 | | - ans.slot("p") = ::Rcpp::wrap((int *) f->p, (int *) f->p + f->n + 1); |
69 | | - ans.slot("i") = ::Rcpp::wrap((int *) f->i, (int *) f->i + f->nzmax); |
70 | | - ans.slot("x") = ::Rcpp::wrap((T *) f->x, (T *) f->x + f->nzmax); |
71 | | - } |
72 | | - return ::Rcpp::wrap(ans); |
73 | | - } |
74 | | - |
75 | | - } /* namespace RcppEigen */ |
76 | | - |
77 | | - template<typename T> |
78 | | - SEXP wrap(const Eigen::CholmodDecomposition<Eigen::SparseMatrix<T>> &obj) { |
79 | | - return RcppEigen::Eigen_cholmod_wrap(obj); |
80 | | - } |
81 | | - |
82 | | -} /* namespace Rcpp */ |
83 | | - |
84 | 35 | #endif |
0 commit comments