sparse_fast.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Daniele Panozzo <daniele.panozzo@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_SPARSE_FAST_H
  9. #define IGL_SPARSE_FAST_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. // Build a sparse matrix from list of indices and values (I,J,V), functions
  17. // like the sparse function in matlab. Divides the construction in two phases, one
  18. // for fixing the sparsity pattern, and one to populate it with values.
  19. //
  20. // Templates:
  21. // IndexVector list of indices, value should be non-negative and should
  22. // expect to be cast to an index. Must implement operator(i) to retrieve
  23. // ith element
  24. // ValueVector list of values, value should be expect to be cast to type
  25. // T. Must implement operator(i) to retrieve ith element
  26. // T should be a eigen sparse matrix primitive type like int or double
  27. // Input:
  28. // I nnz vector of row indices of non zeros entries in X
  29. // J nnz vector of column indices of non zeros entries in X
  30. // V nnz vector of non-zeros entries in X
  31. // Optional:
  32. // m number of rows
  33. // n number of cols
  34. // Outputs:
  35. // X m by n matrix of type T whose entries are to be found
  36. //
  37. IGL_INLINE void sparse_fast_precompute(
  38. const Eigen::VectorXi & I,
  39. const Eigen::VectorXi & J,
  40. Eigen::SparseMatrix<double>& X,
  41. Eigen::VectorXi& data);
  42. IGL_INLINE void sparse_fast_precompute(
  43. const std::vector<Eigen::Triplet<double> >& triplets,
  44. Eigen::SparseMatrix<double>& X,
  45. Eigen::VectorXi& data);
  46. IGL_INLINE void sparse_fast(
  47. const std::vector<Eigen::Triplet<double> >& triplets,
  48. Eigen::SparseMatrix<double>& X,
  49. const Eigen::VectorXi& data);
  50. IGL_INLINE void sparse_fast(
  51. const Eigen::VectorXd & V,
  52. Eigen::SparseMatrix<double>& X,
  53. const Eigen::VectorXi& data);
  54. }
  55. #ifndef IGL_STATIC_LIBRARY
  56. # include "sparse_fast.cpp"
  57. #endif
  58. #endif