ROL
ROL_HouseholderReflector.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_HOUSEHOLDERREFLECTOR_H
11#define ROL_HOUSEHOLDERREFLECTOR_H
12
14
38namespace ROL {
39
40template <class Real>
42
43 typedef Vector<Real> V;
44
45private:
46
47 const ROL::Ptr<const V> x_;
48 const ROL::Ptr<const V> y_;
49
50 ROL::Ptr<V> u_;
51
52public:
53
54 HouseholderReflector( const ROL::Ptr<const Vector<Real> > &x,
55 const ROL::Ptr<const Vector<Real> > &y) : x_(x), y_(y), u_(x->clone()) {}
56
57
58 HouseholderReflector( const ROL::Ptr<const Vector<Real> > &x,
59 const ROL::Ptr<const Vector<Real> > &y,
60 ROL::Ptr<Vector<Real> > &scratch ) : x_(x), y_(y), u_(scratch) {}
61
62 HouseholderReflector( const ROL::Ptr<const Vector<Real> > &x ) : x_(x), y_(x->basis(0)), u_(x->clone()) {}
63
64 HouseholderReflector( const ROL::Ptr<const Vector<Real> > &x,
65 ROL::Ptr<Vector<Real> > &scratch ) : x_(x), y_(x->basis(0)), u_(scratch) {}
66
67
68
69 void apply( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
70
71 Real xdoty = x_->dot(*y_);
72 Real xnorm = x_->norm();
73 Real ynorm = y_->norm();
74 Real sgn = xdoty/std::abs(xdoty);
75
76 Real alpha = sgn*xnorm/ynorm;
77
78 u_->set(*x_);
79 u_->axpy(alpha,*y_);
80
81 Real beta = -2.0*u_->dot(v)/u_->dot(*u_);
82
83 Hv.set(v);
84 Hv.axpy(beta,*u_);
85 }
86
87 void applyInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
88 apply(Hv,v,tol);
89 }
90
91}; // class HouseholderReflector
92
93} // namespace ROL
94
95#endif // ROL_HOUSEHOLDERREFLECTOR_H
Provides the interface to create a Householder reflector operator, that when applied to a vector x,...
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x)
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x, const ROL::Ptr< const Vector< Real > > &y, ROL::Ptr< Vector< Real > > &scratch)
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x, ROL::Ptr< Vector< Real > > &scratch)
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x, const ROL::Ptr< const Vector< Real > > &y)
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 axpy(const Real alpha, const Vector &x)
Compute where .