| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

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