31 #ifndef SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
34 #ifdef HAVE_SACADO_TEUCHOSCORE
36 #define SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
41 template <
typename T1,
typename T2>
42 typename std::enable_if<
49 template <
typename T1,
typename T2>
50 typename std::enable_if<
53 typename std::common_type< typename ScalarType<T1>::type,
typename ScalarType<T2>::type >::type
56 relErrFadImpl(
const T1& v1,
const T2& v2)
59 magnitudeType maxRelErr = relErrFadImpl(v1.val(), v2.val());
60 for (
int i=0;
i<v1.size(); ++
i) {
61 magnitudeType tmpRelErr = relErrFadImpl(v1.dx(
i), v2.dx(
i));
62 if (tmpRelErr >= maxRelErr)
63 maxRelErr = tmpRelErr;
71 template <
typename T1,
typename T2>
72 struct TestRelErr<
T1,
T2,
73 typename std::enable_if<Sacado::IsExpr<T1>::value ||
74 Sacado::IsExpr<T2>::value >::type >
78 typedef typename std::common_type<scalarType1,scalarType2>::type scalarType;
81 const std::string &v1_name,
83 const std::string &v2_name,
85 const std::string &maxRelErr_error_name,
86 const magnitudeType &maxRelErr_error,
87 const std::string &maxRelErr_warning_name,
88 const magnitudeType &maxRelErr_warning,
89 const Ptr<std::ostream> &out
96 const magnitudeType rel_err = Sacado::Fad::relErrFadImpl( v1, v2);
97 const bool success = ( !SMT::isnaninf(rel_err) && !SMT::isnaninf(maxRelErr_error)
98 && rel_err <= maxRelErr_error );
102 <<
"Check: rel_err(" << v1_name <<
", " << v2_name <<
")\n"
103 <<
" = rel_err(" << v1 <<
", " << v2 <<
") "
104 <<
"= " << rel_err << endl
105 <<
" <= " << maxRelErr_error_name
107 if( success && rel_err >= maxRelErr_warning ) {
109 <<
"Warning! rel_err(" << v1_name <<
", " << v2_name <<
")\n"
110 <<
" = rel_err(" << v1 <<
", " << v2 <<
") "
111 <<
"= " << rel_err << endl
112 <<
" >= " << maxRelErr_warning_name
113 <<
" = " << maxRelErr_warning <<
"!\n";
121 #define TEUCHOS_TEST_FLOATING_NOT_EQUALITY( v1, v2, tol, out, success ) \
123 const bool l_result = Teuchos::testRelErr( \
124 #v1, v1, #v2, v2, "tol", tol, "tol", tol, Teuchos::outArg(out) ); \
125 if (l_result) (success) = false; \
static bool eval(const std::string &v1_name, const T1 &v1, const std::string &v2_name, const T2 &v2, const std::string &maxRelErr_error_name, const magnitudeType &maxRelErr_error, const std::string &maxRelErr_warning_name, const magnitudeType &maxRelErr_warning, const Ptr< std::ostream > &out)
bool is_null(const std::shared_ptr< T > &p)
const std::string passfail(const bool result)
std::common_type< magType1, magType2 >::type magnitudeType
Teuchos::ScalarTraits< typename std::common_type< Scalar1, Scalar2 >::type >::magnitudeType relErr(const Scalar1 &s1, const Scalar2 &s2)