ROL
ROL_ElementwiseVector.hpp
Go to the documentation of this file.
1
2// @HEADER
3// *****************************************************************************
4// Rapid Optimization Library (ROL) Package
5//
6// Copyright 2014 NTESS and the ROL contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef ROL_ELEMENTWISE_VECTOR_H
12#define ROL_ELEMENTWISE_VECTOR_H
13
14#include "ROL_Vector.hpp"
15
27namespace ROL {
28
29template< class Real>
30class ElementwiseVector : public Vector<Real> {
31
32public:
33
34 virtual ~ElementwiseVector() {}
35
36 void plus( const Vector<Real> &x ) {
37 this->applyBinary(Elementwise::Plus<Real>(),x);
38 }
39
40 void scale( const Real alpha ) {
41 this->applyUnary(Elementwise::Scale<Real>(alpha));
42 }
43
44 virtual Real dot( const Vector<Real> &x ) const {
45 ROL::Ptr<Vector<Real> > y = this->clone();
46 y->set(*this);
47 y->applyBinary(Elementwise::Multiply<Real>(),x);
48 return y->reduce(Elementwise::ReductionSum<Real>());
49 }
50
51 virtual Real norm() const {
52 return std::sqrt(this->dot(*this));
53 }
54
55 void axpy( const Real alpha, const Vector<Real> &x ) {
56 this->applyBinary(Elementwise::Axpy<Real>(alpha),x);
57 }
58
59 void zero() {
60 this->applyUnary(Elementwise::Fill<Real>(Real(0)));
61 }
62
63 void set( const Vector<Real> &x ) {
64 this->applyBinary(Elementwise::Set<Real>(),x);
65 }
66
67 // MUST overload these three functions
68 virtual void applyUnary( const Elementwise::UnaryFunction<Real> &uf ) = 0;
69
70 virtual void applyBinary( const Elementwise::BinaryFunction<Real> &bf,
71 const Vector<Real> &x ) = 0;
72
73 virtual Real reduce( const Elementwise::ReductionOp<Real> &r ) const = 0;
74
75}; // class ElementwiseVector
76
77
78} // namespace ROL
79
80
81
82
83#endif // ROL_ELEMENTWISE_VECTOR_H
84
Intermediate abstract class which does not require users implements plus, set, scale,...
void scale(const Real alpha)
Compute where .
void set(const Vector< Real > &x)
Set where .
virtual Real norm() const
Returns where .
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &bf, const Vector< Real > &x)=0
virtual Real dot(const Vector< Real > &x) const
Compute where .
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &uf)=0
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const =0
void plus(const Vector< Real > &x)
Compute , where .
void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.