// 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 "repmat.h" template IGL_INLINE void igl::repmat( const Eigen::MatrixBase & A, const int r, const int c, Eigen::PlainObjectBase & B) { assert(r>0); assert(c>0); // Make room for output B.resize(r*A.rows(),c*A.cols()); // copy tiled blocks for(int i = 0;i IGL_INLINE void igl::repmat( const Eigen::SparseMatrix & A, const int r, const int c, Eigen::SparseMatrix & B) { assert(r>0); assert(c>0); B.resize(r*A.rows(), c*A.cols()); std::vector> b; b.reserve(r*c*A.nonZeros()); for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { // loop outer level for (int k = 0; k < A.outerSize(); ++k) { // loop inner level for (typename Eigen::SparseMatrix::InnerIterator it(A,k); it; ++it) { Eigen::Triplet triplet(i * A.rows() + it.row(), j * A.cols() + it.col(), it.value()); b.push_back(triplet); } } } } B.setFromTriplets(b.begin(), b.end()); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); // generated by autoexplicit.sh template void igl::repmat, Eigen::Matrix >(Eigen::MatrixBase > const&, int, int, Eigen::PlainObjectBase >&); template void igl::repmat, Eigen::Matrix >(Eigen::MatrixBase > const&, int, int, Eigen::PlainObjectBase >&); template void igl::repmat, Eigen::Matrix >(Eigen::MatrixBase > const&, int, int, Eigen::PlainObjectBase >&); template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); template void igl::repmat(Eigen::SparseMatrix const&, int, int, Eigen::SparseMatrix&); #endif