Stan Math Library  2.20.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 
6 #include <vector>
7 #include <numeric>
8 
9 namespace stan {
10 namespace math {
11 
24 template <typename T>
25 const std::vector<int> csr_extract_v(
26  const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
27  std::vector<int> v(A.nonZeros());
28  for (int nze = 0; nze < A.nonZeros(); ++nze)
29  v[nze] = *(A.innerIndexPtr() + nze) + stan::error_index::value;
30  return v;
31 }
32 
42 template <typename T, int R, int C>
43 const std::vector<int> csr_extract_v(const Eigen::Matrix<T, R, C>& A) {
44  Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
45  std::vector<int> v = csr_extract_v(B);
46  return v;
47 }
48  // end of csr_format group
50 } // namespace math
51 } // namespace stan
52 
53 #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–2018, Stan Development Team.