34 template<
class OrdinalType,
class ScalarType>
37 typedef ScalarType scalar_type;
39 typedef MagnitudeType magnitude_type;
49 MagnitudeType trigErrorBound_;
55 MagnitudeType norm2 (
const ScalarType a,
const ScalarType& b)
62 const ScalarType a_scaled = a / scale;
63 const ScalarType b_scaled = b / scale;
77 static MagnitudeType trigErrorBound ()
85 return 2 * (4*u) / (1 - 4*u);
92 GivensTester (std::ostream& out) :
93 out_ (out), trigErrorBound_ (trigErrorBound())
97 bool compare (ScalarType a, ScalarType b)
103 out_ <<
"Comparing Givens rotations for [a; b] = ["
104 << a <<
"; " << b <<
"]" << endl;
106 generic_blas_type genericBlas;
107 library_blas_type libraryBlas;
110 ScalarType a_generic = a;
111 ScalarType b_generic = b;
112 MagnitudeType c_generic;
113 ScalarType s_generic;
114 genericBlas.
ROTG (&a_generic, &b_generic, &c_generic, &s_generic);
116 ScalarType a_library = a;
117 ScalarType b_library = b;
118 MagnitudeType c_library;
119 ScalarType s_library;
120 libraryBlas.ROTG (&a_library, &b_library, &c_library, &s_library);
122 out_ <<
"-- DefaultBLASImpl results: a,b,c,s = "
123 << a_generic <<
", " << b_generic <<
", "
124 << c_generic <<
", " << s_generic << endl;
125 out_ <<
"-- (Library) BLAS results: a,b,c,s = "
126 << a_library <<
", " << b_library <<
", "
127 << c_library <<
", " << s_library << endl;
132 out_ <<
"-- |c_generic - c_library| = "
136 out_ <<
"---- Difference exceeded error bound " << trigErrorBound_ << endl;
140 out_ <<
"-- |s_generic - s_library| = "
144 out_ <<
"---- Difference exceeded error bound " << trigErrorBound_ << endl;
152 const MagnitudeType inputNorm = norm2 (a, b);
153 const MagnitudeType outputDiffNorm =
154 norm2 (a_generic - a_library, b_generic - b_library);
156 out_ <<
"-- ||[a; b]||_2 = " << inputNorm << endl;
157 out_ <<
"-- ||[a_generic - a_library; b_generic - b_library]||_2 = "
158 << outputDiffNorm << endl;
167 const MagnitudeType fwdErrorBound =
170 if (outputDiffNorm > fwdErrorBound * inputNorm) {
172 out_ <<
"---- Forward error exceeded relative error bound "
173 << fwdErrorBound << endl;
193 success = success && compare (one, zero);
194 success = success && compare (zero, one);
195 success = success && compare (-one, zero);
196 success = success && compare (zero, -one);
200 const ScalarType incr = one / as<ScalarType> (10);
201 for (
int k = -30; k < 30; ++k) {
202 const ScalarType a = as<ScalarType> (k) * incr;
203 const ScalarType b = one - as<ScalarType> (k) * incr;
204 success = success && compare (a, b);
243 const int myRank = mpiSession.
getRank();
245 std::ostream& out = (myRank == 0) ? std::cout : blackHole;
248 CommandLineProcessor cmdp(
false,
true);
249 cmdp.setOption (
"verbose",
"quiet", &verbose,
"Print messages and results.");
253 const CommandLineProcessor::EParseCommandLineReturn parseResult =
254 cmdp.parse (argc,argv);
257 if (parseResult == CommandLineProcessor::PARSE_HELP_PRINTED) {
258 out <<
"End Result: TEST PASSED" << endl;
262 std::invalid_argument,
263 "Failed to parse command-line arguments");
267 GivensTester<int, double> tester (verbose ? out : blackHole);
268 const bool success = tester.test ();
271 out <<
"End Result: TEST PASSED" << endl;
274 out <<
"End Result: TEST FAILED" << endl;
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
T magnitudeType
Mandatory typedef for result of magnitude.
Templated interface class to BLAS routines.
static magnitudeType eps()
Returns relative machine precision.
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
basic_ostream<> subclass that does nothing but discard output.
static magnitudeType base()
Returns the base of the machine.
Initialize, finalize, and query the global MPI session.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
int main(int argc, char *argv[])
static magnitudeType magnitude(ScalarTypea)
Returns the magnitudeType of the scalar type a.
Default implementation for BLAS routines.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
void ROTG(ScalarType *da, ScalarType *db, rotg_c_type *c, ScalarType *s) const
Computes a Givens plane rotation.
Basic command line parser for input from (argc,argv[])
static T zero()
Returns representation of zero for this scalar type.
Definition of Teuchos::as, for conversions between types.
static T one()
Returns representation of one for this scalar type.
Class that helps parse command line input arguments from (argc,argv[]) and set options.