accumarray.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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 "accumarray.h"
  9. #include <cassert>
  10. template <
  11. typename DerivedS,
  12. typename DerivedV,
  13. typename DerivedA
  14. >
  15. void igl::accumarray(
  16. const Eigen::MatrixBase<DerivedS> & S,
  17. const Eigen::MatrixBase<DerivedV> & V,
  18. Eigen::PlainObjectBase<DerivedA> & A)
  19. {
  20. assert(V.size() == S.size() && "S and V should be same size");
  21. A.setZero(S.maxCoeff()+1,1);
  22. for(int s = 0;s<S.size();s++)
  23. {
  24. A(S(s)) += V(s);
  25. }
  26. }
  27. #ifdef IGL_STATIC_LIBRARY
  28. // Explicit template instantiations
  29. template void igl::accumarray<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  30. #endif