accumarray.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. #include <test_common.h>
  9. #include <igl/accumarray.h>
  10. TEST_CASE("accumarray: matlab_help", "[igl]")
  11. {
  12. const Eigen::VectorXd V =
  13. (Eigen::VectorXd(5) << 101,102,103,104,105).finished();
  14. const Eigen::VectorXi S =
  15. (Eigen::VectorXi(5) << 0,2,3,2,3).finished();
  16. Eigen::VectorXd A;
  17. igl::accumarray(S,V,A);
  18. const Eigen::VectorXd Agt =
  19. (Eigen::VectorXd(4) << 101,0,206,208).finished();
  20. test_common::assert_eq(A,Agt);
  21. }
  22. TEST_CASE("accumarray: scalar", "[igl]")
  23. {
  24. const auto n =
  25. (Eigen::VectorXi(5) << 1,2,2,4,5).finished();
  26. Eigen::VectorXi C;
  27. igl::accumarray(n,1,C);
  28. const auto Cgt =
  29. (Eigen::VectorXi(6) << 0,1,2,0,1,1).finished();
  30. test_common::assert_eq(C,Cgt);
  31. }