// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2020 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 "blkdiag.h" template IGL_INLINE void igl::blkdiag( const std::vector> & L, Eigen::SparseMatrix & Y) { int nr = 0; int nc = 0; for(const auto & A : L) { nr += A.rows(); nc += A.cols(); } Y.resize(nr,nc); { int i = 0; int j = 0; for(const auto & A : L) { for(int k = 0;k::InnerIterator it(A,k);it;++it) { Y.insert(i+it.row(),j+k) = it.value(); } } i += A.rows(); j += A.cols(); } } } template IGL_INLINE void igl::blkdiag( const std::vector & L, Eigen::PlainObjectBase & Y) { int nr = 0; int nc = 0; for(const auto & A : L) { nr += A.rows(); nc += A.cols(); } Y.setZero(nr,nc); { int i = 0; int j = 0; for(const auto & A : L) { Y.block(i,j,A.rows(),A.cols()) = A; i += A.rows(); j += A.cols(); } } } #ifdef IGL_STATIC_LIBRARY // explicit template instantiations template void igl::blkdiag >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); template void igl::blkdiag(std::vector, std::allocator > > const&, Eigen::SparseMatrix&); #endif