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
15namespace ROL {
16
17template<class Real>
18Real 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
27template<class Real, class Exponent>
28Real 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
38template<class Real>
39Real 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
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real normL1(const Vector< Real > &x)
Real normLp(const Vector< Real > &x, Exponent p)
Real normLinf(const Vector< Real > &x)