// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2017 Daniele Panozzo // // 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 "sparse_fast.h" #include #include #include #include #include // Hashing function // namespace std { // template<> // struct hash > { // size_t operator()(const pair& p) const { // size_t seed = 0; // hash h; // seed ^= h(p.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2); // seed ^= h(p.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); // return seed; // } // }; // } IGL_INLINE void igl::sparse_fast_precompute( const Eigen::VectorXi & I, const Eigen::VectorXi & J, Eigen::SparseMatrix& X, Eigen::VectorXi& data) { // Generates the triplets std::vector > t(I.size()); for (unsigned i = 0; i(I[i],J[i],1); // Call the triplets version sparse_fast_precompute(t,X,data); } IGL_INLINE void igl::sparse_fast_precompute( const std::vector >& triplets, Eigen::SparseMatrix& X, Eigen::VectorXi& data) { // Construct an empty sparse matrix X.setFromTriplets(triplets.begin(),triplets.end()); X.makeCompressed(); // Build hash table for all nnz entries // TODO: this is slow and could be done in nlogn std::map,int> id; for (unsigned k=0; k rc = std::make_pair(row,col); id[rc] = value_index; } } // Compute the indices data.resize(triplets.size()); for (unsigned i=0; i >& triplets, Eigen::SparseMatrix& X, const Eigen::VectorXi& data) { assert(triplets.size() == data.size()); // Clear it first for (unsigned i = 0; i& X, const Eigen::VectorXi& data) { assert(V.size() == data.size()); // Clear it first for (unsigned i = 0; i