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 
13 #include "ROL_LinearOperator.hpp"
14 
38 namespace ROL {
39 
40 template <class Real>
41 class HouseholderReflector : public LinearOperator<Real> {
42 
43  typedef Vector<Real> V;
44 
45 private:
46 
47  const ROL::Ptr<const V> x_;
48  const ROL::Ptr<const V> y_;
49 
50  ROL::Ptr<V> u_;
51 
52 public:
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
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Provides the interface to create a Householder reflector operator, that when applied to a vector x...
HouseholderReflector(const ROL::Ptr< const Vector< Real > > &x, const ROL::Ptr< const Vector< Real > > &y, ROL::Ptr< Vector< Real > > &scratch)
const ROL::Ptr< const V > x_
const ROL::Ptr< const V > y_
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)
Provides the interface to apply a linear operator.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
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)