10 #ifndef SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
13 #ifdef HAVE_SACADO_TEUCHOSCORE
15 #define SACADO_FAD_GENERALFADTESTINGHELPERS_HPP
20 template <
typename T1,
typename T2>
21 typename std::enable_if<
28 template <
typename T1,
typename T2>
29 typename std::enable_if<
32 typename std::common_type< typename ScalarType<T1>::type,
typename ScalarType<T2>::type >::type
35 relErrFadImpl(
const T1& v1,
const T2& v2)
38 magnitudeType maxRelErr = relErrFadImpl(v1.val(), v2.val());
39 for (
int i=0;
i<v1.size(); ++
i) {
40 magnitudeType tmpRelErr = relErrFadImpl(v1.dx(
i), v2.dx(
i));
41 if (tmpRelErr >= maxRelErr)
42 maxRelErr = tmpRelErr;
50 template <
typename T1,
typename T2>
51 struct TestRelErr<
T1,
T2,
52 typename std::enable_if<Sacado::IsExpr<T1>::value ||
53 Sacado::IsExpr<T2>::value >::type >
57 typedef typename std::common_type<scalarType1,scalarType2>::type scalarType;
60 const std::string &v1_name,
62 const std::string &v2_name,
64 const std::string &maxRelErr_error_name,
65 const magnitudeType &maxRelErr_error,
66 const std::string &maxRelErr_warning_name,
67 const magnitudeType &maxRelErr_warning,
68 const Ptr<std::ostream> &out
75 const magnitudeType rel_err = Sacado::Fad::relErrFadImpl( v1, v2);
76 const bool success = ( !SMT::isnaninf(rel_err) && !SMT::isnaninf(maxRelErr_error)
77 && rel_err <= maxRelErr_error );
81 <<
"Check: rel_err(" << v1_name <<
", " << v2_name <<
")\n"
82 <<
" = rel_err(" << v1 <<
", " << v2 <<
") "
83 <<
"= " << rel_err << endl
84 <<
" <= " << maxRelErr_error_name
86 if( success && rel_err >= maxRelErr_warning ) {
88 <<
"Warning! rel_err(" << v1_name <<
", " << v2_name <<
")\n"
89 <<
" = rel_err(" << v1 <<
", " << v2 <<
") "
90 <<
"= " << rel_err << endl
91 <<
" >= " << maxRelErr_warning_name
92 <<
" = " << maxRelErr_warning <<
"!\n";
100 #define TEUCHOS_TEST_FLOATING_NOT_EQUALITY( v1, v2, tol, out, success ) \
102 const bool l_result = Teuchos::testRelErr( \
103 #v1, v1, #v2, v2, "tol", tol, "tol", tol, Teuchos::outArg(out) ); \
104 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)