// 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 "find.h" #include "verbose.h" #include template < typename T, typename DerivedI, typename DerivedJ, typename DerivedV> IGL_INLINE void igl::find( const Eigen::SparseMatrix& X, Eigen::DenseBase & I, Eigen::DenseBase & J, Eigen::DenseBase & V) { // Resize outputs to fit nonzeros I.derived().resize(X.nonZeros(),1); J.derived().resize(X.nonZeros(),1); V.derived().resize(X.nonZeros(),1); int i = 0; // Iterate over outside for(int k=0; k::InnerIterator it (X,k); it; ++it) { V(i) = it.value(); I(i) = it.row(); J(i) = it.col(); i++; } } } template < typename T> IGL_INLINE std::vector > igl::find( const Eigen::SparseMatrix& X) { std::vector> ijv; for(int i = 0; i < X.outerSize(); i++) { for(typename Eigen::SparseMatrix::InnerIterator it(X,i); it; it++) { // Match find above //if(it.value()) { ijv.emplace_back(it.row(),it.col(),it.value()); } } } return ijv; } template < typename DerivedX, typename DerivedI, typename DerivedJ, typename DerivedV> IGL_INLINE void igl::find( const Eigen::DenseBase& X, Eigen::PlainObjectBase & I, Eigen::PlainObjectBase & J, Eigen::PlainObjectBase & V) { const int nnz = X.count(); I.resize(nnz,1); J.resize(nnz,1); V.resize(nnz,1); { int k = 0; for(int j = 0;j IGL_INLINE void igl::find( const Eigen::DenseBase& X, Eigen::PlainObjectBase & I) { const int nnz = X.count(); I.resize(nnz,1); { int k = 0; for(int j = 0;j IGL_INLINE void igl::find( const Eigen::SparseVector& X, Eigen::Matrix & I, Eigen::Matrix & V) { // Resize outputs to fit nonzeros I.resize(X.nonZeros()); V.resize(X.nonZeros()); int i = 0; // loop over non-zeros for(typename Eigen::SparseVector::InnerIterator it(X); it; ++it) { I(i) = it.index(); V(i) = it.value(); i++; } } template IGL_INLINE std::vector igl::find( const Eigen::Array & M) { std::vector I; // This reserve seems to be worth it even if it means running over M twice I.reserve(M.count()); for(int i = 0;i igl::find(Eigen::Array const&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix, Eigen::Array >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&); template void igl::find, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase >&, Eigen::DenseBase >&, Eigen::DenseBase >&); template void igl::find, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&); #endif