Stan Math Library  2.9.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>
6 #include <limits>
7 
8 namespace Eigen {
9 
14  template <>
15  struct NumTraits<stan::math::var> {
22 
29 
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() {
62  }
63 
70  inline static Real lowest() {
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> {
112  };
113 
118  template <>
119  struct scalar_product_traits<double, stan::math::var> {
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> {
132  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
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> {
161  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
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> {
191  typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
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
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–2015, Stan Development Team.