1#ifndef STAN_MATH_REV_CORE_EIGEN_NUMTRAITS_HPP
2#define STAN_MATH_REV_CORE_EIGEN_NUMTRAITS_HPP
36 return NumTraits<double>::dummy_precision();
39 static inline Real epsilon() {
return NumTraits<double>::epsilon(); }
41 static inline Real highest() {
return NumTraits<double>::highest(); }
42 static inline Real lowest() {
return NumTraits<double>::lowest(); }
65 RequireInitialization = 0,
70 ReadCost = 2 * NumTraits<double>::ReadCost,
76 AddCost = NumTraits<double>::AddCost,
82 MulCost = NumTraits<double>::MulCost
90 static int digits10() {
return std::numeric_limits<double>::digits10; }
100template <
typename BinaryOp>
101struct ScalarBinaryOpTraits<
stan::math::var, double, BinaryOp> {
112template <
typename BinaryOp>
113struct ScalarBinaryOpTraits<double,
stan::math::var, BinaryOp> {
124template <
typename BinaryOp>
125struct ScalarBinaryOpTraits<
stan::math::var, int, BinaryOp> {
136template <
typename BinaryOp>
137struct ScalarBinaryOpTraits<int,
stan::math::var, BinaryOp> {
149template <
typename BinaryOp>
161template <
typename BinaryOp>
162struct ScalarBinaryOpTraits<double,
std::complex<stan::math::var>, BinaryOp> {
173template <
typename BinaryOp>
174struct ScalarBinaryOpTraits<
std::complex<stan::math::var>, double, BinaryOp> {
185template <
typename BinaryOp>
186struct ScalarBinaryOpTraits<int,
std::complex<stan::math::var>, BinaryOp> {
197template <
typename BinaryOp>
198struct ScalarBinaryOpTraits<
std::complex<stan::math::var>, int, BinaryOp> {
209template <
typename BinaryOp>
210struct ScalarBinaryOpTraits<
stan::math::var, std::complex<double>, BinaryOp> {
221template <
typename BinaryOp>
233template <
typename BinaryOp>
234struct ScalarBinaryOpTraits<
std::complex<double>, std::complex<stan::math::var>,
246template <
typename BinaryOp>
247struct ScalarBinaryOpTraits<
std::complex<stan::math::var>, std::complex<double>,
252template <
typename BinaryOp>
253struct ScalarBinaryOpTraits<
stan::math::var, std::complex<stan::math::var>,
258template <
typename BinaryOp>
264template <
typename BinaryOp>
265struct ScalarBinaryOpTraits<
std::complex<stan::math::var>,
266 std::complex<stan::math::var>, BinaryOp> {
272#if EIGEN_VERSION_AT_LEAST(5, 0, 0)
288template <
typename CondScalar,
typename Arg1,
typename Arg2,
typename Arg3>
289struct ternary_evaluator<
293 IndexBased, IndexBased>
295 scalar_boolean_select_op<stan::math::var, stan::math::var,
299 scalar_boolean_select_op<stan::math::var, stan::math::var, CondScalar>,
308template <
typename EigVar,
typename EigVari,
typename EigDbl>
309struct functor_has_linear_access<
310 stan::math::vi_val_adj_functor<EigVar, EigVari, EigDbl>> {
317template <
typename EigVar,
typename EigDbl>
318struct functor_has_linear_access<
stan::math::val_adj_functor<EigVar, EigDbl>> {
325template <
typename EigVar,
typename EigVari>
326struct functor_has_linear_access<
stan::math::vi_val_functor<EigVar, EigVari>> {
333template <
typename EigVar,
typename EigVari>
334struct functor_has_linear_access<
stan::math::vi_adj_functor<EigVar, EigVari>> {
343struct remove_all<
stan::math::vari*> {
358template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
359 bool ConjugateRhs,
typename RhsMapper,
int Version>
360struct general_matrix_vector_product<Index,
stan::math::var, LhsMapper,
362 RhsMapper, ConjugateRhs, Version> {
366 enum { LhsStorageOrder = ColMajor };
368 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
369 const LhsMapper& lhsMapper,
370 const RhsMapper& rhsMapper,
ResScalar* res,
373 const Index lhsStride = lhsMapper.stride();
375 const Index rhsIncr = rhsMapper.stride();
376 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
379 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
386 for (Index i = 0; i < rows; ++i) {
387 res[i * resIncr] += var(
388 new gevv_vvv_vari(&alpha, &lhs[i], lhsStride, rhs, rhsIncr, cols));
393template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
394 bool ConjugateRhs,
typename RhsMapper,
int Version>
395struct general_matrix_vector_product<Index,
stan::math::var, LhsMapper,
397 RhsMapper, ConjugateRhs, Version> {
401 enum { LhsStorageOrder = RowMajor };
403 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
404 const LhsMapper& lhsMapper,
405 const RhsMapper& rhsMapper,
ResScalar* res,
408 const Index lhsStride = lhsMapper.stride();
410 const Index rhsIncr = rhsMapper.stride();
411 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
414 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
419 for (Index i = 0; i < rows; i++) {
422 (
static_cast<int>(LhsStorageOrder) ==
static_cast<int>(ColMajor))
424 : (&lhs[i * lhsStride]),
425 (
static_cast<int>(LhsStorageOrder) ==
static_cast<int>(ColMajor))
428 rhs, rhsIncr, cols));
433#if EIGEN_VERSION_AT_LEAST(3, 3, 8)
434template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
435 int RhsStorageOrder,
bool ConjugateRhs,
int ResInnerStride>
436struct general_matrix_matrix_product<
438 RhsStorageOrder, ConjugateRhs, ColMajor, ResInnerStride> {
440template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
441 int RhsStorageOrder,
bool ConjugateRhs>
442struct general_matrix_matrix_product<Index,
stan::math::var, LhsStorageOrder,
444 RhsStorageOrder, ConjugateRhs, ColMajor> {
450 using Traits = gebp_traits<RhsScalar, LhsScalar>;
453 = const_blas_data_mapper<stan::math::var, Index, LhsStorageOrder>;
455 = const_blas_data_mapper<stan::math::var, Index, RhsStorageOrder>;
458#if EIGEN_VERSION_AT_LEAST(3, 3, 8)
459 static void run(Index rows, Index cols, Index depth,
const LhsScalar* lhs,
460 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
461 ResScalar* res, Index resIncr, Index resStride,
463 level3_blocking<LhsScalar, RhsScalar>& ,
464 GemmParallelInfo<Index>* )
466 static void run(Index rows, Index cols, Index depth,
const LhsScalar* lhs,
467 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
469 level3_blocking<LhsScalar, RhsScalar>& ,
470 GemmParallelInfo<Index>* )
473 for (Index i = 0; i < cols; i++) {
474 general_matrix_vector_product<
477 ConjugateRhs>::run(rows, depth, lhs, lhsStride,
478 &rhs[
static_cast<int>(RhsStorageOrder)
479 ==
static_cast<int>(ColMajor)
482 static_cast<int>(RhsStorageOrder)
483 ==
static_cast<int>(ColMajor)
486 &res[i * resStride], 1, alpha);
491 static void run(Index rows, Index cols, Index depth,
494 level3_blocking<LhsScalar, RhsScalar>& blocking,
495 GemmParallelInfo<Index>* info = 0) {
497 const Index lhsStride = lhsMapper.stride();
499 const Index rhsStride = rhsMapper.stride();
501 run(rows, cols, depth, lhs, lhsStride, rhs, rhsStride, res, resStride,
502 alpha, blocking, info);
Specialization of the standard library complex number type for reverse-mode autodiff type stan::math:...
(Expert) Numerical traits for algorithmic differentiation variables.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
static Real dummy_precision()
Return the precision for stan::math::var delegates to precision for double.
static int digits10()
Return the number of decimal digits that can be represented without change.
const_blas_data_mapper< stan::math::var, Index, LhsStorageOrder > LhsMapper
gebp_traits< RhsScalar, LhsScalar > Traits
const_blas_data_mapper< stan::math::var, Index, RhsStorageOrder > RhsMapper
static void run(Index rows, Index cols, Index depth, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsStride, ResScalar *res, Index resIncr, Index resStride, const ResScalar &alpha, level3_blocking< LhsScalar, RhsScalar > &, GemmParallelInfo< Index > *)
static void run(Index rows, Index cols, Index depth, const LhsMapper &lhsMapper, const RhsMapper &rhsMapper, ResScalar *res, Index resStride, const ResScalar &alpha, level3_blocking< LhsScalar, RhsScalar > &blocking, GemmParallelInfo< Index > *info=0)
static void run(Index rows, Index cols, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsIncr, ResScalar *res, Index resIncr, const RhsScalar &alpha)
static void run(Index rows, Index cols, const LhsMapper &lhsMapper, const RhsMapper &rhsMapper, ResScalar *res, Index resIncr, const RhsScalar &alpha)
static void run(Index rows, Index cols, const LhsMapper &lhsMapper, const RhsMapper &rhsMapper, ResScalar *res, Index resIncr, const ResScalar &alpha)
static void run(Index rows, Index cols, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsIncr, ResScalar *res, Index resIncr, const ResScalar &alpha)
typename Arg3::Scalar CondScalar
Evaluator for .select() expressions that evaluates only the branch chosen by the condition,...