10 #ifndef ROL_ATOMVECTOR_H
11 #define ROL_ATOMVECTOR_H
38 const int numMySamples,
const int dimension)
42 ROL::Ptr<const std::vector<Real> >
getAtom(
const int i)
const {
43 ROL_TEST_FOR_EXCEPTION((i < 0 || i >
numMySamples_), std::invalid_argument,
44 ">>> ERROR (ROL::AtomVector): index out of bounds in getAtom!");
46 std::vector<Real> pt(dim,0);
48 for (
uint j = 0; j <
dim; ++j) {
49 pt[j] = yval[I*dim + j];
51 return ROL::makePtr<std::vector<Real>>(pt);
54 void setAtom(
const int i,
const std::vector<Real> &pt) {
55 ROL_TEST_FOR_EXCEPTION((i < 0 || i >
numMySamples_), std::invalid_argument,
56 ">>> ERROR (ROL::AtomVector): index out of bounds in setAtom!");
59 for (
uint j = 0; j <
dim; ++j) {
60 yval[I*dim + j] = pt[j];
74 class PrimalAtomVector :
public AtomVector<Real> {
77 const ROL::Ptr<std::vector<Real> >
scale_;
84 const int numMySamples,
const int dimension,
85 const ROL::Ptr<std::vector<Real> > &
scale)
86 :
AtomVector<Real>(vec,bman,numMySamples,dimension),
92 uint ysize = yval.size();
93 ROL_TEST_FOR_EXCEPTION( xval.size() != ysize, std::invalid_argument,
94 "Error: Vectors must have the same dimension." );
98 Real val(0), sum_val(0);
99 for (
uint i = 0; i < numMySamples; i++) {
101 index = i*dimension + j;
102 val += xval[index] * (*scale_)[index] * yval[index];
110 ROL::Ptr<Vector<Real> >
clone(
void)
const {
113 return ROL::makePtr<PrimalAtomVector>(
114 ROL::makePtr<std::vector<Real>>(numMySamples*
dimension),
123 dual_vec_ = ROL::makePtr<DualAtomVector<Real>>(
124 ROL::makePtr<std::vector<Real>>(numMySamples*
dimension),
130 for (
uint i = 0; i < numMySamples; i++) {
132 index = i*dimension + j;
142 class DualAtomVector :
public AtomVector<Real> {
145 const ROL::Ptr<std::vector<Real> >
scale_;
152 const int numMySamples,
const int dimension,
153 const ROL::Ptr<std::vector<Real> > &
scale)
154 :
AtomVector<Real>(vec,bman,numMySamples,dimension),
160 uint ysize = yval.size();
161 ROL_TEST_FOR_EXCEPTION( xval.size() != ysize, std::invalid_argument,
162 "Error: Vectors must have the same dimension." );
166 Real val(0), sum_val(0);
167 for (
uint i = 0; i < numMySamples; i++) {
169 index = i*dimension + j;
170 val += xval[index] * yval[index] / (*scale_)[index];
178 ROL::Ptr<Vector<Real> >
clone(
void)
const {
181 return ROL::makePtr<DualAtomVector>(
182 ROL::makePtr<std::vector<Real>>(numMySamples*
dimension),
191 primal_vec_ = ROL::makePtr<PrimalAtomVector<Real>>(
192 ROL::makePtr<std::vector<Real>>(numMySamples*
dimension),
198 for (
uint i = 0; i < numMySamples; i++) {
200 index = i*dimension + j;
const ROL::Ptr< std::vector< Real > > scale_
std::vector< Real >::size_type uint
typename PV< Real >::size_type size_type
void scale(const Real alpha)
Compute where .
Provides the std::vector implementation of the ROL::Vector interface.
int getDimension(void) const
ROL::Ptr< const std::vector< Real > > getAtom(const int i) const
Provides the std::vector implementation of the ROL::Vector interface.
void setAtom(const int i, const std::vector< Real > &pt)
Real dot(const Vector< Real > &x) const
Compute where .
Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::vector< Real >::size_type uint
AtomVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman, const int numMySamples, const int dimension)
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real dot(const Vector< Real > &x) const
Compute where .
const Ptr< BatchManager< Real > > getBatchManager(void) const
int getNumMyAtoms(void) const
DualAtomVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman, const int numMySamples, const int dimension, const ROL::Ptr< std::vector< Real > > &scale)
PrimalAtomVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman, const int numMySamples, const int dimension, const ROL::Ptr< std::vector< Real > > &scale)
const ROL::Ptr< std::vector< Real > > scale_
std::vector< Real >::size_type uint
ROL::Ptr< PrimalAtomVector< Real > > primal_vec_
int dimension(void) const
Return dimension of the vector space.
ROL::Ptr< DualAtomVector< Real > > dual_vec_