22 #include "Teuchos_GlobalMPISession.hpp"
26 int main(
int argc,
char *argv[]) {
30 typedef std::vector<RealT> vector;
41 Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
43 int iprint = argc - 1;
45 ROL::Ptr<std::ostream> outStream;
47 outStream = ROL::makePtrFromRef(std::cout);
49 outStream = ROL::makePtrFromRef(bhs);
53 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
61 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim);
62 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(
dim);
63 ROL::Ptr<vector> w_ptr = ROL::makePtr<vector>(
dim,2.0);
65 ROL::Ptr<V> xs = ROL::makePtr<SV>( x_ptr );
66 ROL::Ptr<V> ys = ROL::makePtr<SV>( y_ptr );
73 ROL::Ptr<LinearOperator> W = ROL::makePtr<DiagonalOperator>(ws);
78 RealT xy = x.dot(y.dual());
79 RealT yx = y.dot(x.dual());
81 *outStream <<
"\nAbsolute error between x.dot(y.dual()) and y.dot(x.dual()): "
82 << std::abs(xy-yx) <<
"\n";
83 *outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
84 *outStream <<
"y.dot(x.dual()): " << yx <<
"\n";
85 if ( std::abs(xy-yx) > errtol ) {
86 *outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
90 RealT xx = std::sqrt(x.dot(x)), xnorm = x.norm();
91 RealT yy = std::sqrt(y.dot(y)), ynorm = y.norm();
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<vector> x1_ptr = ROL::makePtr<vector>(
dim);
132 ROL::Ptr<vector> y1_ptr = ROL::makePtr<vector>(
dim);
133 ROL::Ptr<vector> z1_ptr = ROL::makePtr<vector>(
dim);
135 ROL::Ptr<V> x1s = ROL::makePtr<SV>( x1_ptr );
136 ROL::Ptr<V> y1s = ROL::makePtr<SV>( y1_ptr );
137 ROL::Ptr<V> z1s = ROL::makePtr<SV>( z1_ptr );
144 PrimalVector x1(x1s,W);
145 PrimalVector y1(y1s,W);
146 PrimalVector z1(z1s,W);
148 std::vector<RealT> consistency = x1.checkVector(y1, z1,
true, *outStream);
150 if (checkvec.
norm() > std::sqrt(errtol)) {
156 catch (std::logic_error& err) {
157 *outStream << err.what() <<
"\n";
162 std::cout <<
"End Result: TEST FAILED\n";
164 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[])