ROL
ROL_DiagonalOperator.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 #ifndef ROL_DIAGONALOPERATOR_H
11 #define ROL_DIAGONALOPERATOR_H
12 
13 #include "ROL_Vector.hpp"
14 #include "ROL_Elementwise_Function.hpp"
15 #include "ROL_LinearOperator.hpp"
16 
17 
25 namespace ROL {
26 
27 template<class Real>
28 class DiagonalOperator : public LinearOperator<Real> {
29 
30 private:
31 
32  ROL::Ptr<Vector<Real> > diag_;
33 
34  const Elementwise::Multiply<Real> mult_;
35  const Elementwise::Divide<Real> div_;
36 
37 public:
38 
39  DiagonalOperator( const Vector<Real> &diag ) : diag_(diag.clone()) {
40  diag_->set(diag);
41  }
42 
43  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
44  diag_->set(x);
45  }
46 
47  void apply( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
48  Hv.set(v);
49  Hv.applyBinary( mult_, *diag_ );
50  }
51 
52  void applyInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
53  Hv.set(v);
54  Hv.applyBinary( div_, *diag_ );
55  }
56 
57 };
58 
59 } // namespace ROL
60 
61 
62 
63 
64 #endif // ROL_DIAGONALOPERATOR_H
65 
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Definition: ROL_Vector.hpp:214
DiagonalOperator(const Vector< Real > &diag)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
ROL::Ptr< Vector< Real > > diag_
Provides the interface to apply a diagonal operator which acts like elementwise multiplication when a...
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update linear operator.
const Elementwise::Multiply< Real > mult_
const Elementwise::Divide< Real > div_
Provides the interface to apply a linear operator.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175