56 #include "Teuchos_GlobalMPISession.hpp"
60 int main(
int argc,
char *argv[]) {
64 typedef std::vector<RealT> vector;
75 Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
77 int iprint = argc - 1;
79 ROL::Ptr<std::ostream> outStream;
81 outStream = ROL::makePtrFromRef(std::cout);
83 outStream = ROL::makePtrFromRef(bhs);
87 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
95 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim);
96 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(
dim);
97 ROL::Ptr<vector> w_ptr = ROL::makePtr<vector>(
dim,2.0);
99 ROL::Ptr<V> xs = ROL::makePtr<SV>( x_ptr );
100 ROL::Ptr<V> ys = ROL::makePtr<SV>( y_ptr );
107 ROL::Ptr<LinearOperator> W = ROL::makePtr<DiagonalOperator>(ws);
109 PrimalVector x(xs,W);
112 RealT xy = x.dot(y.dual());
113 RealT yx = y.dot(x.dual());
115 *outStream <<
"\nAbsolute error between x.dot(y.dual()) and y.dot(x.dual()): "
116 << std::abs(xy-yx) <<
"\n";
117 *outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
118 *outStream <<
"y.dot(x.dual()): " << yx <<
"\n";
119 if ( std::abs(xy-yx) > errtol ) {
120 *outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
124 RealT xx = std::sqrt(x.dot(x)), xnorm = x.norm();
125 RealT yy = std::sqrt(y.dot(y)), ynorm = y.norm();
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<vector> x1_ptr = ROL::makePtr<vector>(
dim);
166 ROL::Ptr<vector> y1_ptr = ROL::makePtr<vector>(
dim);
167 ROL::Ptr<vector> z1_ptr = ROL::makePtr<vector>(
dim);
169 ROL::Ptr<V> x1s = ROL::makePtr<SV>( x1_ptr );
170 ROL::Ptr<V> y1s = ROL::makePtr<SV>( y1_ptr );
171 ROL::Ptr<V> z1s = ROL::makePtr<SV>( z1_ptr );
178 PrimalVector x1(x1s,W);
179 PrimalVector y1(y1s,W);
180 PrimalVector z1(z1s,W);
182 std::vector<RealT> consistency = x1.checkVector(y1, z1,
true, *outStream);
184 if (checkvec.
norm() > std::sqrt(errtol)) {
190 catch (std::logic_error& err) {
191 *outStream << err.what() <<
"\n";
196 std::cout <<
"End Result: TEST FAILED\n";
198 std::cout <<
"End Result: TEST PASSED\n";
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides the interface to apply a diagonal operator which acts like elementwise multiplication when a...
Real norm() const
Returns where .
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides the interface to apply a linear operator.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])