// 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 "AtA_cached.h" #include #include #include template IGL_INLINE void igl::AtA_cached_precompute( const Eigen::SparseMatrix& A, igl::AtA_cached_data& data, Eigen::SparseMatrix& AtA) { // 1 Compute At (this could be avoided, but performance-wise it will not make a difference) std::vector > Col_RowPtr; std::vector > Col_IndexPtr; Col_RowPtr.resize(A.cols()); Col_IndexPtr.resize(A.cols()); for (unsigned k=0; k= 0); assert(row < A.rows()); assert(row >= 0); assert(value_index >= 0); assert(value_index < A.nonZeros()); Col_RowPtr[col].push_back(row); Col_IndexPtr[col].push_back(value_index); } } Eigen::SparseMatrix At = A.transpose(); At.makeCompressed(); AtA = At * A; AtA.makeCompressed(); assert(AtA.isCompressed()); // If weights are not provided, use 1 if (data.W.size() == 0) data.W = Eigen::VectorXd::Ones(A.rows()); assert(data.W.size() == A.rows()); data.I_outer.reserve(AtA.outerSize()); data.I_row.reserve(2*AtA.nonZeros()); data.I_col.reserve(2*AtA.nonZeros()); data.I_w.reserve(2*AtA.nonZeros()); // 2 Construct the rules for (unsigned k=0; k= 0); assert(row < AtA.rows()); assert(row >= 0); assert(value_index >= 0); assert(value_index < AtA.nonZeros()); data.I_outer.push_back(data.I_row.size()); // Find correspondences unsigned i=0; unsigned j=0; while (i Col_RowPtr[col][j]) ++j; else ++i; } } } data.I_outer.push_back(data.I_row.size()); // makes it more efficient to iterate later on igl::AtA_cached(A,data,AtA); } template IGL_INLINE void igl::AtA_cached( const Eigen::SparseMatrix& A, const igl::AtA_cached_data& data, Eigen::SparseMatrix& AtA) { for (unsigned i=0; i(Eigen::SparseMatrix const&, igl::AtA_cached_data const&, Eigen::SparseMatrix&); template void igl::AtA_cached_precompute(Eigen::SparseMatrix const&, igl::AtA_cached_data&, Eigen::SparseMatrix&); #endif