// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "sparse.h" #include #include template IGL_INLINE void igl::sparse( const IndexVector & I, const IndexVector & J, const ValueVector & V, Eigen::SparseMatrix& X) { size_t m = (size_t)I.maxCoeff()+1; size_t n = (size_t)J.maxCoeff()+1; return igl::sparse(I,J,V,m,n,X); } #include "verbose.h" template IGL_INLINE void igl::sparse( const IndexVector & I, const IndexVector & J, const ValueVector & V, const size_t m, const size_t n, Eigen::SparseMatrix& X) { using namespace std; using namespace Eigen; assert((int)I.maxCoeff() < (int)m); assert((int)I.minCoeff() >= 0); assert((int)J.maxCoeff() < (int)n); assert((int)J.minCoeff() >= 0); assert(I.size() == J.size()); assert(J.size() == V.size()); // Really we just need .size() to be the same, but this is safer assert(I.rows() == J.rows()); assert(J.rows() == V.rows()); assert(I.cols() == J.cols()); assert(J.cols() == V.cols()); //// number of values //int nv = V.size(); //Eigen::DynamicSparseMatrix dyn_X(m,n); //// over estimate the number of entries //dyn_X.reserve(I.size()); //for(int i = 0;i < nv;i++) //{ // dyn_X.coeffRef((int)I(i),(int)J(i)) += (T)V(i); //} //X = Eigen::SparseMatrix(dyn_X); vector > IJV; IJV.reserve(I.size()); for(int x = 0;x(I(x),J(x),V(x))); } X.resize(m,n); X.setFromTriplets(IJV.begin(),IJV.end()); } template IGL_INLINE void igl::sparse( const Eigen::PlainObjectBase& D, Eigen::SparseMatrix& X) { assert(false && "Obsolete. Just call D.sparseView() directly"); using namespace std; using namespace Eigen; vector > DIJV; const int m = D.rows(); const int n = D.cols(); for(int i = 0;i(i,j,D(i,j))); } } } X.resize(m,n); X.setFromTriplets(DIJV.begin(),DIJV.end()); } template IGL_INLINE Eigen::SparseMatrix igl::sparse( const Eigen::PlainObjectBase& D) { assert(false && "Obsolete. Just call D.sparseView() directly"); Eigen::SparseMatrix X; igl::sparse(D,X); return X; } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization template void igl::sparse, Eigen::Matrix, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, size_t, size_t, Eigen::SparseMatrix&); template void igl::sparse, double>(Eigen::PlainObjectBase > const&, Eigen::SparseMatrix&); template Eigen::SparseMatrix::Scalar, 0, int> igl::sparse >(Eigen::PlainObjectBase > const&); template Eigen::SparseMatrix::Scalar, 0, int> igl::sparse >(Eigen::PlainObjectBase > const&); template void igl::sparse, Eigen::CwiseNullaryOp, Eigen::Matrix >, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::CwiseNullaryOp, Eigen::Matrix > const&, Eigen::SparseMatrix&); template void igl::sparse, Eigen::Matrix, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::SparseMatrix&); #ifdef _WIN32 template void igl::sparse,Eigen::Matrix,std::complex >(Eigen::Matrix const &,Eigen::Matrix const &,Eigen::Matrix const &,unsigned long long int,unsigned long long int,Eigen::SparseMatrix,0,int> &); #endif #ifndef _WIN32 template void igl::sparse,Eigen::CwiseNullaryOp,Eigen::Matrix >,double>(Eigen::Matrix const&,Eigen::Matrix const&,Eigen::CwiseNullaryOp,Eigen::Matrix > const&,unsigned long,unsigned long,Eigen::SparseMatrix&); template void igl::sparse,Eigen::Matrix,std::complex >(Eigen::Matrix const&,Eigen::Matrix const&,Eigen::Matrix const&,unsigned long,unsigned long,Eigen::SparseMatrix,0,int>&); #endif #endif