47#ifndef ROL_SIMULATED_VECTOR_H
48#define ROL_SIMULATED_VECTOR_H
62class PrimalSimulatedVector;
65class DualSimulatedVector;
71 typedef ROL::Ptr<V>
Vp;
72 typedef ROL::Ptr<BatchManager<Real> >
VBMp;
77 ROL::Ptr<BatchManager<Real> >
bman_;
82 typedef typename std::vector<PV>::size_type
size_type;
92 const PV &xs =
dynamic_cast<const PV&
>(x);
95 std::invalid_argument,
96 "Error: Vectors must have the same number of subvectors." );
105 const PV &xs =
dynamic_cast<const PV&
>(x);
108 std::invalid_argument,
109 "Error: Vectors must have the same number of subvectors." );
118 vecs_[i]->scale(alpha);
122 void axpy(
const Real alpha,
const V &x ) {
124 const PV &xs =
dynamic_cast<const PV&
>(x);
127 std::invalid_argument,
128 "Error: Vectors must have the same number of subvectors." );
135 virtual Real
dot(
const V &x )
const {
137 const PV &xs =
dynamic_cast<const PV&
>(x);
140 std::invalid_argument,
141 "Error: Vectors must have the same number of subvectors." );
146 locresult +=
vecs_[i]->dot(*xs.
get(i));
149 bman_->sumAll(&locresult, &result, 1);
155 return std::sqrt(
dot(*
this));
162 std::vector<Vp> clonevec;
166 return ROL::makePtr<PV>(clonevec,
bman_);
181 ROL_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
182 std::invalid_argument,
183 "Error: Basis index must be between 0 and vector dimension." );
187 PV &eb =
dynamic_cast<PV&
>(*bvec);
195 end +=
vecs_[j]->dimension();
197 if( begin<= i && i<end ) {
213 total_dim +=
vecs_[j]->dimension();
225 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
227 vecs_[i]->applyUnary(f);
232 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
233 const PV &xs =
dynamic_cast<const PV&
>(x);
236 vecs_[i]->applyBinary(f,*xs.
get(i));
240 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
241 Real result = r.initialValue();
251 vecs_[i]->setScalar(C);
257 vecs_[i]->randomize(l,u);
289ROL::Ptr<Vector<Real> >
293 typedef ROL::Ptr<Vector<Real> > Vp;
297 return ROL::makePtr<PV>(std::vector<Vp>(temp, temp+1), bman );
303 const std::vector<ROL::Ptr<Vector<Real>>>
vecs_;
304 const ROL::Ptr<BatchManager<Real>>
bman_;
316 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
325 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<int>(xs.
numVectors()),
326 std::invalid_argument,
327 "Error: Vectors must have the same number of subvectors." );
332 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
335 Real t = locresult + y;
336 c = (t - locresult) - y;
340 bman_->sumAll(&locresult, &result, 1);
345 ROL::Ptr<Vector<Real> >
clone(
void)
const {
346 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
347 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
350 return ROL::makePtr<PrimalSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
358 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
370 const std::vector<ROL::Ptr<Vector<Real> > >
vecs_;
371 const ROL::Ptr<BatchManager<Real> >
bman_;
383 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
392 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<Real
>(xs.
numVectors()),
393 std::invalid_argument,
394 "Error: Vectors must have the same number of subvectors." );
399 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
402 Real t = locresult + y;
403 c = (t - locresult) - y;
407 bman_->sumAll(&locresult, &result, 1);
412 ROL::Ptr<Vector<Real> >
clone(
void)
const {
413 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
414 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
417 return ROL::makePtr<DualSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
426 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
436ROL::Ptr<const Vector<Real> >
440 typedef ROL::Ptr<const Vector<Real> > Vp;
444 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1), bman );
448ROL::Ptr<Vector<Real> >
453 typedef ROL::Ptr<Vector<Real> > Vp;
457 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
461ROL::Ptr<const Vector<Real> >
467 typedef ROL::Ptr<const Vector<Real> > Vp;
471 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
475ROL::Ptr<Vector<Real> >
482 typedef ROL::Ptr<Vector<Real> > Vp;
486 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
490ROL::Ptr<const Vector<Real> >
497 typedef ROL::Ptr<const Vector<Real> > Vp;
501 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
505ROL::Ptr<Vector<Real> >
513 typedef ROL::Ptr<Vector<Real> > Vp;
516 Vp temp[] = {a,b,c,d};
517 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
521ROL::Ptr<const Vector<Real> >
529 typedef ROL::Ptr<const Vector<Real> > Vp;
532 Vp temp[] = {a,b,c,d};
533 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
PartitionedVector< Real > PV
Real dot(const Vector< Real > &x) const
Compute where .
bool isPrimalInitialized_
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
const std::vector< ROL::Ptr< Vector< Real > > > vecs_
const ROL::Ptr< SampleGenerator< Real > > sampler_
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
const ROL::Ptr< BatchManager< Real > > bman_
ROL::Ptr< PrimalSimulatedVector< Real > > primal_pvec_
DualSimulatedVector(const std::vector< ROL::Ptr< Vector< Real > > > &vecs, const ROL::Ptr< BatchManager< Real > > &bman, const ROL::Ptr< SampleGenerator< Real > > &sampler)
std::vector< ROL::Ptr< Vector< Real > > > primal_vecs_
PrimalSimulatedVector(const std::vector< ROL::Ptr< Vector< Real > > > &vecs, const ROL::Ptr< BatchManager< Real > > &bman, const ROL::Ptr< SampleGenerator< Real > > &sampler)
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
ROL::Ptr< DualSimulatedVector< Real > > dual_pvec_
std::vector< ROL::Ptr< Vector< Real > > > dual_vecs_
const ROL::Ptr< BatchManager< Real > > bman_
Real dot(const Vector< Real > &x) const
Compute where .
const std::vector< ROL::Ptr< Vector< Real > > > vecs_
const ROL::Ptr< SampleGenerator< Real > > sampler_
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
Defines the linear algebra of a vector space on a generic partitioned vector where the individual vec...
ROL::Ptr< BatchManager< Real > > VBMp
void scale(const Real alpha)
Compute where .
std::vector< PV >::size_type size_type
void zero()
Set to zero vector.
ROL::Ptr< BatchManager< Real > > bman_
ROL::Ptr< Vector< Real > > get(size_type i)
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
ROL::Ptr< const Vector< Real > > get(size_type i) const
size_type numVectors() const
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
const std::vector< Vp > vecs_
void set(size_type i, const V &x)
SimulatedVector< Real > PV
virtual const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
void set(const V &x)
Set where .
void setScalar(const Real C)
Set where .
void axpy(const Real alpha, const V &x)
Compute where .
Real norm() const
Returns where .
std::vector< Vp > dual_vecs_
Vp basis(const int i) const
Return i-th basis vector.
int dimension() const
Return dimension of the vector space.
SimulatedVector(const std::vector< Vp > &vecs, const VBMp &bman)
virtual Vp clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< PV > dual_pvec_
virtual Real dot(const V &x) const
Compute where .
void plus(const V &x)
Compute , where .
Defines the linear algebra or vector space interface.
ROL::Ptr< Vector< Real > > CreateSimulatedVector(const ROL::Ptr< Vector< Real > > &a, const ROL::Ptr< BatchManager< Real > > &bman)