1#ifndef STAN_MATH_PRIM_FUN_HOLDER_HPP
2#define STAN_MATH_PRIM_FUN_HOLDER_HPP
70template <
class ArgType,
typename... Ptrs>
79template <
class ArgType,
typename... Ptrs>
80struct traits<
stan::math::Holder<ArgType, Ptrs...>> {
82 typedef typename traits<ArgType>::XprKind
XprKind;
84 typedef typename ArgType::Scalar
Scalar;
88 Flags = (ArgType::Flags
89 & (RowMajorBit | LvalueBit | LinearAccessBit | DirectAccessBit
90 | PacketAccessBit | NoPreferredStorageOrderBit))
92 RowsAtCompileTime = ArgType::RowsAtCompileTime,
93 ColsAtCompileTime = ArgType::ColsAtCompileTime,
94 MaxRowsAtCompileTime = ArgType::MaxRowsAtCompileTime,
95 MaxColsAtCompileTime = ArgType::MaxColsAtCompileTime,
96 InnerStrideAtCompileTime = ArgType::InnerStrideAtCompileTime,
97 OuterStrideAtCompileTime = ArgType::OuterStrideAtCompileTime
114template <
typename ArgType,
typename... Ptrs>
116 :
public Eigen::internal::dense_xpr_base<Holder<ArgType, Ptrs...>>::type {
118 typedef typename Eigen::internal::ref_selector<
Holder<ArgType, Ptrs...>>::type
120 typename Eigen::internal::ref_selector<ArgType>::non_const_type
m_arg;
143 template <
typename T, require_eigen_t<T>* =
nullptr>
157 m_arg = std::move(other.m_arg);
168template <
typename ArgType,
typename... Ptrs>
169struct evaluator<
stan::math::Holder<ArgType, Ptrs...>>
176 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
179 Flags = evaluator<ArgTypeNestedCleaned>::Flags,
180 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment,
189 return m_argImpl.coeff(row, col);
192 return m_argImpl.coeff(index);
196 return m_argImpl.coeffRef(row, col);
199 return m_argImpl.coeffRef(index);
202 template <
int LoadMode,
typename PacketType>
203 EIGEN_STRONG_INLINE PacketType
packet(Index row, Index col)
const {
204 return m_argImpl.template packet<LoadMode, PacketType>(row, col);
206 template <
int LoadMode,
typename PacketType>
207 EIGEN_STRONG_INLINE PacketType
packet(Index index)
const {
208 return m_argImpl.template packet<LoadMode, PacketType>(index);
211 template <
int StoreMode,
typename PacketType>
213 const PacketType& x) {
214 return m_argImpl.template writePacket<StoreMode, PacketType>(row, col, x);
216 template <
int StoreMode,
typename PacketType>
217 EIGEN_STRONG_INLINE
void writePacket(Index index,
const PacketType& x) {
218 return m_argImpl.template writePacket<StoreMode, PacketType>(index, x);
238template <
typename T,
typename... Ptrs,
239 std::enable_if_t<
sizeof...(Ptrs) >= 1>* =
nullptr>
241 return Holder<T, Ptrs...>(std::forward<T>(
arg), pointers...);
246 return std::forward<T>(
arg);
263 return std::make_tuple();
266 std::enable_if_t<!(Eigen::internal::traits<std::decay_t<T>>::Flags
267 & Eigen::NestByRefBit)>* =
nullptr>
270 return std::make_tuple();
283template <
typename T, require_t<std::is_rvalue_reference<T&&>>* =
nullptr,
285 static_cast<
bool>(Eigen::
internal::traits<std::decay_t<T>>::Flags&
286 Eigen::NestByRefBit)>* =
nullptr>
288 res =
new T(std::move(a));
289 return std::make_tuple(res);
291template <
typename T, require_t<std::is_rvalue_reference<T&&>>* =
nullptr,
292 require_not_eigen_t<T>* =
nullptr>
293auto holder_handle_element(T&& a, T*& res) {
294 res =
new T(std::move(a));
295 return std::make_tuple(res);
309template <
typename T, std::size_t... Is,
typename... Args>
311 const std::tuple<Args*...>& ptrs) {
312 return holder(std::forward<T>(expr), std::get<Is>(ptrs)...);
324template <
typename F, std::size_t... Is,
typename... Args>
327 std::tuple<std::remove_reference_t<Args>*...> res;
328 auto ptrs = std::tuple_cat(
331 func(*std::get<Is>(res)...),
332 std::make_index_sequence<std::tuple_size<
decltype(ptrs)>::value>(), ptrs);
349template <
typename F,
typename... Args,
351 decltype(std::declval<F>()(std::declval<Args&>()...))>* =
nullptr>
354 std::make_index_sequence<
sizeof...(Args)>(),
355 std::forward<Args>(args)...);
368template <
typename F,
typename... Args,
370 decltype(std::declval<F>()(std::declval<Args&>()...))>* =
nullptr>
372 return func(std::forward<Args>(args)...);
Eigen::internal::ref_selector< Holder< ArgType, Ptrs... > >::type Nested
Holder< ArgType, Ptrs... > & operator=(const Holder< ArgType, Ptrs... > &other)
Eigen::Index outerStride() const
Eigen::Index rows() const
Eigen::Index innerStride() const
Holder< ArgType, Ptrs... > & operator=(Holder< ArgType, Ptrs... > &&other)
Holder(const Holder< ArgType, Ptrs... > &)=default
Holder< ArgType, Ptrs... > & operator=(const T &other)
Assignment operator assigns expresssions.
Eigen::Index cols() const
std::tuple< std::unique_ptr< Ptrs >... > m_unique_ptrs
Eigen::internal::ref_selector< ArgType >::non_const_type m_arg
Holder(Holder< ArgType, Ptrs... > &&)=default
Holder(ArgType &&arg, Ptrs *... pointers)
require_not_t< is_plain_type< std::decay_t< T > > > require_not_plain_type_t
Require type does not satisfy is_plain_type.
require_t< is_plain_type< std::decay_t< T > > > require_plain_type_t
Require type satisfies is_plain_type.
(Expert) Numerical traits for algorithmic differentiation variables.
auto make_holder_impl_construct_object(T &&expr, std::index_sequence< Is... >, const std::tuple< Args *... > &ptrs)
Second step in implementation of construction holder from a functor.
auto holder_handle_element(T &a, T *&res)
Handles single element (moving rvalue non-expressions to heap) for construction of holder or holder_c...
auto make_holder_impl(const F &func, std::index_sequence< Is... >, Args &&... args)
Implementation of construction holder from a functor.
auto make_holder(const F &func, Args &&... args)
Constructs an expression from given arguments using given functor.
fvar< T > arg(const std::complex< fvar< T > > &z)
Return the phase angle of the complex argument.
Ptrs holder(T &&arg, Ptrs *... pointers)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
evaluator< ArgTypeNestedCleaned > m_argImpl
stan::math::Holder< ArgType, Ptrs... > XprType
void writePacket(Index row, Index col, const PacketType &x)
void writePacket(Index index, const PacketType &x)
Scalar & coeffRef(Index index)
CoeffReturnType coeff(Index index) const
CoeffReturnType coeff(Index row, Index col) const
remove_all< ArgType >::type ArgTypeNestedCleaned
PacketType packet(Index index) const
PacketType packet(Index row, Index col) const
Scalar & coeffRef(Index row, Index col)
XprType::CoeffReturnType CoeffReturnType
evaluator(const XprType &xpr)
ArgType::StorageKind StorageKind
traits< ArgType >::XprKind XprKind
ArgType::StorageIndex StorageIndex