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> {
287template <
typename CondScalar,
typename Arg1,
typename Arg2,
typename Arg3>
288struct ternary_evaluator<
292 IndexBased, IndexBased>
294 scalar_boolean_select_op<stan::math::var, stan::math::var,
298 scalar_boolean_select_op<stan::math::var, stan::math::var, CondScalar>,
306template <
typename EigVar,
typename EigVari,
typename EigDbl>
307struct functor_has_linear_access<
308 stan::math::vi_val_adj_functor<EigVar, EigVari, EigDbl>> {
315template <
typename EigVar,
typename EigDbl>
316struct functor_has_linear_access<
stan::math::val_adj_functor<EigVar, EigDbl>> {
323template <
typename EigVar,
typename EigVari>
324struct functor_has_linear_access<
stan::math::vi_val_functor<EigVar, EigVari>> {
331template <
typename EigVar,
typename EigVari>
332struct functor_has_linear_access<
stan::math::vi_adj_functor<EigVar, EigVari>> {
341struct remove_all<
stan::math::vari*> {
356template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
357 bool ConjugateRhs,
typename RhsMapper,
int Version>
358struct general_matrix_vector_product<Index,
stan::math::var, LhsMapper,
360 RhsMapper, ConjugateRhs, Version> {
364 enum { LhsStorageOrder = ColMajor };
366 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
367 const LhsMapper& lhsMapper,
368 const RhsMapper& rhsMapper,
ResScalar* res,
371 const Index lhsStride = lhsMapper.stride();
373 const Index rhsIncr = rhsMapper.stride();
374 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
377 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
384 for (Index i = 0; i < rows; ++i) {
385 res[i * resIncr] += var(
386 new gevv_vvv_vari(&alpha, &lhs[i], lhsStride, rhs, rhsIncr, cols));
391template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
392 bool ConjugateRhs,
typename RhsMapper,
int Version>
393struct general_matrix_vector_product<Index,
stan::math::var, LhsMapper,
395 RhsMapper, ConjugateRhs, Version> {
399 enum { LhsStorageOrder = RowMajor };
401 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
402 const LhsMapper& lhsMapper,
403 const RhsMapper& rhsMapper,
ResScalar* res,
406 const Index lhsStride = lhsMapper.stride();
408 const Index rhsIncr = rhsMapper.stride();
409 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
412 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
417 for (Index i = 0; i < rows; i++) {
420 (
static_cast<int>(LhsStorageOrder) ==
static_cast<int>(ColMajor))
422 : (&lhs[i * lhsStride]),
423 (
static_cast<int>(LhsStorageOrder) ==
static_cast<int>(ColMajor))
426 rhs, rhsIncr, cols));
431#if EIGEN_VERSION_AT_LEAST(3, 3, 8)
432template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
433 int RhsStorageOrder,
bool ConjugateRhs,
int ResInnerStride>
434struct general_matrix_matrix_product<
436 RhsStorageOrder, ConjugateRhs, ColMajor, ResInnerStride> {
438template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
439 int RhsStorageOrder,
bool ConjugateRhs>
440struct general_matrix_matrix_product<Index,
stan::math::var, LhsStorageOrder,
442 RhsStorageOrder, ConjugateRhs, ColMajor> {
448 using Traits = gebp_traits<RhsScalar, LhsScalar>;
451 = const_blas_data_mapper<stan::math::var, Index, LhsStorageOrder>;
453 = const_blas_data_mapper<stan::math::var, Index, RhsStorageOrder>;
456#if EIGEN_VERSION_AT_LEAST(3, 3, 8)
457 static void run(Index rows, Index cols, Index depth,
const LhsScalar* lhs,
458 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
459 ResScalar* res, Index resIncr, Index resStride,
461 level3_blocking<LhsScalar, RhsScalar>& ,
462 GemmParallelInfo<Index>* )
464 static void run(Index rows, Index cols, Index depth,
const LhsScalar* lhs,
465 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
467 level3_blocking<LhsScalar, RhsScalar>& ,
468 GemmParallelInfo<Index>* )
471 for (Index i = 0; i < cols; i++) {
472 general_matrix_vector_product<
475 ConjugateRhs>::run(rows, depth, lhs, lhsStride,
476 &rhs[
static_cast<int>(RhsStorageOrder)
477 ==
static_cast<int>(ColMajor)
480 static_cast<int>(RhsStorageOrder)
481 ==
static_cast<int>(ColMajor)
484 &res[i * resStride], 1, alpha);
489 static void run(Index rows, Index cols, Index depth,
492 level3_blocking<LhsScalar, RhsScalar>& blocking,
493 GemmParallelInfo<Index>* info = 0) {
495 const Index lhsStride = lhsMapper.stride();
497 const Index rhsStride = rhsMapper.stride();
499 run(rows, cols, depth, lhs, lhsStride, rhs, rhsStride, res, resStride,
500 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,...