1#ifndef STAN_MATH_REV_FUN_TO_SOA_SPARSE_MATRIX_HPP
2#define STAN_MATH_REV_FUN_TO_SOA_SPARSE_MATRIX_HPP
28template <
int Options = Eigen::ColMajor,
typename VarMatrix,
typename Vec1,
29 typename Vec2, require_var_t<VarMatrix>* =
nullptr,
30 require_eigen_dense_base_t<value_type_t<VarMatrix>>* =
nullptr,
31 require_all_std_vector_vt<std::is_integral, Vec1, Vec2>* =
nullptr>
34 auto u_arena =
to_arena(std::forward<Vec1>(u));
35 auto v_arena =
to_arena(std::forward<Vec2>(v));
36 using sparse_mat_t = Eigen::SparseMatrix<double, Options>;
38 sparse_arena_mat_t arena_val_x(m, n, w.val().size(), u_arena.data(),
39 v_arena.data(), w.vi_->val_.data());
40 sparse_arena_mat_t arena_adj_x(m, n, w.adj().size(), u_arena.data(),
41 v_arena.data(), w.vi_->adj_.data());
62template <
int Options = Eigen::ColMajor,
typename MatrixVar,
typename Vec1,
68 auto w_arena =
to_arena(std::forward<MatrixVar>(w));
69 auto u_arena =
to_arena(std::forward<Vec1>(u));
70 auto v_arena =
to_arena(std::forward<Vec2>(v));
72 m, n, w_arena.size(), u_arena.data(), v_arena.data(), w_arena.data());
76 using var_sparse_iterator_t =
78 using dbl_sparse_iterator_t =
81 for (
int k = 0; k < arena_x.outerSize(); ++k) {
82 var_sparse_iterator_t it_arena_x(arena_x, k);
83 dbl_sparse_iterator_t it_var_x(var_x.adj(), k);
84 for (;
static_cast<bool>(it_arena_x) &&
static_cast<bool>(it_var_x);
85 ++it_arena_x, ++it_var_x) {
86 it_arena_x.valueRef().adj() += it_var_x.valueRef();
109template <
int Options = Eigen::ColMajor,
typename Mat,
typename Vec1,
114 auto w_arena =
to_arena(std::forward<Mat>(w));
115 auto u_arena =
to_arena(std::forward<Vec1>(u));
116 auto v_arena =
to_arena(std::forward<Vec2>(v));
118 m, n, w_arena.size(), u_arena.data(), v_arena.data(), w_arena.data());
require_t< container_type_check_base< is_eigen_dense_base, value_type_t, TypeCheck, Check... > > require_eigen_dense_base_vt
Require type satisfies is_eigen_dense_base.
require_all_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check >... > require_all_std_vector_vt
Require all of the types satisfy is_std_vector.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
auto to_soa_sparse_matrix(int m, int n, VarMatrix &&w, Vec1 &&u, Vec2 &&v)
Create a sparse matrix from the given SoA matrix and indexes.
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...