ROL
ROL_ElementwiseVector.hpp
Go to the documentation of this file.
1 
2 // @HEADER
3 // ************************************************************************
4 //
5 // Rapid Optimization Library (ROL) Package
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact lead developers:
39 // Drew Kouri (dpkouri@sandia.gov) and
40 // Denis Ridzal (dridzal@sandia.gov)
41 //
42 // ************************************************************************
43 // @HEADER
44 
45 #ifndef ROL_ELEMENTWISE_VECTOR_H
46 #define ROL_ELEMENTWISE_VECTOR_H
47 
48 #include "ROL_Vector.hpp"
49 
61 namespace ROL {
62 
63 template< class Real>
64 class ElementwiseVector : public Vector<Real> {
65 
66 public:
67 
68  virtual ~ElementwiseVector() {}
69 
70  void plus( const Vector<Real> &x ) {
71  this->applyBinary(Elementwise::Plus<Real>(),x);
72  }
73 
74  void scale( const Real alpha ) {
75  this->applyUnary(Elementwise::Scale<Real>(alpha));
76  }
77 
78  virtual Real dot( const Vector<Real> &x ) const {
79  ROL::Ptr<Vector<Real> > y = this->clone();
80  y->set(*this);
81  y->applyBinary(Elementwise::Multiply<Real>(),x);
82  return y->reduce(Elementwise::ReductionSum<Real>());
83  }
84 
85  virtual Real norm() const {
86  return std::sqrt(this->dot(*this));
87  }
88 
89  void axpy( const Real alpha, const Vector<Real> &x ) {
90  this->applyBinary(Elementwise::Axpy<Real>(alpha),x);
91  }
92 
93  void zero() {
94  this->applyUnary(Elementwise::Fill<Real>(Real(0)));
95  }
96 
97  void set( const Vector<Real> &x ) {
98  this->applyBinary(Elementwise::Set<Real>(),x);
99  }
100 
101  // MUST overload these three functions
102  virtual void applyUnary( const Elementwise::UnaryFunction<Real> &uf ) = 0;
103 
104  virtual void applyBinary( const Elementwise::BinaryFunction<Real> &bf,
105  const Vector<Real> &x ) = 0;
106 
107  virtual Real reduce( const Elementwise::ReductionOp<Real> &r ) const = 0;
108 
109 }; // class ElementwiseVector
110 
111 
112 } // namespace ROL
113 
114 
115 
116 
117 #endif // ROL_ELEMENTWISE_VECTOR_H
118 
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const =0
virtual Real norm() const
Returns where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
virtual Real dot(const Vector< Real > &x) const
Compute where .
Intermediate abstract class which does not require users implements plus, set, scale, axpy, norm, dot, or zero if they implement the three elementwise functions: applyUnary, applyBinary, and reduce.
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &bf, const Vector< Real > &x)=0
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &uf)=0
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void scale(const Real alpha)
Compute where .
void set(const Vector< Real > &x)
Set where .
void plus(const Vector< Real > &x)
Compute , where .
void zero()
Set to zero vector.