18 #include "Teuchos_GlobalMPISession.hpp"
23 int main(
int argc,
char *argv[]) {
25 Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
27 int iprint = argc - 1;
29 std::ostream& outStream = (iprint > 0) ? std::cout : bhs;
33 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
41 ROL::Ptr<std::vector<ElementT> > x_ptr
42 = ROL::makePtr<std::vector<ElementT>>(
dim);
43 ROL::Ptr<std::vector<ElementT> > y_ptr
44 = ROL::makePtr<std::vector<ElementT>>(
dim);
45 ROL::Ptr<std::vector<ElementT> > W_ptr
46 = ROL::makePtr<std::vector<ElementT>>(
dim,
static_cast<ElementT>(2));
49 for (
int i = 0; i <
dim; i++) {
50 (*x_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
51 (*y_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
63 outStream <<
"\nAbsolute error between x.dot(y.dual()) and y.dot(x.dual()): "
64 << std::abs(xy-yx) <<
"\n";
65 outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
66 outStream <<
"y.dot(x.dual()): " << yx <<
"\n";
67 if ( std::abs(xy-yx) > errtol ) {
68 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
72 outStream <<
"\nAbsolute error between x.apply(y) and y.apply(x): "
73 << std::abs(axy-ayx) <<
"\n";
74 outStream <<
"x.apply(y): " << axy <<
"\n";
75 outStream <<
"y.apply(x): " << ayx <<
"\n";
76 if ( std::abs(axy-ayx) > errtol ) {
77 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
81 outStream <<
"\nAbsolute error between x.apply(y) and x.dot(y.dual()): "
82 << std::abs(axy-ayx) <<
"\n";
83 outStream <<
"x.apply(y): " << axy <<
"\n";
84 outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
85 if ( std::abs(axy-xy) > errtol ) {
86 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
93 outStream <<
"\nAbsolute error between sqrt(x.dot(x)) and x.norm(): "
94 << std::abs(xx-xnorm) <<
"\n";
95 outStream <<
"sqrt(x.dot(x)): " << xx <<
"\n";
96 outStream <<
"x.norm(): " << xnorm <<
"\n";
97 if ( std::abs(xx-xnorm) > errtol ) {
98 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
102 outStream <<
"\nAbsolute error between sqrt(y.dot(y)) and y.norm(): "
103 << std::abs(yy-ynorm) <<
"\n";
104 outStream <<
"sqrt(y.dot(y)): " << yy <<
"\n";
105 outStream <<
"y.norm(): " << ynorm <<
"\n";
106 if ( std::abs(yy-ynorm) > errtol ) {
107 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
112 ROL::Ptr<ROL::Vector<RealT> > z = x.
clone();
114 RealT znorm = z->norm();
115 outStream <<
"\nNorm of ROL::Vector z (clone of x): " << znorm <<
"\n";
116 if ( std::abs(xnorm - znorm) > errtol ) {
117 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
120 ROL::Ptr<ROL::Vector<RealT> > w = y.
clone();
123 RealT wnorm = w->norm();
124 outStream <<
"\nNorm of ROL::Vector w (clone of y): " << wnorm <<
"\n";
125 if ( std::abs(ynorm - wnorm) > errtol ) {
126 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
131 ROL::Ptr<std::vector<ElementT> > x1_ptr
132 = ROL::makePtr<std::vector<ElementT>>(
dim);
133 ROL::Ptr<std::vector<ElementT> > y1_ptr
134 = ROL::makePtr<std::vector<ElementT>>(
dim);
135 ROL::Ptr<std::vector<ElementT> > z1_ptr
136 = ROL::makePtr<std::vector<ElementT>>(
dim);
139 for (
int i = 0; i <
dim; i++) {
140 (*x1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
141 (*y1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
142 (*z1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
150 std::vector<RealT> consistency = x1.
checkVector(y1, z1,
true, outStream);
152 if (checkvec.
norm() > std::sqrt(errtol)) {
158 catch (std::logic_error& err) {
159 outStream << err.what() <<
"\n";
164 std::cout <<
"End Result: TEST FAILED\n";
166 std::cout <<
"End Result: TEST PASSED\n";
Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
virtual std::vector< Real > checkVector(const Vector< Real > &x, const Vector< Real > &y, const bool printToStream=true, std::ostream &outStream=std::cout) const
Verify vector-space methods.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Real dot(const Vector< Real > &x) const
Compute where .
Real dot(const Vector< Real > &x) const
Compute where .
Real norm() const
Returns where .
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
const Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .