52 #include "Teuchos_GlobalMPISession.hpp"
57 int main(
int argc,
char *argv[]) {
59 Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
61 int iprint = argc - 1;
63 std::ostream& outStream = (iprint > 0) ? std::cout : bhs;
67 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
75 ROL::Ptr<std::vector<ElementT> > x_ptr
76 = ROL::makePtr<std::vector<ElementT>>(
dim);
77 ROL::Ptr<std::vector<ElementT> > y_ptr
78 = ROL::makePtr<std::vector<ElementT>>(
dim);
79 ROL::Ptr<std::vector<ElementT> > W_ptr
80 = ROL::makePtr<std::vector<ElementT>>(
dim,
static_cast<ElementT>(2));
83 for (
int i = 0; i <
dim; i++) {
84 (*x_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
85 (*y_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
97 outStream <<
"\nAbsolute error between x.dot(y.dual()) and y.dot(x.dual()): "
98 << std::abs(xy-yx) <<
"\n";
99 outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
100 outStream <<
"y.dot(x.dual()): " << yx <<
"\n";
101 if ( std::abs(xy-yx) > errtol ) {
102 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
106 outStream <<
"\nAbsolute error between x.apply(y) and y.apply(x): "
107 << std::abs(axy-ayx) <<
"\n";
108 outStream <<
"x.apply(y): " << axy <<
"\n";
109 outStream <<
"y.apply(x): " << ayx <<
"\n";
110 if ( std::abs(axy-ayx) > errtol ) {
111 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
115 outStream <<
"\nAbsolute error between x.apply(y) and x.dot(y.dual()): "
116 << std::abs(axy-ayx) <<
"\n";
117 outStream <<
"x.apply(y): " << axy <<
"\n";
118 outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
119 if ( std::abs(axy-xy) > errtol ) {
120 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
127 outStream <<
"\nAbsolute error between sqrt(x.dot(x)) and x.norm(): "
128 << std::abs(xx-xnorm) <<
"\n";
129 outStream <<
"sqrt(x.dot(x)): " << xx <<
"\n";
130 outStream <<
"x.norm(): " << xnorm <<
"\n";
131 if ( std::abs(xx-xnorm) > errtol ) {
132 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
136 outStream <<
"\nAbsolute error between sqrt(y.dot(y)) and y.norm(): "
137 << std::abs(yy-ynorm) <<
"\n";
138 outStream <<
"sqrt(y.dot(y)): " << yy <<
"\n";
139 outStream <<
"y.norm(): " << ynorm <<
"\n";
140 if ( std::abs(yy-ynorm) > errtol ) {
141 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
146 ROL::Ptr<ROL::Vector<RealT> > z = x.
clone();
148 RealT znorm = z->norm();
149 outStream <<
"\nNorm of ROL::Vector z (clone of x): " << znorm <<
"\n";
150 if ( std::abs(xnorm - znorm) > errtol ) {
151 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
154 ROL::Ptr<ROL::Vector<RealT> > w = y.
clone();
157 RealT wnorm = w->norm();
158 outStream <<
"\nNorm of ROL::Vector w (clone of y): " << wnorm <<
"\n";
159 if ( std::abs(ynorm - wnorm) > errtol ) {
160 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
165 ROL::Ptr<std::vector<ElementT> > x1_ptr
166 = ROL::makePtr<std::vector<ElementT>>(
dim);
167 ROL::Ptr<std::vector<ElementT> > y1_ptr
168 = ROL::makePtr<std::vector<ElementT>>(
dim);
169 ROL::Ptr<std::vector<ElementT> > z1_ptr
170 = ROL::makePtr<std::vector<ElementT>>(
dim);
173 for (
int i = 0; i <
dim; i++) {
174 (*x1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
175 (*y1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
176 (*z1_ptr)[i] =
static_cast<ElementT>(rand())/static_cast<ElementT>(RAND_MAX);
184 std::vector<RealT> consistency = x1.
checkVector(y1, z1,
true, outStream);
186 if (checkvec.
norm() > std::sqrt(errtol)) {
192 catch (std::logic_error& err) {
193 outStream << err.what() <<
"\n";
198 std::cout <<
"End Result: TEST FAILED\n";
200 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 .