30 #ifndef SACADO_TAY_SCALARTRAITSIMP_HPP 31 #define SACADO_TAY_SCALARTRAITSIMP_HPP 35 #ifdef HAVE_SACADO_TEUCHOSCORE 37 #include "Teuchos_ScalarTraits.hpp" 38 #include "Teuchos_TestForException.hpp" 46 template <
typename TayType>
47 struct ScalarTraitsImp {
50 typedef typename mpl::apply<TayType,typename Teuchos::ScalarTraits<ValueT>::magnitudeType>::type magnitudeType;
51 typedef typename mpl::apply<TayType,typename Teuchos::ScalarTraits<ValueT>::halfPrecision>::type halfPrecision;
52 typedef typename mpl::apply<TayType,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;
56 static const bool isComparable =
57 Teuchos::ScalarTraits<ValueT>::isComparable;
58 static const bool hasMachineParameters =
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() {
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();
90 static magnitudeType magnitude(
const TayType&
a) {
92 TEUCHOS_SCALAR_TRAITS_NAN_INF_ERR(
93 a,
"Error, the input value to magnitude(...) a = " <<
a <<
95 TEUCHOS_TEST_FOR_EXCEPTION(is_tay_real(
a) ==
false, std::runtime_error,
96 "Complex magnitude is not a differentiable " 97 "function of complex inputs.");
100 magnitudeType b(
a.degree(),
101 Teuchos::ScalarTraits<ValueT>::magnitude(
a.val()));
102 if (Teuchos::ScalarTraits<ValueT>::real(
a.val()) >= 0)
103 for (
int i=1;
i<=
a.degree();
i++)
104 b.fastAccessCoeff(
i) =
105 Teuchos::ScalarTraits<ValueT>::magnitude(
a.fastAccessCoeff(
i));
107 for (
int i=1;
i<=
a.degree();
i++)
108 b.fastAccessCoeff(
i) =
109 -Teuchos::ScalarTraits<ValueT>::magnitude(
a.fastAccessCoeff(
i));
112 static ValueT zero() {
115 static ValueT one() {
120 static TayType conjugate(
const TayType&
x) {
122 TEUCHOS_TEST_FOR_EXCEPTION(is_tay_real(
x) ==
false, std::runtime_error,
123 "Complex conjugate is not a differentiable " 124 "function of complex inputs.");
128 y.val() = Teuchos::ScalarTraits<ValueT>::conjugate(
x.val());
133 static TayType real(
const TayType&
x) {
135 TEUCHOS_TEST_FOR_EXCEPTION(is_tay_real(
x) ==
false, std::runtime_error,
136 "Real component is not a differentiable " 137 "function of complex inputs.");
141 y.val() = Teuchos::ScalarTraits<ValueT>::real(
x.val());
146 static TayType imag(
const TayType&
x) {
148 TEUCHOS_TEST_FOR_EXCEPTION(is_tay_real(
x) ==
false, std::runtime_error,
149 "Imaginary component is not a differentiable " 150 "function of complex inputs.");
152 return TayType(Teuchos::ScalarTraits<ValueT>::imag(
x.val()));
155 static ValueT nan() {
156 return Teuchos::ScalarTraits<ValueT>::nan();
158 static bool isnaninf(
const TayType&
x) {
159 for (
int i=0;
i<=
x.degree();
i++)
160 if (Teuchos::ScalarTraits<ValueT>::isnaninf(
x.fastAccessCoeff(
i)))
164 static void seedrandom(
unsigned int s) {
165 Teuchos::ScalarTraits<ValueT>::seedrandom(s);
167 static ValueT random() {
168 return Teuchos::ScalarTraits<ValueT>::random();
170 static std::string name() {
173 static TayType squareroot(
const TayType&
x) {
175 TEUCHOS_SCALAR_TRAITS_NAN_INF_ERR(
176 x,
"Error, the input value to squareroot(...) a = " <<
x <<
177 " can not be NaN!" );
181 static TayType
pow(
const TayType&
x,
const TayType&
y) {
186 static bool is_complex_real(
const ValueT&
x) {
188 Teuchos::ScalarTraits<ValueT>::magnitude(
x-Teuchos::ScalarTraits<ValueT>::real(
x)) == 0;
192 static bool is_tay_real(
const TayType&
x) {
195 if (Teuchos::ScalarTraits<ValueT>::isComplex) {
196 for (
int i=0;
i<=
x.degree();
i++)
197 if (!is_complex_real(
x.fastAccessCoeff(
i)))
209 #endif // HAVE_SACADO_TEUCHOSCORE 211 #endif // SACADO_FAD_SCALARTRAITSIMP_HPP static std::string eval()
PowExprType< Expr< T1 >, Expr< T2 > >::expr_type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
Sacado::Random< double > rnd
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)