30#ifndef SACADO_FAD_SCALARTRAITSIMP_HPP
31#define SACADO_FAD_SCALARTRAITSIMP_HPP
35#ifdef HAVE_SACADO_TEUCHOSCORE
37#include "Teuchos_ScalarTraits.hpp"
38#include "Teuchos_TestForException.hpp"
46 template <
typename FadType>
47 struct ScalarTraitsImp {
50 typedef typename mpl::apply<FadType,typename Teuchos::ScalarTraits<ValueT>::magnitudeType>::type
magnitudeType;
51 typedef typename mpl::apply<FadType,typename Teuchos::ScalarTraits<ValueT>::halfPrecision>::type
halfPrecision;
52 typedef typename mpl::apply<FadType,typename Teuchos::ScalarTraits<ValueT>::doublePrecision>::type
doublePrecision;
54 static const bool isComplex = Teuchos::ScalarTraits<ValueT>::isComplex;
55 static const bool isOrdinal = Teuchos::ScalarTraits<ValueT>::isOrdinal;
57 Teuchos::ScalarTraits<ValueT>::isComparable;
59 Teuchos::ScalarTraits<ValueT>::hasMachineParameters;
60 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
eps() {
61 return Teuchos::ScalarTraits<ValueT>::eps();
63 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
sfmin() {
64 return Teuchos::ScalarTraits<ValueT>::sfmin();
66 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
base() {
67 return Teuchos::ScalarTraits<ValueT>::base();
69 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
prec() {
70 return Teuchos::ScalarTraits<ValueT>::prec();
72 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType t() {
73 return Teuchos::ScalarTraits<ValueT>::t();
75 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
rnd() {
76 return Teuchos::ScalarTraits<ValueT>::rnd();
78 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
emin() {
79 return Teuchos::ScalarTraits<ValueT>::emin();
81 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
rmin() {
82 return Teuchos::ScalarTraits<ValueT>::rmin();
84 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
emax() {
85 return Teuchos::ScalarTraits<ValueT>::emax();
87 static typename Teuchos::ScalarTraits<ValueT>::magnitudeType
rmax() {
88 return Teuchos::ScalarTraits<ValueT>::rmax();
93 a,
"Error, the input value to magnitude(...) a = " <<
a <<
96 "Complex magnitude is not a differentiable "
97 "function of complex inputs.");
101 Teuchos::ScalarTraits<ValueT>::magnitude(
a.val()));
102 if (Teuchos::ScalarTraits<ValueT>::real(
a.val()) >= 0)
103 for (
int i=0;
i<
a.size();
i++)
105 Teuchos::ScalarTraits<ValueT>::magnitude(
a.fastAccessDx(
i));
107 for (
int i=0;
i<
a.size();
i++)
109 -Teuchos::ScalarTraits<ValueT>::magnitude(
a.fastAccessDx(
i));
123 "Complex conjugate is not a differentiable "
124 "function of complex inputs.");
127 y.val() = Teuchos::ScalarTraits<ValueT>::conjugate(
x.val());
135 "Real component is not a differentiable "
136 "function of complex inputs.");
139 y.val() = Teuchos::ScalarTraits<ValueT>::real(
x.val());
147 "Imaginary component is not a differentiable "
148 "function of complex inputs.");
150 return FadType(Teuchos::ScalarTraits<ValueT>::imag(
x.val()));
154 return Teuchos::ScalarTraits<ValueT>::nan();
157 if (Teuchos::ScalarTraits<ValueT>::isnaninf(
x.val()))
159 for (
int i=0;
i<
x.size();
i++)
160 if (Teuchos::ScalarTraits<ValueT>::isnaninf(
x.dx(
i)))
165 Teuchos::ScalarTraits<ValueT>::seedrandom(s);
168 return Teuchos::ScalarTraits<ValueT>::random();
170 static std::string name() {
176 x,
"Error, the input value to squareroot(...) a = " <<
x <<
177 " can not be NaN!" );
182 return std::pow(
x,
y);
188 Teuchos::ScalarTraits<ValueT>::magnitude(
x-Teuchos::ScalarTraits<ValueT>::real(
x)) == 0;
195 if (Teuchos::ScalarTraits<ValueT>::isComplex) {
198 for (
int i=0;
i<
x.size();
i++)
Sacado::Random< double > rnd
Sacado::Fad::DFad< double > FadType
BLAS(bool use_default_impl=true, bool use_dynamic=true, OrdinalType static_workspace_size=0)
Default constructor.
SACADO_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
static std::string eval()