| Stan Math Library 2.11.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/rev/core.hpp>
5 #include <stan/math/rev/core/gevv_vvv_vari.hpp>
6 #include <stan/math/prim/mat/fun/Eigen.hpp>
7 #include <limits>
8
9 namespace Eigen {
10
15 template <>
16 struct NumTraits<stan::math::var> {
22 typedef stan::math::var Real;
23
29 typedef stan::math::var NonInteger;
30
36 typedef stan::math::var Nested;
37
44 inline static Real epsilon() {
45 return std::numeric_limits<double>::epsilon();
46 }
47
51 inline static Real dummy_precision() {
52 return 1e-12; // copied from NumTraits.h values for double
53 }
54
61 inline static Real highest() {
62 return std::numeric_limits<double>::max();
63 }
64
71 inline static Real lowest() {
72 return -std::numeric_limits<double>::max();
73 }
74
79 enum {
80 IsInteger = 0,
81 IsSigned = 1,
82 IsComplex = 0,
83 RequireInitialization = 0,
84 ReadCost = 1,
85 AddCost = 1,
86 MulCost = 1,
87 HasFloatingPoint = 1
88 };
89 };
90
91 namespace internal {
95 template<>
96 struct significant_decimals_default_impl<stan::math::var, false> {
97 static inline int run() {
98 using std::ceil;
99 using std::log;
100 return cast<double, int>(ceil(-log(std::numeric_limits<double>
101 ::epsilon())
102 / log(10.0)));
103 }
104 };
105
110 template <>
111 struct scalar_product_traits<stan::math::var, double> {
112 typedef stan::math::var ReturnType;
113 };
114
119 template <>
120 struct scalar_product_traits<double, stan::math::var> {
121 typedef stan::math::var ReturnType;
122 };
123
127 template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
128 struct general_matrix_vector_product<Index, stan::math::var, ColMajor,
129 ConjugateLhs, stan::math::var,
130 ConjugateRhs> {
131 typedef stan::math::var LhsScalar;
132 typedef stan::math::var RhsScalar;
133 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
134 ResScalar;
135 enum { LhsStorageOrder = ColMajor };
136
137 EIGEN_DONT_INLINE static void run(
138 Index rows, Index cols,
139 const LhsScalar* lhs, Index lhsStride,
140 const RhsScalar* rhs, Index rhsIncr,
141 ResScalar* res, Index resIncr,
142 const ResScalar &alpha) {
143 for (Index i = 0; i < rows; i++) {
144 res[i*resIncr]
145 += stan::math::var
146 (new stan::math::gevv_vvv_vari
147 (&alpha,
148 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
149 ?(&lhs[i]):(&lhs[i*lhsStride]),
150 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
151 ?(lhsStride):(1),
152 rhs, rhsIncr, cols));
153 }
154 }
155 };
156 template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
157 struct general_matrix_vector_product<Index, stan::math::var,
158 RowMajor, ConjugateLhs,
159 stan::math::var, ConjugateRhs> {
160 typedef stan::math::var LhsScalar;
161 typedef stan::math::var RhsScalar;
162 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
163 ResScalar;
164 enum { LhsStorageOrder = RowMajor };
165
166 EIGEN_DONT_INLINE static void
167 run(Index rows, Index cols,
168 const LhsScalar* lhs, Index lhsStride,
169 const RhsScalar* rhs, Index rhsIncr,
170 ResScalar* res, Index resIncr, const RhsScalar &alpha) {
171 for (Index i = 0; i < rows; i++) {
172 res[i*resIncr]
173 += stan::math::var
174 (new stan::math::gevv_vvv_vari
175 (&alpha,
176 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
177 ? (&lhs[i]) : (&lhs[i*lhsStride]),
178 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
179 ? (lhsStride) : (1),
180 rhs, rhsIncr, cols));
181 }
182 }
183 };
184 template<typename Index, int LhsStorageOrder, bool ConjugateLhs,
185 int RhsStorageOrder, bool ConjugateRhs>
186 struct general_matrix_matrix_product<Index, stan::math::var,
187 LhsStorageOrder, ConjugateLhs,
188 stan::math::var, RhsStorageOrder,
189 ConjugateRhs, ColMajor> {
190 typedef stan::math::var LhsScalar;
191 typedef stan::math::var RhsScalar;
192 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
193 ResScalar;
194 static void run(Index rows, Index cols, Index depth,
195 const LhsScalar* _lhs, Index lhsStride,
196 const RhsScalar* _rhs, Index rhsStride,
197 ResScalar* res, Index resStride,
198 const ResScalar &alpha,
199 level3_blocking<LhsScalar, RhsScalar>& /* blocking */,
200 GemmParallelInfo<Index>* /* info = 0 */) {
201 for (Index i = 0; i < cols; i++) {
202 general_matrix_vector_product<Index, LhsScalar, LhsStorageOrder,
203 ConjugateLhs, RhsScalar, ConjugateRhs>
204 ::run(rows, depth, _lhs, lhsStride,
205 &_rhs[(static_cast<int>(RhsStorageOrder)
206 == static_cast<int>(ColMajor))
207 ? (i*rhsStride) :(i) ],
208 (static_cast<int>(RhsStorageOrder)
209 == static_cast<int>(ColMajor)) ? (1) : (rhsStride),
210 &res[i*resStride], 1, alpha);
211 }
212 }
213 };
214 }
215 }
216
217 #endif
Eigen::NumTraits< stan::math::var >::lowest
static Real lowest()
Return standard library's lowest for double-precision floating point, -std::numeric_limits max...
Definition: Eigen_NumTraits.hpp:71
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:137
Eigen::internal::significant_decimals_default_impl< stan::math::var, false >::run
static int run()
Definition: Eigen_NumTraits.hpp:97
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:160
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
Eigen::NumTraits< stan::math::var >::dummy_precision
static Real dummy_precision()
Return dummy precision.
Definition: Eigen_NumTraits.hpp:51
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:193
Eigen::NumTraits< stan::math::var >::NonInteger
stan::math::var NonInteger
Non-integer valued variables.
Definition: Eigen_NumTraits.hpp:29
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:134
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
Eigen::NumTraits< stan::math::var >::highest
static Real highest()
Return standard library's highest for double-precision floating point, std::numeric_limits max...
Definition: Eigen_NumTraits.hpp:61
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:8
Eigen::internal::scalar_product_traits< stan::math::var, double >::ReturnType
stan::math::var ReturnType
Definition: Eigen_NumTraits.hpp:112
stan::math::gevv_vvv_vari
Definition: gevv_vvv_vari.hpp:11
gevv_vvv_vari.hpp
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:161
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:190
Eigen::NumTraits< stan::math::var >::Real
stan::math::var Real
Real-valued variables.
Definition: Eigen_NumTraits.hpp:22
Eigen::NumTraits< stan::math::var >::epsilon
static Real epsilon()
Return standard library's epsilon for double-precision floating point, std::numeric_limits::e...
Definition: Eigen_NumTraits.hpp:44
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
stan::math::max
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:21
stan::math::e
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:95
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:131
Eigen::NumTraits< stan::math::var >::Nested
stan::math::var Nested
Nested variables.
Definition: Eigen_NumTraits.hpp:36
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:163
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:194
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:167
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:132
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:191
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:121

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