sparse.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_H
  9. #define IGL_SPARSE_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
  18. ///
  19. /// @tparam IndexVector list of indices, value should be non-negative and should
  20. /// expect to be cast to an index. Must implement operator(i) to retrieve
  21. /// ith element
  22. /// @tparam ValueVector list of values, value should be expect to be cast to type
  23. /// T. Must implement operator(i) to retrieve ith element
  24. /// @tparam T should be a eigen sparse matrix primitive type like int or double
  25. /// @param[in] I nnz vector of row indices of non zeros entries in X
  26. /// @param[in] J nnz vector of column indices of non zeros entries in X
  27. /// @param[in] V nnz vector of non-zeros entries in X
  28. /// @param[in] m number of rows
  29. /// @param[in] n number of cols
  30. /// @param[out] X m by n matrix of type T whose entries are to be found
  31. ///
  32. /// \deprecated just use Eigen::SparseMatrix<>.setFromTriplets()
  33. template <
  34. class IndexVectorI,
  35. class IndexVectorJ,
  36. class ValueVector,
  37. typename T>
  38. IGL_INLINE void sparse(
  39. const IndexVectorI & I,
  40. const IndexVectorJ & J,
  41. const ValueVector & V,
  42. const size_t m,
  43. const size_t n,
  44. Eigen::SparseMatrix<T>& X);
  45. /// \overload
  46. template <class IndexVector, class ValueVector, typename T>
  47. IGL_INLINE void sparse(
  48. const IndexVector & I,
  49. const IndexVector & J,
  50. const ValueVector & V,
  51. Eigen::SparseMatrix<T>& X);
  52. /// Convert a full, dense matrix to a sparse one
  53. ///
  54. /// \note Just use .sparseView()
  55. ///
  56. /// @tparam T should be a eigen sparse matrix primitive type like int or double
  57. /// @param[in] D m by n full, dense matrix
  58. /// @param[out] X m by n sparse matrix
  59. template <typename DerivedD, typename T>
  60. IGL_INLINE void sparse(
  61. const Eigen::PlainObjectBase<DerivedD>& D,
  62. Eigen::SparseMatrix<T>& X);
  63. /// \overload
  64. template <typename DerivedD>
  65. IGL_INLINE Eigen::SparseMatrix<typename DerivedD::Scalar > sparse(
  66. const Eigen::PlainObjectBase<DerivedD>& D);
  67. }
  68. #ifndef IGL_STATIC_LIBRARY
  69. # include "sparse.cpp"
  70. #endif
  71. #endif