harwell_boeing.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "harwell_boeing.h"
  2. template <typename Scalar, typename Index>
  3. IGL_INLINE void igl::harwell_boeing(
  4. const Eigen::SparseMatrix<Scalar> & A,
  5. int & num_rows,
  6. std::vector<Scalar> & V,
  7. std::vector<Index> & R,
  8. std::vector<Index> & C)
  9. {
  10. num_rows = A.rows();
  11. int num_cols = A.cols();
  12. int nnz = A.nonZeros();
  13. V.resize(nnz);
  14. R.resize(nnz);
  15. C.resize(num_cols+1);
  16. // Assumes outersize is columns
  17. assert(A.cols() == A.outerSize());
  18. int column_pointer = 0;
  19. int i = 0;
  20. int k = 0;
  21. // Iterate over outside
  22. for(; k<A.outerSize(); ++k)
  23. {
  24. C[k] = column_pointer;
  25. // Iterate over inside
  26. for(typename Eigen::SparseMatrix<Scalar>::InnerIterator it (A,k); it; ++it)
  27. {
  28. V[i] = it.value();
  29. R[i] = it.row();
  30. i++;
  31. // Also increment column pointer
  32. column_pointer++;
  33. }
  34. }
  35. // by convention C[num_cols] = nnz
  36. C[k] = column_pointer;
  37. }
  38. #ifndef IGL_HEADER_ONLY
  39. // Explicit template specialization
  40. // generated by autoexplicit.sh
  41. template void igl::harwell_boeing<double, int>(Eigen::SparseMatrix<double, 0, int> const&, int&, std::vector<double, std::allocator<double> >&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&);
  42. #endif