Automatic Differentiation
 
Loading...
Searching...
No Matches
csr_extract_u.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_CSR_EXTRACT_U_HPP
2#define STAN_MATH_PRIM_FUN_CSR_EXTRACT_U_HPP
3
7#include <vector>
8#include <numeric>
9
10namespace stan {
11namespace math {
12
24template <typename T>
25const std::vector<int> csr_extract_u(
26 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 }
31 return u;
32}
33
43template <typename T, require_eigen_dense_base_t<T>* = nullptr>
44const std::vector<int> csr_extract_u(const T& A) {
45 // conversion to sparse seems to touch data twice, so we need to call to_ref
46 Eigen::SparseMatrix<scalar_type_t<T>, Eigen::RowMajor> B
47 = to_ref(A).sparseView();
48 std::vector<int> u = csr_extract_u(B);
49 return u;
50}
51 // end of csr_format group
53
54} // namespace math
55} // namespace stan
56
57#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.
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 ...