Stan Math Library  2.20.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 <vector>
7 #include <numeric>
8 
9 namespace stan {
10 namespace math {
11 
23 template <typename T>
24 const std::vector<int> csr_extract_u(
25  const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
26  std::vector<int> u(A.outerSize() + 1); // last entry is garbage.
27  for (int nze = 0; nze <= A.outerSize(); ++nze)
28  u[nze] = *(A.outerIndexPtr() + nze) + stan::error_index::value;
29  return u;
30 }
31 
39 template <typename T, int R, int C>
40 const std::vector<int> csr_extract_u(const Eigen::Matrix<T, R, C>& A) {
41  Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
42  std::vector<int> u = csr_extract_u(B);
43  return u;
44 }
45  // end of csr_format group
47 
48 } // namespace math
49 } // namespace stan
50 
51 #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–2018, Stan Development Team.