ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
vector
ROL_SingletonVector.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_SINGLETONVECTOR_H
12
#define ROL_SINGLETONVECTOR_H
13
14
#include "
ROL_Vector.hpp
"
15
20
21
22
namespace
ROL
{
23
24
template
<
class
Real>
25
class
SingletonVector
:
public
Vector
<Real> {
26
27
using
V
=
Vector<Real>
;
28
29
private
:
30
31
Real
value_
;
32
33
Real
getValueX
(
const
V
& x )
const
{
34
return
dynamic_cast<
const
SingletonVector<Real>
&
>
(x).
getValue
();
35
}
36
37
public
:
38
39
SingletonVector
(Real
value
= Real(0)) :
value_
(
value
) {}
40
41
Real
getValue
()
const
{
return
value_
; }
42
void
setValue
( Real v ) {
value_
= v; }
43
44
void
set
(
const
V
& x ) {
45
value_
=
getValueX
(x);
46
}
47
48
void
plus
(
const
V
& x ) {
49
value_
+=
getValueX
(x);
50
}
51
52
void
axpy
(
const
Real alpha,
const
V
& x ) {
53
value_
+= alpha*
getValueX
(x);
54
}
55
56
void
scale
(
const
Real alpha ) {
57
value_
*= alpha;
58
}
59
60
Real
dot
(
const
V
& x )
const
{
61
Real xv =
getValueX
(x);
62
xv *=
value_
;
63
return
xv;
64
}
65
66
Real
norm
()
const
{
67
return
std::abs(
value_
);
68
}
69
70
ROL::Ptr<V>
clone
()
const
{
71
return
ROL::makePtr<SingletonVector>(0);
72
}
73
74
ROL::Ptr<V>
basis
(
const
int
i)
const
{
75
ROL_TEST_FOR_EXCEPTION( i >= 1 || i < 0,
76
std::invalid_argument,
77
"Error: Basis index must be between 0 and vector dimension."
);
78
return
ROL::makePtr<SingletonVector>(1);
79
}
80
81
int
dimension
()
const
{
return
1; };
82
83
void
applyUnary
(
const
Elementwise::UnaryFunction<Real> &f ) {
84
value_
= f.apply(
value_
);
85
}
86
87
void
applyBinary
(
const
Elementwise::BinaryFunction<Real> &f,
const
V
& x ) {
88
value_
= f.apply(
value_
,
getValueX
(x));
89
}
90
91
Real
reduce
(
const
Elementwise::ReductionOp<Real> &r )
const
{
92
return
value_
;
93
}
94
95
void
setScalar
(
const
Real C ) {
96
value_
= C;
97
}
98
99
void
randomize
(
const
Real l=0.0,
const
Real u=1.0 ) {
100
Real a = (u-l);
101
Real b = l;
102
Real x =
static_cast<
Real
>
(rand())/
static_cast<
Real
>
(RAND_MAX);
103
value_
= a*x + b;
104
}
105
106
void
print
( std::ostream& os )
const
{
107
os <<
value_
<< std::endl;
108
}
109
110
};
111
112
113
}
// namespace ROL
114
115
116
117
118
#endif
// ROL_SINGLETONVECTOR_H
119
ROL_Vector.hpp
ROL::SingletonVector::setValue
void setValue(Real v)
Definition
ROL_SingletonVector.hpp:42
ROL::SingletonVector::print
void print(std::ostream &os) const
Definition
ROL_SingletonVector.hpp:106
ROL::SingletonVector::value_
Real value_
Definition
ROL_SingletonVector.hpp:31
ROL::SingletonVector::scale
void scale(const Real alpha)
Compute where .
Definition
ROL_SingletonVector.hpp:56
ROL::SingletonVector::reduce
Real reduce(const Elementwise::ReductionOp< Real > &r) const
Definition
ROL_SingletonVector.hpp:91
ROL::SingletonVector::setScalar
void setScalar(const Real C)
Set where .
Definition
ROL_SingletonVector.hpp:95
ROL::SingletonVector::axpy
void axpy(const Real alpha, const V &x)
Definition
ROL_SingletonVector.hpp:52
ROL::SingletonVector::dot
Real dot(const V &x) const
Definition
ROL_SingletonVector.hpp:60
ROL::SingletonVector::applyUnary
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
Definition
ROL_SingletonVector.hpp:83
ROL::SingletonVector::clone
ROL::Ptr< V > clone() const
Clone to make a new (uninitialized) vector.
Definition
ROL_SingletonVector.hpp:70
ROL::SingletonVector::basis
ROL::Ptr< V > basis(const int i) const
Return i-th basis vector.
Definition
ROL_SingletonVector.hpp:74
ROL::SingletonVector::plus
void plus(const V &x)
Definition
ROL_SingletonVector.hpp:48
ROL::SingletonVector::set
void set(const V &x)
Definition
ROL_SingletonVector.hpp:44
ROL::SingletonVector::SingletonVector
SingletonVector(Real value=Real(0))
Definition
ROL_SingletonVector.hpp:39
ROL::SingletonVector::getValueX
Real getValueX(const V &x) const
Definition
ROL_SingletonVector.hpp:33
ROL::SingletonVector::V
Vector< Real > V
Definition
ROL_SingletonVector.hpp:27
ROL::SingletonVector::norm
Real norm() const
Returns where .
Definition
ROL_SingletonVector.hpp:66
ROL::SingletonVector::getValue
Real getValue() const
Definition
ROL_SingletonVector.hpp:41
ROL::SingletonVector::dimension
int dimension() const
Return dimension of the vector space.
Definition
ROL_SingletonVector.hpp:81
ROL::SingletonVector::applyBinary
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
Definition
ROL_SingletonVector.hpp:87
ROL::SingletonVector::randomize
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
Definition
ROL_SingletonVector.hpp:99
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::value
ROL::Objective_SerialSimOpt Objective_SimOpt value(const V &u, const V &z, Real &tol) override
Definition
ROL_Objective_SerialSimOpt.hpp:50
Generated by
1.17.0