// 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 "diag.h" #include "verbose.h" // Bug in unsupported/Eigen/SparseExtra needs iostream first #include #include template IGL_INLINE void igl::diag( const Eigen::SparseMatrix& X, Eigen::SparseVector& V) { assert(false && "Just call X.diagonal().sparseView() directly"); V = X.diagonal().sparseView(); } template IGL_INLINE void igl::diag( const Eigen::SparseMatrix& X, Eigen::MatrixBase & V) { assert(false && "Just call X.diagonal() directly"); V = X.diagonal(); } template IGL_INLINE void igl::diag( const Eigen::SparseVector& V, Eigen::SparseMatrix& X) { // clear and resize output std::vector > Xijv; const int n = V.size(); const int nnz = V.nonZeros(); Xijv.reserve(nnz); // loop over non-zeros for(typename Eigen::SparseVector::InnerIterator it(V); it; ++it) { Xijv.emplace_back(it.index(),it.index(),it.value()); } X.resize(n,n); X.setFromTriplets(Xijv.begin(),Xijv.end()); } template IGL_INLINE void igl::diag( const Eigen::MatrixBase & V, Eigen::SparseMatrix& X) { assert(V.rows() == 1 || V.cols() == 1); // clear and resize output std::vector > Xijv; const int n = V.size(); Xijv.reserve(n); // loop over non-zeros for(int i = 0;i >(Eigen::SparseMatrix const&, Eigen::MatrixBase >&); template void igl::diag(Eigen::SparseMatrix const&, Eigen::SparseVector&); template void igl::diag >(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); template void igl::diag(Eigen::SparseVector const&, Eigen::SparseMatrix&); #endif