sparse.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef IGL_SPARSE_H
  2. #define IGL_SPARSE_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Dense>
  6. #include <Eigen/Sparse>
  7. namespace igl
  8. {
  9. // Build a sparse matrix from list of indices and values (I,J,V), functions
  10. // like the sparse function in matlab
  11. //
  12. // Templates:
  13. // IndexVector list of indices, value should be non-negative and should
  14. // expect to be cast to an index. Must implement operator(i) to retrieve
  15. // ith element
  16. // ValueVector list of values, value should be expect to be cast to type
  17. // T. Must implement operator(i) to retrieve ith element
  18. // T should be a eigen sparse matrix primitive type like int or double
  19. // Input:
  20. // I nnz vector of row indices of non zeros entries in X
  21. // J nnz vector of column indices of non zeros entries in X
  22. // V nnz vector of non-zeros entries in X
  23. // Optional:
  24. // m number of rows
  25. // n number of cols
  26. // Outputs:
  27. // X m by n matrix of type T whose entries are to be found
  28. //
  29. template <class IndexVector, class ValueVector, typename T>
  30. IGL_INLINE void sparse(
  31. const IndexVector & I,
  32. const IndexVector & J,
  33. const ValueVector & V,
  34. Eigen::SparseMatrix<T>& X);
  35. template <class IndexVector, class ValueVector, typename T>
  36. IGL_INLINE void sparse(
  37. const IndexVector & I,
  38. const IndexVector & J,
  39. const ValueVector & V,
  40. const size_t m,
  41. const size_t n,
  42. Eigen::SparseMatrix<T>& X);
  43. // THIS MAY BE SUPERSEDED BY EIGEN'S .sparseView Indeed it is.
  44. // Convert a full, dense matrix to a sparse one
  45. //
  46. // Templates:
  47. // T should be a eigen sparse matrix primitive type like int or double
  48. // Input:
  49. // D m by n full, dense matrix
  50. // Output:
  51. // X m by n sparse matrix
  52. template <typename DerivedD, typename T>
  53. IGL_INLINE void sparse(
  54. const Eigen::PlainObjectBase<DerivedD>& D,
  55. Eigen::SparseMatrix<T>& X);
  56. // Wrapper with return
  57. template <typename DerivedD>
  58. IGL_INLINE Eigen::SparseMatrix<typename DerivedD::Scalar > sparse(
  59. const Eigen::PlainObjectBase<DerivedD>& D);
  60. }
  61. #ifdef IGL_HEADER_ONLY
  62. # include "sparse.cpp"
  63. #endif
  64. #endif