accumarray.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 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 ACCUMARRY_H
  9. #define ACCUMARRY_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Accumulate values in V using subscripts in S. Like Matlab's accumarray.
  15. ///
  16. /// @param[in] S #S list of subscripts
  17. /// @param[in] V #V list of values
  18. /// @param[out] A max(subs)+1 list of accumulated values
  19. template <
  20. typename DerivedS,
  21. typename DerivedV,
  22. typename DerivedA
  23. >
  24. void accumarray(
  25. const Eigen::MatrixBase<DerivedS> & S,
  26. const Eigen::MatrixBase<DerivedV> & V,
  27. Eigen::PlainObjectBase<DerivedA> & A);
  28. /// Accumulate constant value `V` using subscripts in S. Like Matlab's accumarray.
  29. ///
  30. /// @param[in] S #S list of subscripts
  31. /// @param[in] V single value used for all
  32. /// @param[out] A max(subs)+1 list of accumulated values
  33. template <
  34. typename DerivedS,
  35. typename DerivedA
  36. >
  37. void accumarray(
  38. const Eigen::MatrixBase<DerivedS> & S,
  39. const typename DerivedA::Scalar V,
  40. Eigen::PlainObjectBase<DerivedA> & A);
  41. }
  42. #ifndef IGL_STATIC_LIBRARY
  43. # include "accumarray.cpp"
  44. #endif
  45. #endif