harwell_boeing.cpp 1.5 KB

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