Skip to content

Commit 652cb99

Browse files
authored
Merge pull request #131 from jaganmn/rcppeigen_cholmod
Header clean-up to fix lme4/lme4#745
2 parents 56dc0cc + 451678f commit 652cb99

File tree

9 files changed

+70
-1720
lines changed

9 files changed

+70
-1720
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ License: GPL (>= 2) | file LICENSE
2424
LazyLoad: yes
2525
Depends: R (>= 3.6.0)
2626
LinkingTo: Rcpp
27-
Imports: Matrix (>= 1.1-0), Rcpp (>= 0.11.0), stats, utils
28-
Suggests: inline, tinytest, pkgKitten, microbenchmark
27+
Imports: Rcpp (>= 0.11.0), stats, utils
28+
Suggests: Matrix, inline, microbenchmark, pkgKitten, tinytest
2929
URL: https://github.com/RcppCore/RcppEigen, https://dirk.eddelbuettel.com/code/rcpp.eigen.html
3030
BugReports: https://github.com/RcppCore/RcppEigen/issues

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
useDynLib("RcppEigen", .registration=TRUE)
22

3-
importClassesFrom("Matrix", "dgCMatrix", "dgeMatrix", "dsCMatrix", "dtCMatrix")
43
importFrom("Rcpp", "evalCpp")
54
importFrom("utils", "packageDescription", "package.skeleton")
65
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt")

inst/include/Eigen/CholmodSupport

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
#include "src/Core/util/DisableStupidWarnings.h"
1414

15-
extern "C" {
16-
#include <RcppEigenCholmod.h>
17-
}
18-
1915
/** \ingroup Support_modules
2016
* \defgroup CholmodSupport_Module CholmodSupport module
2117
*

inst/include/Eigen/src/CholmodSupport/CholmodSupport.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#ifndef EIGEN_CHOLMODSUPPORT_H
1111
#define EIGEN_CHOLMODSUPPORT_H
1212

13+
#ifndef R_MATRIX_CHOLMOD
14+
# define R_MATRIX_CHOLMOD(_NAME_) cholmod_ ## _NAME_
15+
#endif
16+
1317
namespace Eigen {
1418

1519
namespace internal {
@@ -195,23 +199,23 @@ class CholmodBase : public SparseSolverBase<Derived>
195199
{
196200
EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
197201
m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
198-
cholmod_start(&m_cholmod);
202+
R_MATRIX_CHOLMOD(start)(&m_cholmod);
199203
}
200204

201205
explicit CholmodBase(const MatrixType& matrix)
202206
: m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false)
203207
{
204208
EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
205209
m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
206-
cholmod_start(&m_cholmod);
210+
R_MATRIX_CHOLMOD(start)(&m_cholmod);
207211
compute(matrix);
208212
}
209213

210214
~CholmodBase()
211215
{
212216
if(m_cholmodFactor)
213-
cholmod_free_factor(&m_cholmodFactor, &m_cholmod);
214-
cholmod_finish(&m_cholmod);
217+
R_MATRIX_CHOLMOD(free_factor)(&m_cholmodFactor, &m_cholmod);
218+
R_MATRIX_CHOLMOD(finish)(&m_cholmod);
215219
}
216220

217221
inline StorageIndex cols() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); }
@@ -246,11 +250,11 @@ class CholmodBase : public SparseSolverBase<Derived>
246250
{
247251
if(m_cholmodFactor)
248252
{
249-
cholmod_free_factor(&m_cholmodFactor, &m_cholmod);
253+
R_MATRIX_CHOLMOD(free_factor)(&m_cholmodFactor, &m_cholmod);
250254
m_cholmodFactor = 0;
251255
}
252256
cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
253-
m_cholmodFactor = cholmod_analyze(&A, &m_cholmod);
257+
m_cholmodFactor = R_MATRIX_CHOLMOD(analyze)(&A, &m_cholmod);
254258

255259
this->m_isInitialized = true;
256260
this->m_info = Success;
@@ -268,7 +272,7 @@ class CholmodBase : public SparseSolverBase<Derived>
268272
{
269273
eigen_assert(m_analysisIsOk && "You must first call analyzePattern()");
270274
cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
271-
cholmod_factorize_p(&A, m_shiftOffset, 0, 0, m_cholmodFactor, &m_cholmod);
275+
R_MATRIX_CHOLMOD(factorize_p)(&A, m_shiftOffset, 0, 0, m_cholmodFactor, &m_cholmod);
272276

273277
// If the factorization failed, minor is the column at which it did. On success minor == n.
274278
this->m_info = (m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue);
@@ -293,15 +297,15 @@ class CholmodBase : public SparseSolverBase<Derived>
293297
Ref<const Matrix<typename Rhs::Scalar,Dynamic,Dynamic,ColMajor> > b_ref(b.derived());
294298

295299
cholmod_dense b_cd = viewAsCholmod(b_ref);
296-
cholmod_dense* x_cd = cholmod_solve(CHOLMOD_A, m_cholmodFactor, &b_cd, &m_cholmod);
300+
cholmod_dense* x_cd = R_MATRIX_CHOLMOD(solve)(CHOLMOD_A, m_cholmodFactor, &b_cd, &m_cholmod);
297301
if(!x_cd)
298302
{
299303
this->m_info = NumericalIssue;
300304
return;
301305
}
302306
// TODO optimize this copy by swapping when possible (be careful with alignment, etc.)
303307
dest = Matrix<Scalar,Dest::RowsAtCompileTime,Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),b.rows(),b.cols());
304-
cholmod_free_dense(&x_cd, &m_cholmod);
308+
R_MATRIX_CHOLMOD(free_dense)(&x_cd, &m_cholmod);
305309
}
306310

307311
/** \internal */
@@ -316,15 +320,15 @@ class CholmodBase : public SparseSolverBase<Derived>
316320
// note: cs stands for Cholmod Sparse
317321
Ref<SparseMatrix<typename RhsDerived::Scalar,ColMajor,typename RhsDerived::StorageIndex> > b_ref(b.const_cast_derived());
318322
cholmod_sparse b_cs = viewAsCholmod(b_ref);
319-
cholmod_sparse* x_cs = cholmod_spsolve(CHOLMOD_A, m_cholmodFactor, &b_cs, &m_cholmod);
323+
cholmod_sparse* x_cs = R_MATRIX_CHOLMOD(spsolve)(CHOLMOD_A, m_cholmodFactor, &b_cs, &m_cholmod);
320324
if(!x_cs)
321325
{
322326
this->m_info = NumericalIssue;
323327
return;
324328
}
325329
// TODO optimize this copy by swapping when possible (be careful with alignment, etc.)
326330
dest.derived() = viewAsEigen<typename DestDerived::Scalar,ColMajor,typename DestDerived::StorageIndex>(*x_cs);
327-
cholmod_free_sparse(&x_cs, &m_cholmod);
331+
R_MATRIX_CHOLMOD(free_sparse)(&x_cs, &m_cholmod);
328332
}
329333
#endif // EIGEN_PARSED_BY_DOXYGEN
330334

0 commit comments

Comments
 (0)