normalize_row_sums.cpp 1.3 KB

123456789101112131415161718192021222324252627282930
  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. // Resize output
  15. B.derived().resize(A.rows(),A.cols());
  16. // loop over rows
  17. for(int i = 0; i < A.rows();i++)
  18. {
  19. typename DerivedB::Scalar sum = A.row(i).sum();
  20. assert(sum != 0);
  21. B.row(i) = A.row(i).array()/sum;
  22. }
  23. }
  24. #ifndef IGL_HEADER_ONLY
  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