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);
266 static Ptr<PartitionedVector>
create( std::initializer_list<Vp> vs ) {
267 std::vector<Vp> subvecs{vs};
268 return ROL::makePtr<PartitionedVector>( subvecs );
273 std::vector<Vp> subvecs(N);
275 return ROL::makePtr<PartitionedVector>( subvecs );
282 template<
typename Real>
287 template<
typename Real>
292 template<
typename Real>
294 return staticPtrCast<PartitionedVector<Real>>(x);
297 template<
typename Real>
299 return staticPtrCast<const PartitionedVector<Real>>(x);
305 ROL::Ptr<Vector<Real>>
308 using Vp = ROL::Ptr<Vector<Real>>;
312 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
316 ROL::Ptr<const Vector<Real> >
319 using Vp = ROL::Ptr<const Vector<Real>>;
323 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1) );
327 ROL::Ptr<Vector<Real>>
330 using Vp = ROL::Ptr<Vector<Real>>;
334 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
338 ROL::Ptr<const Vector<Real> >
341 using Vp = ROL::Ptr<const Vector<Real>>;
345 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2) );
350 ROL::Ptr<Vector<Real>>
355 using Vp = ROL::Ptr<Vector<Real>>;
359 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
363 ROL::Ptr<const Vector<Real> >
368 using Vp = ROL::Ptr<const Vector<Real>>;
372 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3) );
376 ROL::Ptr<Vector<Real> >
383 typedef ROL::Ptr<Vector<Real> > Vp;
386 Vp temp[] = {a,b,c,d};
387 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
391 ROL::Ptr<const Vector<Real> >
398 using Vp = ROL::Ptr<const Vector<Real>>;
401 Vp temp[] = {a,b,c,d};
402 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4) );
407 #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 .
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 .