1 #ifndef STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP 2 #define STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP 19 struct NumTraits<
stan::math::var> : GenericNumTraits<stan::math::var> {
31 return NumTraits<double>::dummy_precision();
54 RequireInitialization = 0,
59 ReadCost = 2 * NumTraits<double>::ReadCost,
65 AddCost = NumTraits<double>::AddCost,
71 MulCost = NumTraits<double>::MulCost
80 return std::numeric_limits<double>::digits10;
86 #if EIGEN_VERSION_AT_LEAST(3, 3, 0) 92 struct scalar_product_traits<stan::math::var, double> {
101 struct scalar_product_traits<double, stan::math::var> {
116 template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
117 bool ConjugateRhs,
typename RhsMapper,
int Version>
118 struct general_matrix_vector_product<Index, stan::math::var, LhsMapper,
119 ColMajor, ConjugateLhs,
121 ConjugateRhs, Version> {
125 enum { LhsStorageOrder = ColMajor };
127 EIGEN_DONT_INLINE
static void 129 const LhsMapper& lhsMapper,
130 const RhsMapper& rhsMapper,
131 ResScalar* res, Index resIncr,
132 const ResScalar &alpha) {
133 const LhsScalar* lhs = lhsMapper.data();
134 const Index lhsStride = lhsMapper.stride();
135 const RhsScalar* rhs = rhsMapper.data();
136 const Index rhsIncr = rhsMapper.stride();
137 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
140 EIGEN_DONT_INLINE
static void 141 run(Index rows, Index cols,
142 const LhsScalar* lhs, Index lhsStride,
143 const RhsScalar* rhs, Index rhsIncr,
144 ResScalar* res, Index resIncr,
145 const ResScalar &alpha) {
148 for (Index i = 0; i <
rows; ++i) {
150 += var(
new gevv_vvv_vari(&alpha, &lhs[i], lhsStride,
151 rhs, rhsIncr, cols));
156 template <
typename Index,
typename LhsMapper,
bool ConjugateLhs,
157 bool ConjugateRhs,
typename RhsMapper,
int Version>
158 struct general_matrix_vector_product<Index, stan::math::var, LhsMapper,
159 RowMajor, ConjugateLhs,
161 ConjugateRhs, Version> {
165 enum { LhsStorageOrder = RowMajor };
167 EIGEN_DONT_INLINE
static void 169 const LhsMapper& lhsMapper,
170 const RhsMapper& rhsMapper,
171 ResScalar* res, Index resIncr,
172 const RhsScalar &alpha) {
173 const LhsScalar* lhs = lhsMapper.data();
174 const Index lhsStride = lhsMapper.stride();
175 const RhsScalar* rhs = rhsMapper.data();
176 const Index rhsIncr = rhsMapper.stride();
177 run(rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha);
180 EIGEN_DONT_INLINE
static void 181 run(Index rows, Index cols,
182 const LhsScalar* lhs, Index lhsStride,
183 const RhsScalar* rhs, Index rhsIncr,
184 ResScalar* res, Index resIncr,
185 const RhsScalar &alpha) {
186 for (Index i = 0; i <
rows; i++) {
191 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
192 ? (&lhs[i]) : (&lhs[i*lhsStride]),
193 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
195 rhs, rhsIncr, cols));
200 template <
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
201 int RhsStorageOrder,
bool ConjugateRhs>
202 struct general_matrix_matrix_product<Index, stan::math::var,
203 LhsStorageOrder, ConjugateLhs,
205 ConjugateRhs, ColMajor> {
210 typedef gebp_traits<RhsScalar, LhsScalar> Traits;
212 typedef const_blas_data_mapper<stan::math::var, Index, LhsStorageOrder>
214 typedef const_blas_data_mapper<stan::math::var, Index, RhsStorageOrder>
218 static void run(Index
rows, Index
cols, Index depth,
219 const LhsScalar* lhs, Index lhsStride,
220 const RhsScalar* rhs, Index rhsStride,
221 ResScalar* res, Index resStride,
222 const ResScalar &alpha,
223 level3_blocking<LhsScalar, RhsScalar>& ,
224 GemmParallelInfo<Index>* ) {
225 for (Index i = 0; i <
cols; i++) {
226 general_matrix_vector_product<Index, LhsScalar, LhsMapper,
228 ConjugateLhs, RhsScalar, RhsMapper,
230 ::run(rows, depth, lhs, lhsStride,
231 &rhs[static_cast<int>(RhsStorageOrder)
232 == static_cast<int>(ColMajor)
233 ? i * rhsStride : i],
234 static_cast<int>(RhsStorageOrder)
235 == static_cast<int>(ColMajor)
237 &res[i * resStride], 1, alpha);
242 static void run(Index rows, Index cols, Index depth,
243 const LhsMapper& lhsMapper,
244 const RhsMapper& rhsMapper,
245 ResScalar* res, Index resStride,
246 const ResScalar &alpha,
247 level3_blocking<LhsScalar, RhsScalar>& blocking,
248 GemmParallelInfo<Index>* info = 0) {
249 const LhsScalar* lhs = lhsMapper.data();
250 const Index lhsStride = lhsMapper.stride();
251 const RhsScalar* rhs = rhsMapper.data();
252 const Index rhsStride = rhsMapper.stride();
254 run(rows, cols, depth, lhs, lhsStride, rhs, rhsStride, res, resStride,
255 alpha, blocking, info);
263 struct significant_decimals_default_impl<stan::math::var, false> {
267 return cast<double, int>(
ceil(-
log(std::numeric_limits<double>
278 struct scalar_product_traits<stan::math::var, double> {
287 struct scalar_product_traits<double, stan::math::var> {
294 template<
typename Index,
bool ConjugateLhs,
bool ConjugateRhs>
295 struct general_matrix_vector_product<Index, stan::math::var, ColMajor,
300 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
302 enum { LhsStorageOrder = ColMajor };
304 EIGEN_DONT_INLINE
static void run(
306 const LhsScalar* lhs, Index lhsStride,
307 const RhsScalar* rhs, Index rhsIncr,
310 for (Index i = 0; i <
rows; i++) {
315 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
316 ?(&lhs[i]):(&lhs[i*lhsStride]),
317 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
319 rhs, rhsIncr, cols));
323 template<
typename Index,
bool ConjugateLhs,
bool ConjugateRhs>
324 struct general_matrix_vector_product<Index, stan::math::var,
325 RowMajor, ConjugateLhs,
329 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
331 enum { LhsStorageOrder = RowMajor };
333 EIGEN_DONT_INLINE
static void 335 const LhsScalar* lhs, Index lhsStride,
336 const RhsScalar* rhs, Index rhsIncr,
337 ResScalar* res, Index resIncr,
const RhsScalar &alpha) {
338 for (Index i = 0; i <
rows; i++) {
343 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
344 ? (&lhs[i]) : (&lhs[i*lhsStride]),
345 (static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
347 rhs, rhsIncr, cols));
351 template<
typename Index,
int LhsStorageOrder,
bool ConjugateLhs,
352 int RhsStorageOrder,
bool ConjugateRhs>
353 struct general_matrix_matrix_product<Index, stan::math::var,
354 LhsStorageOrder, ConjugateLhs,
356 ConjugateRhs, ColMajor> {
359 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
362 const LhsScalar* lhs, Index lhsStride,
363 const RhsScalar* rhs, Index rhsStride,
366 level3_blocking<LhsScalar, RhsScalar>& ,
367 GemmParallelInfo<Index>* ) {
368 for (Index i = 0; i <
cols; i++) {
369 general_matrix_vector_product<Index, LhsScalar, LhsStorageOrder,
370 ConjugateLhs, RhsScalar, ConjugateRhs>
371 ::run(rows, depth, lhs, lhsStride,
372 &rhs[(static_cast<int>(RhsStorageOrder)
373 == static_cast<int>(ColMajor))
374 ? (i*rhsStride) :(i) ],
375 (static_cast<int>(RhsStorageOrder)
376 == static_cast<int>(ColMajor)) ? (1) : (rhsStride),
377 &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)
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