Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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 
4 #include <stan/math.hpp>
5 #include <Eigen/Sparse>
6 #include <vector>
7 #include <numeric>
8 
9 namespace stan {
10 
11  namespace math {
12 
24  template <typename T>
25  const std::vector<int>
26  csr_extract_u(const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
27  std::vector<int> u(A.outerSize() + 1); // last entry is garbage.
28  for (int nze = 0; nze <= A.outerSize(); ++nze)
29  u[nze] = *(A.outerIndexPtr() + nze) + stan::error_index::value;
30  return u;
31  }
32 
40  template <typename T, int R, int C>
41  const std::vector<int>
42  csr_extract_u(const Eigen::Matrix<T, R, C>& A) {
43  Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
44  std::vector<int> u = csr_extract_u(B);
45  return u;
46  }
47  // end of csr_format group
49 
50  }
51 }
52 
53 #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–2015, Stan Development Team.