normalize_row_sums.cpp 1.3 KB

1234567891011121314151617181920212223242526272829
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "normalize_row_sums.h"
  9. template <typename DerivedA, typename DerivedB>
  10. IGL_INLINE void igl::normalize_row_sums(
  11. const Eigen::MatrixBase<DerivedA>& A,
  12. Eigen::MatrixBase<DerivedB> & B)
  13. {
  14. #ifndef NDEBUG
  15. // loop over rows
  16. for(int i = 0; i < A.rows();i++)
  17. {
  18. typename DerivedB::Scalar sum = A.row(i).sum();
  19. assert(sum != 0);
  20. }
  21. #endif
  22. B = (A.array().colwise() / A.rowwise().sum().array()).eval();
  23. }
  24. #ifdef IGL_STATIC_LIBRARY
  25. // Explicit template specialization
  26. template void igl::normalize_row_sums<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  27. template void igl::normalize_row_sums<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&);
  28. #endif