| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/prim/scal/meta/error_index.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <Eigen/Sparse>
7 #include <vector>
8 #include <numeric>
9
10 namespace stan {
11
12 namespace math {
13
26 template <typename T>
27 const std::vector<int>
28 csr_extract_v(const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
29 std::vector<int> v(A.nonZeros());
30 for (int nze = 0; nze < A.nonZeros(); ++nze)
31 v[nze] = *(A.innerIndexPtr() + nze) + stan::error_index::value;
32 return v;
33 }
34
44 template <typename T, int R, int C>
45 const std::vector<int>
46 csr_extract_v(const Eigen::Matrix<T, R, C>& A) {
47 Eigen::SparseMatrix<T, Eigen::RowMajor> B = A.sparseView();
48 std::vector<int> v = csr_extract_v(B);
49 return v;
50 }
51 // end of csr_format group
53 }
54 }
55
56 #endif
stan
Definition: log_sum_exp.hpp:8
stan::error_index::value
Definition: error_index.hpp:7
stan::math::csr_extract_v
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.
Definition: csr_extract_v.hpp:28
Eigen.hpp
error_index.hpp

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