46 #include <initializer_list>
48 #ifndef ROL_PARTITIONED_VECTOR_H
49 #define ROL_PARTITIONED_VECTOR_H
63 typedef ROL::Ptr<V>
Vp;
81 const PV &xs =
dynamic_cast<const PV&
>(x);
83 std::invalid_argument,
84 "Error: Vectors must have the same number of subvectors." );
91 const PV &xs =
dynamic_cast<const PV&
>(x);
93 std::invalid_argument,
94 "Error: Vectors must have the same number of subvectors." );
102 vecs_[i]->scale(alpha);
106 void axpy(
const Real alpha,
const V &x ) {
107 const PV &xs =
dynamic_cast<const PV&
>(x);
109 std::invalid_argument,
110 "Error: Vectors must have the same number of subvectors." );
118 const PV &xs =
dynamic_cast<const PV&
>(x);
120 std::invalid_argument,
121 "Error: Vectors must have the same number of subvectors." );
124 result +=
vecs_[i]->dot(*xs.
get(i));
134 return std::sqrt(result);
138 std::vector<Vp> clonevec;
142 return ROL::makePtr<PV>(clonevec);
154 ROL_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
155 std::invalid_argument,
156 "Error: Basis index must be between 0 and vector dimension." );
159 PV &eb =
dynamic_cast<PV&
>(*bvec);
162 int begin = 0, end = 0;
164 end +=
vecs_[j]->dimension();
165 if( begin<= i && i<end ) {
179 total_dim +=
vecs_[j]->dimension();
191 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
193 vecs_[i]->applyUnary(f);
198 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
199 const PV &xs =
dynamic_cast<const PV&
>(x);
202 vecs_[i]->applyBinary(f,*xs.
get(i));
206 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
207 Real result = r.initialValue();
217 vecs_[i]->setScalar(C);
221 void randomize(
const Real l = 0.0,
const Real u = 1.0 ) {
223 vecs_[i]->randomize(l,u);
227 void print( std::ostream &outStream )
const {
229 outStream <<
"V[" << i <<
"]: ";
230 vecs_[i]->print(outStream);
259 static Ptr<PartitionedVector>
create( std::initializer_list<Vp> vs ) {
260 std::vector<Vp> subvecs{vs};
261 return ROL::makePtr<PartitionedVector>( subvecs );
266 std::vector<Vp> subvecs(N);
268 return ROL::makePtr<PartitionedVector>( subvecs );
275 ROL::Ptr<Vector<Real>>
278 using Vp = ROL::Ptr<Vector<Real>>;
282 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
286 ROL::Ptr<const Vector<Real> >
289 using Vp = ROL::Ptr<const Vector<Real>>;
293 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
297 ROL::Ptr<Vector<Real>>
300 using Vp = ROL::Ptr<Vector<Real>>;
304 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
308 ROL::Ptr<const Vector<Real> >
311 using Vp = ROL::Ptr<const Vector<Real>>;
315 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
320 ROL::Ptr<Vector<Real>>
325 using Vp = ROL::Ptr<Vector<Real>>;
329 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
333 ROL::Ptr<const Vector<Real> >
338 using Vp = ROL::Ptr<const Vector<Real>>;
342 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
346 ROL::Ptr<Vector<Real> >
353 typedef ROL::Ptr<Vector<Real> > Vp;
356 Vp temp[] = {a,b,c,d};
357 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
361 ROL::Ptr<const Vector<Real> >
368 using Vp = ROL::Ptr<const Vector<Real>>;
371 Vp temp[] = {a,b,c,d};
372 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
377 #endif // ROL_PARTITIONED_VECTOR_H
PartitionedVector(const std::vector< Vp > &vecs)
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
PartitionedVector< Real > PV
typename PV< Real >::size_type size_type
size_type numVectors() const
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Ptr< const Vector< Real > > get(size_type i) const
ROL::Ptr< PV > dual_pvec_
Real norm() const
Returns where .
Defines the linear algebra of vector space on a generic partitioned vector.
ROL::Ptr< Vector< Real > > CreatePartitionedVector(const ROL::Ptr< Vector< Real >> &a)
const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
void print(std::ostream &outStream) const
static Ptr< PartitionedVector > create(const V &x, size_type N)
Vp clone() const
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
Real dot(const V &x) const
Compute where .
void zero()
Set to zero vector.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
void setScalar(const Real C)
Set where .
PartitionedVector< Real > PV
void set(size_type i, const V &x)
void scale(const Real alpha)
Compute where .
int dimension() const
Return dimension of the vector space.
void set(const V &x)
Set where .
Vp basis(const int i) const
Return i-th basis vector.
std::vector< Vp > dual_vecs_
std::vector< PV >::size_type size_type
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 plus(const V &x)
Compute , where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void axpy(const Real alpha, const V &x)
Compute where .