55 #include "Teuchos_oblackholestream.hpp" 56 #include "Teuchos_GlobalMPISession.hpp" 60 int main(
int argc,
char *argv[]) {
62 using Teuchos::RCP;
using Teuchos::rcp;
64 typedef std::vector<RealT> vector;
75 Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
77 int iprint = argc - 1;
78 Teuchos::oblackholestream bhs;
79 std::ostream& outStream = (iprint > 0) ? std::cout : bhs;
83 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
91 RCP<vector> x_rcp = rcp(
new vector(dim) );
92 RCP<vector> y_rcp = rcp(
new vector(dim) );
93 RCP<vector> w_rcp = rcp(
new vector(dim,2.0) );
95 RCP<V> xs = rcp(
new SV( x_rcp ) );
96 RCP<V> ys = rcp(
new SV( y_rcp ) );
103 RCP<LinearOperator> W = rcp(
new DiagonalOperator(ws) );
105 PrimalVector x(xs,W);
108 RealT xy = x.dot(y.dual());
109 RealT yx = y.dot(x.dual());
111 outStream <<
"\nAbsolute error between x.dot(y.dual()) and y.dot(x.dual()): " 112 << std::abs(xy-yx) <<
"\n";
113 outStream <<
"x.dot(y.dual()): " << xy <<
"\n";
114 outStream <<
"y.dot(x.dual()): " << yx <<
"\n";
115 if ( std::abs(xy-yx) > errtol ) {
116 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
120 RealT xx = std::sqrt(x.dot(x)), xnorm = x.norm();
121 RealT yy = std::sqrt(y.dot(y)), ynorm = y.norm();
123 outStream <<
"\nAbsolute error between sqrt(x.dot(x)) and x.norm(): " 124 << std::abs(xx-xnorm) <<
"\n";
125 outStream <<
"sqrt(x.dot(x)): " << xx <<
"\n";
126 outStream <<
"x.norm(): " << xnorm <<
"\n";
127 if ( std::abs(xx-xnorm) > errtol ) {
128 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
132 outStream <<
"\nAbsolute error between sqrt(y.dot(y)) and y.norm(): " 133 << std::abs(yy-ynorm) <<
"\n";
134 outStream <<
"sqrt(y.dot(y)): " << yy <<
"\n";
135 outStream <<
"y.norm(): " << ynorm <<
"\n";
136 if ( std::abs(yy-ynorm) > errtol ) {
137 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
142 Teuchos::RCP<ROL::Vector<RealT> > z = x.clone();
144 RealT znorm = z->norm();
145 outStream <<
"\nNorm of ROL::Vector z (clone of x): " << znorm <<
"\n";
146 if ( std::abs(xnorm - znorm) > errtol ) {
147 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
150 Teuchos::RCP<ROL::Vector<RealT> > w = y.clone();
153 RealT wnorm = w->norm();
154 outStream <<
"\nNorm of ROL::Vector w (clone of y): " << wnorm <<
"\n";
155 if ( std::abs(ynorm - wnorm) > errtol ) {
156 outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
161 RCP<vector> x1_rcp = rcp(
new vector(dim) );
162 RCP<vector> y1_rcp = rcp(
new vector(dim) );
163 RCP<vector> z1_rcp = rcp(
new vector(dim) );
165 RCP<V> x1s = rcp(
new SV( x1_rcp ) );
166 RCP<V> y1s = rcp(
new SV( y1_rcp ) );
167 RCP<V> z1s = rcp(
new SV( z1_rcp ) );
174 PrimalVector x1(x1s,W);
175 PrimalVector y1(y1s,W);
176 PrimalVector z1(z1s,W);
178 std::vector<RealT> consistency = x1.checkVector(y1, z1,
true, outStream);
180 if (checkvec.
norm() > std::sqrt(errtol)) {
186 catch (std::logic_error err) {
187 outStream << err.what() <<
"\n";
192 std::cout <<
"End Result: TEST FAILED\n";
194 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.
Provides the interface to apply a diagonal operator which acts like elementwise multiplication when a...
Provides the std::vector implementation of the ROL::Vector interface.
Provides the interface to apply a linear operator.
int main(int argc, char *argv[])
Real norm() const
Returns where .