cumsum.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_CUMSUM_H
  9. #define IGL_CUMSUM_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Computes a cumulative sum of the columns of X, like matlab's `cumsum`.
  15. ///
  16. /// @tparam DerivedX Type of matrix X
  17. /// @tparam DerivedY Type of matrix Y
  18. /// @param[in] X m by n Matrix to be cumulatively summed.
  19. /// @param[in] dim dimension to take cumulative sum (1 or 2)
  20. /// @param[out] Y m by n Matrix containing cumulative sum.
  21. ///
  22. template <typename DerivedX, typename DerivedY>
  23. IGL_INLINE void cumsum(
  24. const Eigen::MatrixBase<DerivedX > & X,
  25. const int dim,
  26. Eigen::PlainObjectBase<DerivedY > & Y);
  27. /// Computes a cumulative sum of the columns of [0;X]
  28. ///
  29. /// @param[in] X m by n Matrix to be cumulatively summed.
  30. /// @param[in] dim dimension to take cumulative sum (1 or 2)
  31. /// @param[in] zero_prefix whether to use zero prefix
  32. /// @param[out] Y if zero_prefix == false
  33. /// m by n Matrix containing cumulative sum
  34. /// else
  35. /// m+1 by n Matrix containing cumulative sum if dim=1
  36. /// or
  37. /// m by n+1 Matrix containing cumulative sum if dim=2
  38. template <typename DerivedX, typename DerivedY>
  39. IGL_INLINE void cumsum(
  40. const Eigen::MatrixBase<DerivedX > & X,
  41. const int dim,
  42. const bool zero_prefix,
  43. Eigen::PlainObjectBase<DerivedY > & Y);
  44. //template <typename DerivedX, typename DerivedY>
  45. //IGL_INLINE void cumsum(
  46. // const Eigen::MatrixBase<DerivedX > & X,
  47. // Eigen::PlainObjectBase<DerivedY > & Y);
  48. }
  49. #ifndef IGL_STATIC_LIBRARY
  50. # include "cumsum.cpp"
  51. #endif
  52. #endif