// 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(); #if false 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()); #else // This will not work for RowMajor B.resize(m*d,n*d); Eigen::VectorXi per_col = Eigen::VectorXi::Zero(n*d); for (int k=0; k::InnerIterator it(A,k); it; ++it) { for(int r = 0;r::InnerIterator it(A,k); it; ++it) { B.insert(it.row()+mr,k+nr) = it.value(); } } } B.makeCompressed(); #endif } 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 instantiation // 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