12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "sum.h"
- #include "redux.h"
- template <typename T>
- IGL_INLINE void igl::sum(
- const Eigen::SparseMatrix<T>& X,
- const int dim,
- Eigen::SparseVector<T>& S)
- {
- assert((dim == 1 || dim == 2) && "dim must be 2 or 1");
-
- int m = X.rows();
- int n = X.cols();
-
- if(dim==1)
- {
- S = Eigen::SparseVector<T>(n);
- }else
- {
- S = Eigen::SparseVector<T>(m);
- }
-
- for(int k=0; k<X.outerSize(); ++k)
- {
-
- for(typename Eigen::SparseMatrix<T>::InnerIterator it (X,k); it; ++it)
- {
- if(dim == 1)
- {
- S.coeffRef(it.col()) += it.value();
- }else
- {
- S.coeffRef(it.row()) += it.value();
- }
- }
- }
- }
- template <typename AType, typename DerivedB>
- IGL_INLINE void igl::sum(
- const Eigen::SparseMatrix<AType> & A,
- const int dim,
- Eigen::PlainObjectBase<DerivedB>& B)
- {
- typedef typename DerivedB::Scalar Scalar;
- igl::redux(A,dim,[](Scalar a, Scalar b){ return a+b;},B);
- }
- #ifdef IGL_STATIC_LIBRARY
- template void igl::sum<double, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<double, 0, int> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
- template void igl::sum<bool, 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> >&);
- template void igl::sum<double>(Eigen::SparseMatrix<double, 0, int> const&, int, Eigen::SparseVector<double, 0, int>&);
- #endif
|