cat.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef IGL_CAT_H
  2. #define IGL_CAT_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Sparse>
  6. #include <Eigen/Dense>
  7. namespace igl
  8. {
  9. // If you're using Dense matrices you might be better off using the << operator
  10. // This is an attempt to act like matlab's cat function.
  11. // Perform concatenation of a two matrices along a single dimension
  12. // If dim == 1, then C = [A;B]. If dim == 2 then C = [A B]
  13. //
  14. // Template:
  15. // Scalar scalar data type for sparse matrices like double or int
  16. // Mat matrix type for all matrices (e.g. MatrixXd, SparseMatrix)
  17. // MatC matrix type for ouput matrix (e.g. MatrixXd) needs to support
  18. // resize
  19. // Inputs:
  20. // A first input matrix
  21. // B second input matrix
  22. // dim dimension along which to concatenate, 0 or 1
  23. // Outputs:
  24. // C output matrix
  25. //
  26. template <typename Scalar>
  27. IGL_INLINE void cat(
  28. const int dim,
  29. const Eigen::SparseMatrix<Scalar> & A,
  30. const Eigen::SparseMatrix<Scalar> & B,
  31. Eigen::SparseMatrix<Scalar> & C);
  32. template <typename Derived, class MatC>
  33. IGL_INLINE void cat(
  34. const int dim,
  35. const Eigen::MatrixBase<Derived> & A,
  36. const Eigen::MatrixBase<Derived> & B,
  37. MatC & C);
  38. // Wrapper that returns C
  39. template <class Mat>
  40. IGL_INLINE Mat cat(const int dim, const Mat & A, const Mat & B);
  41. // Note: Maybe we can autogenerate a bunch of overloads D = cat(int,A,B,C),
  42. // E = cat(int,A,B,C,D), etc.
  43. // Concatenate a "matrix" of blocks
  44. // C = [A0;A1;A2;...;An] where Ai = [A[i][0] A[i][1] ... A[i][m]];
  45. //
  46. // Inputs:
  47. // A a matrix (vector of row vectors)
  48. // Output:
  49. // C
  50. template <class Mat>
  51. IGL_INLINE void cat(const std::vector<std::vector< Mat > > & A, Mat & C);
  52. }
  53. #ifdef IGL_HEADER_ONLY
  54. # include "cat.cpp"
  55. #endif
  56. #endif