ROL
ROL_WrappedVector.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #pragma once
11 #ifndef ROL_WRAPPEDVECTOR_HPP
12 #define ROL_WRAPPEDVECTOR_HPP
13 
14 
15 namespace ROL {
16 
31 template<typename Real>
32 class PrimalScaledVector {
33 
34  using V = Vector<Real>;
37 
38 private:
39 
40  mutable Ptr<V> vec_;
41 
42 
43 public:
44 
45  WrappedVector( const Ptr<V>& vec ) : vec_(vec) {}
46 
47  virtual ~WrappedVector() {}
48 
49  virtual void plus( const V& x ) override { vec_->plus(x); }
50  virtual void scale( const Real alpha ) override { vec_->scale(alpha); }
51 
52  virtual Real dot( const V& x ) const override { return vec_->dot(x); }
53 
54  virtual Real norm() const override { return std::sqrt( this->dot(*this) ); }
55 
56  virtual Ptr<V> clone() const override {
57  return makePtr<WrappedVector>( vec_->clone() );
58  }
59 
60  virtual void axpy( const Real alpha, const V& x ) override {
61  vec_->axpy( alpha, x );
62  }
63 
64  virtual Ptr<V> basis( const int i ) const override {
65  return makePtr<VPrim>( vec_->basis(i) );
66  }
67 
68  virtual int dimension() const override { return vec_->dimension(); }
69 
70  virtual void set( const V& x ) override { vec_->set(x); }
71 
72  virtual void const V& dual() const override { return vec_->dual(); }
73 
74  virtual Real apply( const V& x ) const override { return vec_->apply(x); }
75 
76  virtual void applyUnary( const Elementwise::UnaryFunction<Real>& f ) override {
77  vec_->applyUnary(f);
78  }
79 
80  virtual void applyBinary( const Elementwise::BinaryFunction<Real>& f,
81  const V& x ) override {
82  vec_->applyBinary(f,x);
83  }
84 
85  virtual Real reduce( const Elementwise::ReductionOp<Real>& r ) const override {
86  return vec_->reduce(r);
87  }
88 
89  virtual void setScalar( const Real C ) override { vec_->setScalar(C); }
90 
91  virtual void randomize( const Real l=0.0, const Real u=1.0 ) override {
92  vec_->randomize(l,u);
93  }
94 
95  virtual void print( std::ostream& os ) override { vec_->print(os); }
96 
97  const Ptr<V>& getVector() { return vec_; }
98  const Ptr<const V>& getVector() const { return vec_; }
99 
100  virtual void setVector( const Ptr<const V>& vec ) const { vec_ = vec; }
101 
102 }; // class PrimalScaledVector
103 
104 
105 
106 
107 } // namespace ROL
108 
109 
110 #endif
virtual void print(std::ostream &os) override
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x) override
virtual int dimension() const override
virtual void scale(const Real alpha) override
virtual void set(const V &x) override
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
const Ptr< V > & getVector()
virtual void axpy(const Real alpha, const V &x) override
Provides the implementation of the ROL::Vector interface that handles scalings in the inner product...
WrappedVector(const Ptr< V > &vec)
Provides the implementation of the ROL::Vector interface that handles scalings in the inner product...
virtual void plus(const V &x) override
virtual Ptr< V > clone() const override
virtual Real dot(const V &x) const override
virtual void setVector(const Ptr< const V > &vec) const
virtual Ptr< V > basis(const int i) const override
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f) override
virtual Real norm() const override
const Ptr< const V > & getVector() const
virtual void randomize(const Real l=0.0, const Real u=1.0) override
virtual void setScalar(const Real C) override
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const override
virtual Real apply(const V &x) const override
virtual void const V & dual() const override