ROL
ROL_VectorNorms.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_VECTORNORMS_H
11 #define ROL_VECTORNORMS_H
12 
13 #include "ROL_Vector.hpp"
14 
15 namespace ROL {
16 
17 template<class Real>
18 Real normL1( const Vector<Real> &x ) {
19 
20  ROL::Ptr<Vector<Real> > xabs = x.clone();
21  xabs->set(x);
22 
23  xabs->applyUnary(Elementwise::AbsoluteValue<Real>());
24  return xabs->reduce(Elementwise::ReductionSum<Real>());
25 }
26 
27 template<class Real, class Exponent>
28 Real normLp( const Vector<Real> &x, Exponent p ) {
29 
30  ROL::Ptr<Vector<Real> > xabsp = x.clone();
31  xabsp->set(x);
32  xabsp->applyUnary(Elementwise::AbsoluteValue<Real>());
33  xabsp->applyUnary(Elementwise::Power<Real>(p));
34  Real sum = xabsp->reduce(Elementwise::ReductionSum<Real>());
35  return std::pow(sum,1.0/p);
36 }
37 
38 template<class Real>
39 Real normLinf( const Vector<Real> &x ) {
40 
41  ROL::Ptr<Vector<Real> > xabs = x.clone();
42  xabs->set(x);
43 
44  xabs->applyUnary(Elementwise::AbsoluteValue<Real>());
45  return xabs->reduce(Elementwise::ReductionMax<Real>());
46 }
47 
48 
49 
50 } // namespace ROL
51 
52 #endif // ROL_VECTORNORMS_H
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real normLinf(const Vector< Real > &x)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real normL1(const Vector< Real > &x)
Real normLp(const Vector< Real > &x, Exponent p)