// This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // // Copyright (C) 2008 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifndef EIGEN_CHOLMODSUPPORT_H #define EIGEN_CHOLMODSUPPORT_H template cholmod_sparse SparseMatrix::asCholmodMatrix() { cholmod_sparse res; res.nzmax = nonZeros(); res.nrow = rows();; res.ncol = cols(); res.p = _outerIndexPtr(); res.i = _innerIndexPtr(); res.x = _valuePtr(); res.xtype = CHOLMOD_REAL; res.itype = CHOLMOD_INT; res.sorted = 1; res.packed = 1; res.dtype = 0; res.stype = -1; if (ei_is_same_type::ret) { res.xtype = CHOLMOD_REAL; res.dtype = 1; } else if (ei_is_same_type::ret) { res.xtype = CHOLMOD_REAL; res.dtype = 0; } else if (ei_is_same_type >::ret) { res.xtype = CHOLMOD_COMPLEX; res.dtype = 1; } else if (ei_is_same_type >::ret) { res.xtype = CHOLMOD_COMPLEX; res.dtype = 0; } else { ei_assert(false && "Scalar type not supported by CHOLMOD"); } if (Flags & SelfAdjoint) { if (Flags & Upper) res.stype = 1; else if (Flags & Lower) res.stype = -1; else res.stype = 0; } else res.stype = 0; return res; } template SparseMatrix SparseMatrix::Map(cholmod_sparse& cm) { SparseMatrix res; res.m_innerSize = cm.nrow; res.m_outerSize = cm.ncol; res.m_outerIndex = reinterpret_cast(cm.p); SparseArray data = SparseArray::Map( reinterpret_cast(cm.i), reinterpret_cast(cm.x), res.m_outerIndex[cm.ncol]); res.m_data.swap(data); res.markAsRValue(); return res; } template void SparseCholesky::computeUsingCholmod(const MatrixType& a) { cholmod_common c; cholmod_start(&c); cholmod_sparse A = const_cast(a).asCholmodMatrix(); std::vector perm(a.cols()); for (int i=0; i