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 const PV &xs =
dynamic_cast<const PV&
>(x);
156 std::invalid_argument,
157 "Error: Vectors must have the same number of subvectors." );
160 result +=
vecs_[i]->apply(*xs.
get(i));
166 ROL_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
167 std::invalid_argument,
168 "Error: Basis index must be between 0 and vector dimension." );
171 PV &eb =
dynamic_cast<PV&
>(*bvec);
174 int begin = 0, end = 0;
176 end +=
vecs_[j]->dimension();
177 if( begin<= i && i<end ) {
191 total_dim +=
vecs_[j]->dimension();
203 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
205 vecs_[i]->applyUnary(f);
210 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
211 const PV &xs =
dynamic_cast<const PV&
>(x);
214 vecs_[i]->applyBinary(f,*xs.
get(i));
218 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
219 Real result = r.initialValue();
229 vecs_[i]->setScalar(C);
233 void randomize(
const Real l = 0.0,
const Real u = 1.0 ) {
235 vecs_[i]->randomize(l,u);
239 void print( std::ostream &outStream )
const {
241 outStream <<
"V[" << i <<
"]: ";
242 vecs_[i]->print(outStream);
278 static Ptr<PartitionedVector>
create( std::initializer_list<Vp> vs ) {
279 std::vector<Vp> subvecs{vs};
280 return ROL::makePtr<PartitionedVector>( subvecs );
285 std::vector<Vp> subvecs(N);
287 return ROL::makePtr<PartitionedVector>( subvecs );
294 template<
typename Real>
299 template<
typename Real>
304 template<
typename Real>
306 return staticPtrCast<PartitionedVector<Real>>(x);
309 template<
typename Real>
311 return staticPtrCast<const PartitionedVector<Real>>(x);
317 ROL::Ptr<Vector<Real>>
320 using Vp = ROL::Ptr<Vector<Real>>;
324 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
328 ROL::Ptr<const Vector<Real> >
331 using Vp = ROL::Ptr<const Vector<Real>>;
335 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
339 ROL::Ptr<Vector<Real>>
342 using Vp = ROL::Ptr<Vector<Real>>;
346 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
350 ROL::Ptr<const Vector<Real> >
353 using Vp = ROL::Ptr<const Vector<Real>>;
357 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
362 ROL::Ptr<Vector<Real>>
367 using Vp = ROL::Ptr<Vector<Real>>;
371 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
375 ROL::Ptr<const Vector<Real> >
380 using Vp = ROL::Ptr<const Vector<Real>>;
384 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
388 ROL::Ptr<Vector<Real> >
395 typedef ROL::Ptr<Vector<Real> > Vp;
398 Vp temp[] = {a,b,c,d};
399 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
403 ROL::Ptr<const Vector<Real> >
410 using Vp = ROL::Ptr<const Vector<Real>>;
413 Vp temp[] = {a,b,c,d};
414 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
419 #endif // ROL_PARTITIONED_VECTOR_H
PartitionedVector< Real > & partition(Vector< Real > &x)
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...
Vector< Real > & operator[](size_type i)
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 .
Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
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_
const Vector< Real > & operator[](size_type i) const
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 .