1 #ifndef STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP 2 #define STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP 20 struct NumTraits<
stan::math::var> : GenericNumTraits<stan::math::var> {
32 return NumTraits<double>::dummy_precision();
54 RequireInitialization = 0,
59 ReadCost = 2 * NumTraits<double>::ReadCost,
65 AddCost = NumTraits<double>::AddCost,
71 MulCost = NumTraits<double>::MulCost
79 static int digits10() {
return std::numeric_limits<double>::digits10; }
88 struct remove_all<
stan::math::vari*> {
92 #if EIGEN_VERSION_AT_LEAST(3, 3, 0) 98 struct scalar_product_traits<
stan::math::var, double> {
107 struct scalar_product_traits<double, stan::math::var> {
122 template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
123 bool ConjugateRhs,
typename RhsMapper,
int Version>
124 struct general_matrix_vector_product<Index, stan::math::var, LhsMapper,
126 RhsMapper, ConjugateRhs, Version> {
130 enum { LhsStorageOrder = ColMajor };
132 EIGEN_DONT_INLINE
static void run(Index
rows, Index
cols,
133 const LhsMapper& lhsMapper,
134 const RhsMapper& rhsMapper, ResScalar* res,
135 Index resIncr,
const ResScalar& alpha) {
136 const LhsScalar* lhs = lhsMapper.data();
137 const Index lhsStride = lhsMapper.stride();
138 const RhsScalar* rhs = rhsMapper.data();
139 const Index rhsIncr = rhsMapper.stride();
140 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
143 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
144 const LhsScalar* lhs, Index lhsStride,
145 const RhsScalar* rhs, Index rhsIncr,
146 ResScalar* res, Index resIncr,
147 const ResScalar& alpha) {
150 for (Index i = 0; i <
rows; ++i) {
151 res[i * resIncr] += var(
152 new gevv_vvv_vari(&alpha, &lhs[i], lhsStride, rhs, rhsIncr, cols));
157 template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
158 bool ConjugateRhs,
typename RhsMapper,
int Version>
159 struct general_matrix_vector_product<Index, stan::math::var, LhsMapper,
161 RhsMapper, ConjugateRhs, Version> {
165 enum { LhsStorageOrder = RowMajor };
167 EIGEN_DONT_INLINE
static void run(Index
rows, Index
cols,
168 const LhsMapper& lhsMapper,
169 const RhsMapper& rhsMapper, ResScalar* res,
170 Index resIncr,
const RhsScalar& alpha) {
171 const LhsScalar* lhs = lhsMapper.data();
172 const Index lhsStride = lhsMapper.stride();
173 const RhsScalar* rhs = rhsMapper.data();
174 const Index rhsIncr = rhsMapper.stride();
175 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
178 EIGEN_DONT_INLINE
static void run(Index rows, Index cols,
179 const LhsScalar* lhs, Index lhsStride,
180 const RhsScalar* rhs, Index rhsIncr,
181 ResScalar* res, Index resIncr,
182 const RhsScalar& alpha) {
183 for (Index i = 0; i <
rows; i++) {
186 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
188 : (&lhs[i * lhsStride]),
189 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
192 rhs, rhsIncr, cols));
197 template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
198 int RhsStorageOrder,
bool ConjugateRhs>
199 struct general_matrix_matrix_product<Index, stan::math::var, LhsStorageOrder,
201 RhsStorageOrder, ConjugateRhs, ColMajor> {
206 typedef gebp_traits<RhsScalar, LhsScalar> Traits;
208 typedef const_blas_data_mapper<stan::math::var, Index, LhsStorageOrder>
210 typedef const_blas_data_mapper<stan::math::var, Index, RhsStorageOrder>
214 static void run(Index
rows, Index
cols, Index depth,
const LhsScalar* lhs,
215 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
216 ResScalar* res, Index resStride,
const ResScalar& alpha,
217 level3_blocking<LhsScalar, RhsScalar>& ,
218 GemmParallelInfo<Index>* ) {
219 for (Index i = 0; i <
cols; i++) {
220 general_matrix_vector_product<
221 Index, LhsScalar, LhsMapper, LhsStorageOrder, ConjugateLhs, RhsScalar,
223 ConjugateRhs>::run(rows, depth, lhs, lhsStride,
224 &rhs[static_cast<int>(RhsStorageOrder)
225 == static_cast<int>(ColMajor)
228 static_cast<int>(RhsStorageOrder)
229 == static_cast<int>(ColMajor)
232 &res[i * resStride], 1, alpha);
237 static void run(Index rows, Index cols, Index depth,
238 const LhsMapper& lhsMapper,
const RhsMapper& rhsMapper,
239 ResScalar* res, Index resStride,
const ResScalar& alpha,
240 level3_blocking<LhsScalar, RhsScalar>& blocking,
241 GemmParallelInfo<Index>* info = 0) {
242 const LhsScalar* lhs = lhsMapper.data();
243 const Index lhsStride = lhsMapper.stride();
244 const RhsScalar* rhs = rhsMapper.data();
245 const Index rhsStride = rhsMapper.stride();
247 run(rows, cols, depth, lhs, lhsStride, rhs, rhsStride, res, resStride,
248 alpha, blocking, info);
256 struct significant_decimals_default_impl<stan::math::var, false> {
260 return cast<double, int>(
261 ceil(-
log(std::numeric_limits<double>::epsilon()) /
log(10.0)));
270 struct scalar_product_traits<stan::math::var, double> {
279 struct scalar_product_traits<double, stan::math::var> {
287 template <
typename Index,
bool ConjugateLhs,
bool ConjugateRhs>
288 struct general_matrix_vector_product<Index, stan::math::var, ColMajor,
293 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
295 enum { LhsStorageOrder = ColMajor };
298 const LhsScalar* lhs, Index lhsStride,
299 const RhsScalar* rhs, Index rhsIncr,
302 for (Index i = 0; i <
rows; i++) {
305 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
307 : (&lhs[i * lhsStride]),
308 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
311 rhs, rhsIncr, cols));
315 template <
typename Index,
bool ConjugateLhs,
bool ConjugateRhs>
316 struct general_matrix_vector_product<Index, stan::math::var, RowMajor,
321 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
323 enum { LhsStorageOrder = RowMajor };
326 const LhsScalar* lhs, Index lhsStride,
327 const RhsScalar* rhs, Index rhsIncr,
329 const RhsScalar& alpha) {
330 for (Index i = 0; i <
rows; i++) {
333 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
335 : (&lhs[i * lhsStride]),
336 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
339 rhs, rhsIncr, cols));
343 template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
344 int RhsStorageOrder,
bool ConjugateRhs>
345 struct general_matrix_matrix_product<Index, stan::math::var, LhsStorageOrder,
347 RhsStorageOrder, ConjugateRhs, ColMajor> {
350 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
352 static void run(Index
rows, Index
cols, Index depth,
const LhsScalar* lhs,
353 Index lhsStride,
const RhsScalar* rhs, Index rhsStride,
355 level3_blocking<LhsScalar, RhsScalar>& ,
356 GemmParallelInfo<Index>* ) {
357 for (Index i = 0; i <
cols; i++) {
358 general_matrix_vector_product<
359 Index, LhsScalar, LhsStorageOrder, ConjugateLhs, RhsScalar,
360 ConjugateRhs>::run(rows, depth, lhs, lhsStride,
361 &rhs[(static_cast<int>(RhsStorageOrder)
362 == static_cast<int>(ColMajor))
365 (static_cast<int>(RhsStorageOrder)
366 == static_cast<int>(ColMajor))
369 &res[i * resStride], 1, alpha);
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
static int digits10()
Return the number of decimal digits that can be represented without change.
stan::math::var RhsScalar
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
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)
fvar< T > log(const fvar< T > &x)
The variable implementation base class.
static stan::math::var dummy_precision()
Return the precision for stan::math::var delegates to precision for douboe.
stan::math::var LhsScalar
stan::math::var NonInteger
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 > *)
Independent (input) and dependent (output) variables for gradients.
stan::math::var RhsScalar
(Expert) Numerical traits for algorithmic differentiation variables.
stan::math::var ReturnType
stan::math::var LhsScalar
stan::math::var LhsScalar
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
stan::math::var RhsScalar
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType ResScalar
fvar< T > ceil(const fvar< T > &x)
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)
stan::math::var ReturnType