Stan Math Library  2.9.0
reverse mode automatic differentiation
csr_extract_v.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CSR_EXTRACT_V_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CSR_EXTRACT_V_HPP
3 
4 #include <stan/math.hpp>
5 #include <Eigen/Sparse>
6 #include <vector>
7 #include <numeric>
8 
9 namespace stan {
10 
11  namespace math {
12 
25  template <typename T>
26  const std::vector<int>
27  csr_extract_v(const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
28  std::vector<int> v(A.nonZeros());
29  for (int nze = 0; nze < A.nonZeros(); ++nze)
30  v[nze] = *(A.innerIndexPtr() + nze) + stan::error_index::value;
31  return v;
32  }
33 
43  template <typename T, int R, int C>
44  const std::vector<int>
45  csr_extract_v(const Eigen::Matrix<T, R, C>& A) {
46  Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
47  std::vector<int> v = csr_extract_v(B);
48  return v;
49  }
50  // end of csr_format group
52  }
53 }
54 
55 #endif
const std::vector< int > csr_extract_v(const Eigen::SparseMatrix< T, Eigen::RowMajor > &A)
Extract the column indexes for non-zero value from a sparse matrix.

     [ Stan Home Page ] © 2011–2015, Stan Development Team.