[Rcpp-commits] r3170 - pkg/RcppEigen/inst/include/unsupported/Eigen/src/SparseExtra

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 11 12:08:58 CEST 2011


Author: dmbates
Date: 2011-08-11 12:08:57 +0200 (Thu, 11 Aug 2011)
New Revision: 3170

Modified:
   pkg/RcppEigen/inst/include/unsupported/Eigen/src/SparseExtra/CholmodSupport.h
Log:
Add a solveInPlace method to try to avoid memory problems.


Modified: pkg/RcppEigen/inst/include/unsupported/Eigen/src/SparseExtra/CholmodSupport.h
===================================================================
--- pkg/RcppEigen/inst/include/unsupported/Eigen/src/SparseExtra/CholmodSupport.h	2011-08-10 06:26:35 UTC (rev 3169)
+++ pkg/RcppEigen/inst/include/unsupported/Eigen/src/SparseExtra/CholmodSupport.h	2011-08-11 10:08:57 UTC (rev 3170)
@@ -235,6 +235,24 @@
 	    }
 	}
 	
+    template<typename OtherDerived>
+    void solveInPlace(const MatrixBase<OtherDerived>& other, int type) const {
+	eigen_assert(m_factorizationIsOk && 
+		     "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
+	const Index size = m_cholmodFactor->n;
+	eigen_assert(size==other.rows());
+	    
+	// note: cd stands for Cholmod Dense
+	cholmod_dense b_cd = viewAsCholmod(other.const_cast_derived());
+	cholmod_dense* x_cd = M_cholmod_solve(type, m_cholmodFactor, &b_cd, &m_cholmod);
+	if(!x_cd) {
+	    this->m_info = NumericalIssue;
+	}
+	Scalar* xpt=reinterpret_cast<Scalar*>(x_cd->x);
+	std::copy(xpt, xpt + other.rows() * other.cols(), other.derived().data());
+	M_cholmod_free_dense(&x_cd, &m_cholmod);
+    }
+
 	void setSolveType(int type) {m_solveType = type;}
 
 	/** \brief Reports whether previous computation was successful.



More information about the Rcpp-commits mailing list