max.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "max.h"
  2. #include "for_each.h"
  3. #include "find_zero.h"
  4. template <typename AType, typename DerivedB, typename DerivedI>
  5. IGL_INLINE void igl::max(
  6. const Eigen::SparseMatrix<AType> & A,
  7. const int dim,
  8. Eigen::PlainObjectBase<DerivedB> & B,
  9. Eigen::PlainObjectBase<DerivedI> & I)
  10. {
  11. const int n = A.cols();
  12. const int m = A.rows();
  13. B.resize(dim==1?n:m);
  14. B.setConstant(std::numeric_limits<typename DerivedB::Scalar>::lowest());
  15. I.resize(dim==1?n:m);
  16. for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v)
  17. {
  18. if(dim == 2)
  19. {
  20. std::swap(i,j);
  21. }
  22. // Coded as if dim == 1, assuming swap for dim == 2
  23. if(v > B(j))
  24. {
  25. B(j) = v;
  26. I(j) = i;
  27. }
  28. });
  29. Eigen::VectorXi Z;
  30. find_zero(A,dim,Z);
  31. for(int j = 0;j<I.size();j++)
  32. {
  33. if(Z(j) != (dim==1?m:n) && 0 > B(j))
  34. {
  35. B(j) = 0;
  36. I(j) = Z(j);
  37. }
  38. }
  39. }
  40. #ifdef IGL_STATIC_LIBRARY
  41. // Explicit template instantiation
  42. // generated by autoexplicit.sh
  43. template void igl::max<bool, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<bool, 0, int> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  44. #endif