48 #define ROL_UNUSED(x) (void) x
54 #include "ROL_Elementwise_Function.hpp"
56 #include "ROL_Ptr.hpp"
82 :
public std::enable_shared_from_this<Vector<Real>>
109 virtual void scale(
const Real alpha ) = 0;
119 virtual Real
dot(
const Vector &x )
const = 0;
128 virtual Real
norm()
const = 0;
139 virtual ROL::Ptr<Vector>
clone()
const = 0;
154 ROL::Ptr<Vector> ax = x.
clone();
168 this->
scale( (Real)0 );
182 virtual ROL::Ptr<Vector>
basis(
const int i )
const {
230 virtual void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
232 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
233 "The method applyUnary wass called, but not implemented" << std::endl);
239 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
240 "The method applyBinary wass called, but not implemented" << std::endl);
243 virtual Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
245 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
246 "The method reduce was called, but not implemented" << std::endl);
249 virtual void print( std::ostream &outStream )
const {
250 outStream <<
"The method print was called, but not implemented" << std::endl;
280 virtual void randomize(
const Real l = 0.0,
const Real u = 1.0 ) {
281 Elementwise::UniformlyRandom<Real> ur(l,u);
314 const bool printToStream =
true,
315 std::ostream & outStream = std::cout )
const {
321 std::vector<Real> vCheck;
325 ROL::Ptr<std::ostream> pStream;
327 pStream = ROL::makePtrFromRef(outStream);
329 pStream = ROL::makePtrFromRef(bhs);
334 oldFormatState.copyfmt(*pStream);
336 ROL::Ptr<Vector> v = this->
clone();
337 ROL::Ptr<Vector> vtmp = this->
clone();
338 ROL::Ptr<Vector> xtmp = x.
clone();
339 ROL::Ptr<Vector> ytmp = y.
clone();
341 *pStream <<
"\n" << std::setw(width) << std::left << std::setfill(
'*') <<
"********** Begin verification of linear algebra. " <<
"\n\n";
342 headerFormatState.copyfmt(*pStream);
345 v->set(*
this); xtmp->set(x); ytmp->set(y);
346 v->plus(x); xtmp->plus(*
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
347 *pStream << std::scientific << std::setprecision(12) << std::setfill(
'>');
348 *pStream << std::setw(width) << std::left <<
"Commutativity of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
351 v->set(*
this); xtmp->set(x); ytmp->set(y);
352 ytmp->plus(x); v->plus(*ytmp); xtmp->plus(*
this); xtmp->plus(y); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
353 *pStream << std::setw(width) << std::left <<
"Associativity of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
356 v->set(*
this); xtmp->set(x); ytmp->set(y);
357 v->zero(); v->plus(x); v->axpy(-one, x); vCheck.push_back(v->norm());
358 *pStream << std::setw(width) << std::left <<
"Identity element of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
361 v->set(*
this); xtmp->set(x); ytmp->set(y);
362 v->scale(-one); v->plus(*
this); vCheck.push_back(v->norm());
363 *pStream << std::setw(width) << std::left <<
"Inverse elements of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
366 v->set(*
this); xtmp->set(x); ytmp->set(y);
367 v->scale(one); v->axpy(-one, *
this); vCheck.push_back(v->norm());
368 *pStream << std::setw(width) << std::left <<
"Identity element of scalar multiplication. Consistency error: " <<
" " << vCheck.back() <<
"\n";
371 v->set(*
this); vtmp->set(*
this);
372 v->scale(b); v->scale(a); vtmp->scale(a*b); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
373 *pStream << std::setw(width) << std::left <<
"Consistency of scalar multiplication with field multiplication. Consistency error: " <<
" " << vCheck.back() <<
"\n";
376 v->set(*
this); vtmp->set(*
this);
377 v->scale(a+b); vtmp->scale(a); vtmp->axpy(b, *
this); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
378 *pStream << std::setw(width) << std::left <<
"Distributivity of scalar multiplication with respect to field addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
381 v->set(*
this); xtmp->set(x); ytmp->set(y);
382 v->plus(x); v->scale(a); xtmp->scale(a); xtmp->axpy(a, *
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
383 *pStream << std::setw(width) << std::left <<
"Distributivity of scalar multiplication with respect to vector addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
386 vCheck.push_back(std::abs(this->
dot(x) - x.
dot(*
this)));
387 *pStream << std::setw(width) << std::left <<
"Commutativity of dot (inner) product over the field of reals. Consistency error: " <<
" " << vCheck.back() <<
"\n";
391 xtmp->plus(y); vCheck.push_back(std::abs(this->
dot(*xtmp) - this->
dot(x) - this->
dot(y))/std::max({static_cast<Real>(std::abs(this->
dot(*xtmp))), static_cast<Real>(std::abs(this->
dot(x))), static_cast<Real>(std::abs(this->
dot(y))), one}));
392 *pStream << std::setw(width) << std::left <<
"Additivity of dot (inner) product. Consistency error: " <<
" " << vCheck.back() <<
"\n";
396 Real vnorm = v->norm();
399 vCheck.push_back(std::abs(v->norm() -
zero));
402 vCheck.push_back(std::abs(v->norm() - one));
404 *pStream << std::setw(width) << std::left <<
"Consistency of scalar multiplication and norm. Consistency error: " <<
" " << vCheck.back() <<
"\n";
408 xtmp = ROL::constPtrCast<Vector>(ROL::makePtrFromRef(this->
dual()));
409 ytmp = ROL::constPtrCast<Vector>(ROL::makePtrFromRef(xtmp->dual()));
410 v->axpy(-one, *ytmp); vCheck.push_back(v->norm());
411 *pStream << std::setw(width) << std::left <<
"Reflexivity. Consistency error: " <<
" " << vCheck.back() <<
"\n\n";
416 pStream->copyfmt(headerFormatState);
417 *pStream << std::setw(width) << std::left <<
"********** End verification of linear algebra. " <<
"\n\n";
420 pStream->copyfmt(oldFormatState);