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"
16
17
25namespace ROL {
26
27template<class Real>
28class DiagonalOperator : public LinearOperator<Real> {
29
30private:
31
32 ROL::Ptr<Vector<Real> > diag_;
33
34 const Elementwise::Multiply<Real> mult_;
35 const Elementwise::Divide<Real> div_;
36
37public:
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
Provides the interface to apply a diagonal operator which acts like elementwise multiplication when a...
ROL::Ptr< Vector< Real > > diag_
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update linear operator.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
const Elementwise::Divide< Real > div_
DiagonalOperator(const Vector< Real > &diag)
const Elementwise::Multiply< Real > mult_
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
Provides the interface to apply a linear operator.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)