Automatic Differentiation
 
Loading...
Searching...
No Matches
csr_extract_v.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_CSR_EXTRACT_V_HPP
2#define STAN_MATH_PRIM_FUN_CSR_EXTRACT_V_HPP
3
7#include <vector>
8#include <numeric>
9
10namespace stan {
11namespace math {
12
25template <typename T>
26const std::vector<int> csr_extract_v(
27 const Eigen::SparseMatrix<T, Eigen::RowMajor>& A) {
28 std::vector<int> v(A.nonZeros());
29 for (int nze = 0; nze < A.nonZeros(); ++nze) {
30 v[nze] = *(A.innerIndexPtr() + nze) + stan::error_index::value;
31 }
32 return v;
33}
34
47template <typename T, require_eigen_dense_base_t<T>* = nullptr>
48const std::vector<int> csr_extract_v(const T& A) {
49 // conversion to sparse seems to touch data twice, so we need to call to_ref
50 Eigen::SparseMatrix<scalar_type_t<T>, Eigen::RowMajor> B
51 = to_ref(A).sparseView();
52 std::vector<int> v = csr_extract_v(B);
53 return v;
54}
55 // end of csr_format group
57
58} // namespace math
59} // namespace stan
60
61#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.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9