accumarray.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
  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. // ACCUMARRY Like Matlab's accumarray. Accumulate values in V using subscripts
  15. // in S.
  16. //
  17. // Inputs:
  18. // S #S list of subscripts
  19. // V #V list of values
  20. // Outputs:
  21. // A max(subs)+1 list of accumulated values
  22. template <
  23. typename DerivedS,
  24. typename DerivedV,
  25. typename DerivedA
  26. >
  27. void accumarray(
  28. const Eigen::MatrixBase<DerivedS> & S,
  29. const Eigen::MatrixBase<DerivedV> & V,
  30. Eigen::PlainObjectBase<DerivedA> & A);
  31. // Inputs:
  32. // S #S list of subscripts
  33. // V single value used for all
  34. // Outputs:
  35. // A max(subs)+1 list of accumulated values
  36. template <
  37. typename DerivedS,
  38. typename DerivedA
  39. >
  40. void accumarray(
  41. const Eigen::MatrixBase<DerivedS> & S,
  42. const typename DerivedA::Scalar V,
  43. Eigen::PlainObjectBase<DerivedA> & A);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "accumarray.cpp"
  47. #endif
  48. #endif