// 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 "repdiag.h" #include template IGL_INLINE void igl::repdiag( const Eigen::SparseMatrix& A, const int d, Eigen::SparseMatrix& B) { using namespace std; using namespace Eigen; int m = A.rows(); int n = A.cols(); vector > IJV; IJV.reserve(A.nonZeros()*d); // Loop outer level for (int k=0; k::InnerIterator it(A,k); it; ++it) { for(int i = 0;i(i*m+it.row(),i*n+it.col(),it.value())); } } } B.resize(m*d,n*d); B.setFromTriplets(IJV.begin(),IJV.end()); // Q: Why is this **Very** slow? //int m = A.rows(); //int n = A.cols(); //B.resize(m*d,n*d); //// Reserve enough space for new non zeros //B.reserve(d*A.nonZeros()); //// loop over reps //for(int i=0;i::InnerIterator it(A,k); it; ++it) // { // B.insert(i*m+it.row(),i*n+it.col()) = it.value(); // } // } //} //B.makeCompressed(); } template IGL_INLINE void igl::repdiag( const Eigen::Matrix & A, const int d, Eigen::Matrix & B) { int m = A.rows(); int n = A.cols(); B.resize(m*d,n*d); B.array() *= 0; for(int i = 0;i IGL_INLINE Mat igl::repdiag(const Mat & A, const int d) { Mat B; repdiag(A,d,B); return B; } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization // generated by autoexplicit.sh template void igl::repdiag(Eigen::SparseMatrix const&, int, Eigen::SparseMatrix&); // generated by autoexplicit.sh template Eigen::SparseMatrix igl::repdiag >(Eigen::SparseMatrix const&, int); #endif