All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
Eigen_NumTraits.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP
#define STAN_MATH_REV_MAT_FUN_EIGEN_NUMTRAITS_HPP
#include <stan/math/rev/core.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <limits>
namespace Eigen {
template <>
struct NumTraits<stan::math::var> {
typedef stan::math::var Real;
typedef stan::math::var NonInteger;
typedef stan::math::var Nested;
inline static Real epsilon() {
return std::numeric_limits<double>::epsilon();
}
inline static Real dummy_precision() {
return 1e-12; // copied from NumTraits.h values for double
}
inline static Real highest() {
return std::numeric_limits<double>::max();
}
inline static Real lowest() {
return -std::numeric_limits<double>::max();
}
enum {
IsInteger = 0,
IsSigned = 1,
IsComplex = 0,
RequireInitialization = 0,
ReadCost = 1,
AddCost = 1,
MulCost = 1,
HasFloatingPoint = 1
};
};
namespace internal {
template<>
struct significant_decimals_default_impl<stan::math::var, false> {
static inline int run() {
using std::ceil;
using std::log;
return cast<double, int>(ceil(-log(std::numeric_limits<double>
::epsilon())
/ log(10.0)));
}
};
template <>
struct scalar_product_traits<stan::math::var, double> {
typedef stan::math::var ReturnType;
};
template <>
struct scalar_product_traits<double, stan::math::var> {
typedef stan::math::var ReturnType;
};
template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
struct general_matrix_vector_product<Index, stan::math::var, ColMajor,
ConjugateLhs, stan::math::var,
ConjugateRhs> {
typedef stan::math::var LhsScalar;
typedef stan::math::var RhsScalar;
typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
ResScalar;
enum { LhsStorageOrder = ColMajor };
EIGEN_DONT_INLINE static void run(
Index rows, Index cols,
const LhsScalar* lhs, Index lhsStride,
const RhsScalar* rhs, Index rhsIncr,
ResScalar* res, Index resIncr,
const ResScalar &alpha) {
for (Index i = 0; i < rows; i++) {
res[i*resIncr]
+= stan::math::var
(new stan::math::gevv_vvv_vari
(&alpha,
(static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
?(&lhs[i]):(&lhs[i*lhsStride]),
(static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
?(lhsStride):(1),
rhs, rhsIncr, cols));
}
}
};
template<typename Index, bool ConjugateLhs, bool ConjugateRhs>
struct general_matrix_vector_product<Index, stan::math::var,
RowMajor, ConjugateLhs,
stan::math::var, ConjugateRhs> {
typedef stan::math::var LhsScalar;
typedef stan::math::var RhsScalar;
typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
ResScalar;
enum { LhsStorageOrder = RowMajor };
EIGEN_DONT_INLINE static void
run(Index rows, Index cols,
const LhsScalar* lhs, Index lhsStride,
const RhsScalar* rhs, Index rhsIncr,
ResScalar* res, Index resIncr, const RhsScalar &alpha) {
for (Index i = 0; i < rows; i++) {
res[i*resIncr]
+= stan::math::var
(new stan::math::gevv_vvv_vari
(&alpha,
(static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
? (&lhs[i]) : (&lhs[i*lhsStride]),
(static_cast<int>(LhsStorageOrder) == static_cast<int>(ColMajor))
? (lhsStride) : (1),
rhs, rhsIncr, cols));
}
}
};
template<typename Index, int LhsStorageOrder, bool ConjugateLhs,
int RhsStorageOrder, bool ConjugateRhs>
struct general_matrix_matrix_product<Index, stan::math::var,
LhsStorageOrder, ConjugateLhs,
stan::math::var, RhsStorageOrder,
ConjugateRhs, ColMajor> {
typedef stan::math::var LhsScalar;
typedef stan::math::var RhsScalar;
typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType
ResScalar;
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>& /* blocking */,
GemmParallelInfo<Index>* /* info = 0 */) {
for (Index i = 0; i < cols; i++) {
general_matrix_vector_product<Index, LhsScalar, LhsStorageOrder,
ConjugateLhs, RhsScalar, ConjugateRhs>
::run(rows, depth, _lhs, lhsStride,
&_rhs[(static_cast<int>(RhsStorageOrder)
== static_cast<int>(ColMajor))
? (i*rhsStride) :(i) ],
(static_cast<int>(RhsStorageOrder)
== static_cast<int>(ColMajor)) ? (1) : (rhsStride),
&res[i*resStride], 1, alpha);
}
}
};
}
}
#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
stan::math::rows
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
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
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
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
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.