Stan Math Library  2.11.0
reverse mode automatic differentiation
csr_extract_u.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CSR_EXTRACT_U_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CSR_EXTRACT_U_HPP
3 
6 #include <Eigen/Sparse>
7 #include <vector>
8 #include <numeric>
9 
10 namespace stan {
11 
12  namespace math {
13 
25  template <typename T>
26  const std::vector<int>
27  csr_extract_u(const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
28  std::vector<int> u(A.outerSize() + 1); // last entry is garbage.
29  for (int nze = 0; nze <= A.outerSize(); ++nze)
30  u[nze] = *(A.outerIndexPtr() + nze) + stan::error_index::value;
31  return u;
32  }
33 
41  template <typename T, int R, int C>
42  const std::vector<int>
43  csr_extract_u(const Eigen::Matrix<T, R, C>& A) {
44  Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
45  std::vector<int> u = csr_extract_u(B);
46  return u;
47  }
48  // end of csr_format group
50 
51  }
52 }
53 
54 #endif
const std::vector< int > csr_extract_u(const Eigen::SparseMatrix< T, Eigen::RowMajor > &A)
Extract the NZE index for each entry from a sparse matrix.

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