ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
vector
ROL_ElementwiseVector.hpp
Go to the documentation of this file.
1
2
// @HEADER
3
// *****************************************************************************
4
// Rapid Optimization Library (ROL) Package
5
//
6
// Copyright 2014 NTESS and the ROL contributors.
7
// SPDX-License-Identifier: BSD-3-Clause
8
// *****************************************************************************
9
// @HEADER
10
11
#ifndef ROL_ELEMENTWISE_VECTOR_H
12
#define ROL_ELEMENTWISE_VECTOR_H
13
14
#include "
ROL_Vector.hpp
"
15
26
27
namespace
ROL
{
28
29
template
<
class
Real>
30
class
ElementwiseVector
:
public
Vector
<Real> {
31
32
public
:
33
34
virtual
~ElementwiseVector
() {}
35
36
void
plus
(
const
Vector<Real>
&x ) {
37
this->
applyBinary
(Elementwise::Plus<Real>(),x);
38
}
39
40
void
scale
(
const
Real alpha ) {
41
this->
applyUnary
(Elementwise::Scale<Real>(alpha));
42
}
43
44
virtual
Real
dot
(
const
Vector<Real>
&x )
const
{
45
ROL::Ptr<Vector<Real> > y = this->
clone
();
46
y->set(*
this
);
47
y->applyBinary(Elementwise::Multiply<Real>(),x);
48
return
y->reduce(Elementwise::ReductionSum<Real>());
49
}
50
51
virtual
Real
norm
()
const
{
52
return
std::sqrt(this->
dot
(*
this
));
53
}
54
55
void
axpy
(
const
Real alpha,
const
Vector<Real>
&x ) {
56
this->
applyBinary
(Elementwise::Axpy<Real>(alpha),x);
57
}
58
59
void
zero
() {
60
this->
applyUnary
(Elementwise::Fill<Real>(Real(0)));
61
}
62
63
void
set
(
const
Vector<Real>
&x ) {
64
this->
applyBinary
(Elementwise::Set<Real>(),x);
65
}
66
67
// MUST overload these three functions
68
virtual
void
applyUnary
(
const
Elementwise::UnaryFunction<Real> &uf ) = 0;
69
70
virtual
void
applyBinary
(
const
Elementwise::BinaryFunction<Real> &bf,
71
const
Vector<Real>
&x ) = 0;
72
73
virtual
Real
reduce
(
const
Elementwise::ReductionOp<Real> &r )
const
= 0;
74
75
};
// class ElementwiseVector
76
77
78
}
// namespace ROL
79
80
81
82
83
#endif
// ROL_ELEMENTWISE_VECTOR_H
84
ROL_Vector.hpp
ROL::ElementwiseVector
Intermediate abstract class which does not require users implements plus, set, scale,...
Definition
ROL_ElementwiseVector.hpp:30
ROL::ElementwiseVector::scale
void scale(const Real alpha)
Compute where .
Definition
ROL_ElementwiseVector.hpp:40
ROL::ElementwiseVector::set
void set(const Vector< Real > &x)
Definition
ROL_ElementwiseVector.hpp:63
ROL::ElementwiseVector::norm
virtual Real norm() const
Returns where .
Definition
ROL_ElementwiseVector.hpp:51
ROL::ElementwiseVector::applyBinary
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &bf, const Vector< Real > &x)=0
ROL::ElementwiseVector::~ElementwiseVector
virtual ~ElementwiseVector()
Definition
ROL_ElementwiseVector.hpp:34
ROL::ElementwiseVector::dot
virtual Real dot(const Vector< Real > &x) const
Definition
ROL_ElementwiseVector.hpp:44
ROL::ElementwiseVector::axpy
void axpy(const Real alpha, const Vector< Real > &x)
Definition
ROL_ElementwiseVector.hpp:55
ROL::ElementwiseVector::applyUnary
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &uf)=0
ROL::ElementwiseVector::reduce
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const =0
ROL::ElementwiseVector::plus
void plus(const Vector< Real > &x)
Definition
ROL_ElementwiseVector.hpp:36
ROL::ElementwiseVector::zero
void zero()
Set to zero vector.
Definition
ROL_ElementwiseVector.hpp:59
ROL::ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0