| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Eigen_NumTraits.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP
2 #define STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/rev/core.hpp>
6 #include <stan/math/rev/core/std_numeric_limits.hpp>
7 #include <limits>
8
9 namespace Eigen {
10
18 template<> struct NumTraits<stan::math::var>
19 : GenericNumTraits<stan::math::var> {
20 static inline stan::math::var dummy_precision() {
21 return NumTraits<double>::dummy_precision();
22 }
23
24 enum {
25 RequireInitialization = 0,
26 // ReadCost = twice the cost to copy a double
27 ReadCost = 2 * NumTraits<double>::ReadCost,
28 // AddCost = single addition going forward
29 AddCost = NumTraits<double>::AddCost,
30 // MulCost = single multiplication going forward
31 MulCost = NumTraits<double>::MulCost
32 };
33 };
34
35 namespace internal {
39 template<>
40 struct significant_decimals_default_impl<stan::math::var, false> {
41 static inline int run() {
42 using std::ceil;
43 using std::log;
44 return cast<double, int>(ceil(-log(std::numeric_limits<double>
45 ::epsilon())
46 / log(10.0)));
47 }
48 };
49
54 template <>
55 struct scalar_product_traits<stan::math::var, double> {
56 typedef stan::math::var ReturnType;
57 };
58
63 template <>
64 struct scalar_product_traits<double, stan::math::var> {
65 typedef stan::math::var ReturnType;
66 };
67
71 template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
72 struct general_matrix_vector_product<Index, stan::math::var, ColMajor,
73 ConjugateLhs, stan::math::var,
74 ConjugateRhs> {
75 typedef stan::math::var LhsScalar;
76 typedef stan::math::var RhsScalar;
77 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
78 ResScalar;
79 enum { LhsStorageOrder = ColMajor };
80
81 EIGEN_DONT_INLINE static void run(
82 Index rows, Index cols,
83 const LhsScalar* lhs, Index lhsStride,
84 const RhsScalar* rhs, Index rhsIncr,
85 ResScalar* res, Index resIncr,
86 const ResScalar &alpha) {
87 for (Index i = 0; i < rows; i++) {
88 res[i*resIncr]
89 += stan::math::var
90 (new stan::math::gevv_vvv_vari
91 (&alpha,
92 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
93 ?(&lhs[i]):(&lhs[i*lhsStride]),
94 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
95 ?(lhsStride):(1),
96 rhs, rhsIncr, cols));
97 }
98 }
99 };
100 template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
101 struct general_matrix_vector_product<Index, stan::math::var,
102 RowMajor, ConjugateLhs,
103 stan::math::var, ConjugateRhs> {
104 typedef stan::math::var LhsScalar;
105 typedef stan::math::var RhsScalar;
106 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
107 ResScalar;
108 enum { LhsStorageOrder = RowMajor };
109
110 EIGEN_DONT_INLINE static void
111 run(Index rows, Index cols,
112 const LhsScalar* lhs, Index lhsStride,
113 const RhsScalar* rhs, Index rhsIncr,
114 ResScalar* res, Index resIncr, const RhsScalar &alpha) {
115 for (Index i = 0; i < rows; i++) {
116 res[i*resIncr]
117 += stan::math::var
118 (new stan::math::gevv_vvv_vari
119 (&alpha,
120 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
121 ? (&lhs[i]) : (&lhs[i*lhsStride]),
122 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
123 ? (lhsStride) : (1),
124 rhs, rhsIncr, cols));
125 }
126 }
127 };
128 template<typename Index, int LhsStorageOrder, bool ConjugateLhs,
129 int RhsStorageOrder, bool ConjugateRhs>
130 struct general_matrix_matrix_product<Index, stan::math::var,
131 LhsStorageOrder, ConjugateLhs,
132 stan::math::var, RhsStorageOrder,
133 ConjugateRhs, ColMajor> {
134 typedef stan::math::var LhsScalar;
135 typedef stan::math::var RhsScalar;
136 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
137 ResScalar;
138 static void run(Index rows, Index cols, Index depth,
139 const LhsScalar* lhs, Index lhsStride,
140 const RhsScalar* rhs, Index rhsStride,
141 ResScalar* res, Index resStride,
142 const ResScalar &alpha,
143 level3_blocking<LhsScalar, RhsScalar>& /* blocking */,
144 GemmParallelInfo<Index>* /* info = 0 */) {
145 for (Index i = 0; i < cols; i++) {
146 general_matrix_vector_product<Index, LhsScalar, LhsStorageOrder,
147 ConjugateLhs, RhsScalar, ConjugateRhs>
148 ::run(rows, depth, lhs, lhsStride,
149 &rhs[(static_cast<int>(RhsStorageOrder)
150 == static_cast<int>(ColMajor))
151 ? (i*rhsStride) :(i) ],
152 (static_cast<int>(RhsStorageOrder)
153 == static_cast<int>(ColMajor)) ? (1) : (rhsStride),
154 &res[i*resStride], 1, alpha);
155 }
156 }
157 };
158 }
159 }
160
161 #endif
stan::math::rows
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
Definition: rows.hpp:20
core.hpp
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, ColMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::run
static EIGEN_DONT_INLINE void run(Index rows, Index cols, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsIncr, ResScalar *res, Index resIncr, const ResScalar &alpha)
Definition: Eigen_NumTraits.hpp:81
Eigen::internal::significant_decimals_default_impl< stan::math::var, false >::run
static int run()
Definition: Eigen_NumTraits.hpp:41
std_numeric_limits.hpp
stan
Definition: log_sum_exp.hpp:8
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, RowMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::LhsScalar
stan::math::var LhsScalar
Definition: Eigen_NumTraits.hpp:104
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
Eigen::NumTraits< stan::math::var >::dummy_precision
static stan::math::var dummy_precision()
Definition: Eigen_NumTraits.hpp:20
Eigen::internal::general_matrix_matrix_product< Index, stan::math::var, LhsStorageOrder, ConjugateLhs, stan::math::var, RhsStorageOrder, ConjugateRhs, ColMajor >::ResScalar
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
Definition: Eigen_NumTraits.hpp:137
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, ColMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::ResScalar
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
Definition: Eigen_NumTraits.hpp:78
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:9
Eigen::internal::scalar_product_traits< stan::math::var, double >::ReturnType
stan::math::var ReturnType
Definition: Eigen_NumTraits.hpp:56
stan::math::gevv_vvv_vari
Definition: gevv_vvv_vari.hpp:11
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, RowMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::RhsScalar
stan::math::var RhsScalar
Definition: Eigen_NumTraits.hpp:105
Eigen::internal::general_matrix_matrix_product< Index, stan::math::var, LhsStorageOrder, ConjugateLhs, stan::math::var, RhsStorageOrder, ConjugateRhs, ColMajor >::LhsScalar
stan::math::var LhsScalar
Definition: Eigen_NumTraits.hpp:134
Eigen::internal::general_matrix_matrix_product< Index, stan::math::var, LhsStorageOrder, ConjugateLhs, stan::math::var, RhsStorageOrder, ConjugateRhs, ColMajor >::run
static void run(Index rows, Index cols, Index depth, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsStride, ResScalar *res, Index resStride, const ResScalar &alpha, level3_blocking< LhsScalar, RhsScalar > &, GemmParallelInfo< Index > *)
Definition: Eigen_NumTraits.hpp:138
stan::math::cols
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
Definition: cols.hpp:20
Eigen.hpp
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, ColMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::LhsScalar
stan::math::var LhsScalar
Definition: Eigen_NumTraits.hpp:75
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, RowMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::ResScalar
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
Definition: Eigen_NumTraits.hpp:107
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, RowMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::run
static EIGEN_DONT_INLINE void run(Index rows, Index cols, const LhsScalar *lhs, Index lhsStride, const RhsScalar *rhs, Index rhsIncr, ResScalar *res, Index resIncr, const RhsScalar &alpha)
Definition: Eigen_NumTraits.hpp:111
Eigen::internal::general_matrix_vector_product< Index, stan::math::var, ColMajor, ConjugateLhs, stan::math::var, ConjugateRhs >::RhsScalar
stan::math::var RhsScalar
Definition: Eigen_NumTraits.hpp:76
Eigen::internal::general_matrix_matrix_product< Index, stan::math::var, LhsStorageOrder, ConjugateLhs, stan::math::var, RhsStorageOrder, ConjugateRhs, ColMajor >::RhsScalar
stan::math::var RhsScalar
Definition: Eigen_NumTraits.hpp:135
stan::math::ceil
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11
Eigen::internal::scalar_product_traits< double, stan::math::var >::ReturnType
stan::math::var ReturnType
Definition: Eigen_NumTraits.hpp:65

[ Stan Home Page ] © 2011–2016, Stan Development Team.