Stan Math Library  2.11.0
reverse mode automatic differentiation
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>
7 #include <limits>
8 
9 namespace Eigen {
10 
15  template <>
16  struct NumTraits<stan::math::var> {
23 
30 
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() {
63  }
64 
71  inline static Real lowest() {
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> {
113  };
114 
119  template <>
120  struct scalar_product_traits<double, stan::math::var> {
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> {
133  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
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> {
162  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
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> {
192  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
static Real lowest()
Return standard library's lowest for double-precision floating point, -std::numeric_limitsmax...
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
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)
Definition: log.hpp:15
static Real dummy_precision()
Return dummy precision.
stan::math::var NonInteger
Non-integer valued variables.
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
static Real highest()
Return standard library's highest for double-precision floating point, std::numeric_limitsmax...
(Expert) Numerical traits for algorithmic differentiation variables.
stan::math::var Real
Real-valued variables.
static Real epsilon()
Return standard library's epsilon for double-precision floating point, std::numeric_limits::e...
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
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:21
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:95
stan::math::var Nested
Nested variables.
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 > *)
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)
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11

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