58 T my_max(
const T& v1,
const T& v2 ) {
return v1 > v2 ? v1 : v2; }
61 T my_min(
const T& v1,
const T& v2 ) {
return v1 < v2 ? v1 : v2; }
64 namespace AbstractLinAlgPack {
81 vec_space.
get() == NULL, std::logic_error
82 ,
"VectorMutableBlocked::initialize(...): Error, Must be constructed from "
83 "a non-null block vector space!" );
84 const int num_vec_spaces = vec_space->num_vector_spaces();
85 vecs_.resize(num_vec_spaces);
86 std::copy(vecs,vecs+num_vec_spaces,vecs_.begin());
87 vec_space_ = vec_space;
95 return vec_space_->dim();
105 ,
const size_t num_vecs,
const Vector* vecs[]
107 ,RTOpPack::ReductTarget *reduct_obj
120 !(1 <= first_ele_in && first_ele_in <= n), std::out_of_range
121 ,
"VectorMutableBlocked::apply_op(...): Error, "
122 "first_ele_in = " << first_ele_in <<
" is not in range [1,"<<n<<
"]" );
124 sub_dim_in < 0, std::invalid_argument
125 ,
"VectorMutableBlocked::apply_op(...): Error, "
126 "sub_dim_in = " << sub_dim_in <<
" is not acceptable" );
128 global_offset_in < 0, std::invalid_argument
129 ,
"VectorMutableBlocked::apply_op(...): Error, "
130 "global_offset_in = " << global_offset_in <<
" is not acceptable" );
132 sub_dim_in > 0 && sub_dim_in - (first_ele_in - 1) > n, std::length_error
133 ,
"VectorMutableBlocked::apply_op(...): Error, "
134 "global_offset_in = " << global_offset_in <<
", sub_dim_in = " << sub_dim_in
135 <<
"first_ele_in = " << first_ele_in <<
" and n = " << n
136 <<
" are not compatible" );
138 {
for(
int k = 0; k < num_vecs; ++k) {
142 ,
"VectorMutableBlocked::apply_op(...): Error vecs["<<k<<
"]->space() "
143 <<
"of type \'"<<
typeName(vecs[k]->
space())<<
"\' is not compatible with this "
144 <<
"\'VectorSpaceBlocked\' vector space!"
147 {
for(
int k = 0; k < num_targ_vecs; ++k) {
151 ,
"VectorMutableBlocked::apply_op(...): Error targ_vecs["<<k<<
"]->space() "
152 <<
"of type \'"<<
typeName(vecs[k]->
space())<<
"\' is not compatible with this "
153 <<
"\'VectorSpaceBlocked\' vector space!"
159 Workspace<const VectorMutableBlocked*>
160 vecs_args(wss,num_vecs);
161 {
for(
int k = 0; k < num_vecs; ++k) {
166 ,
"VectorMutableBlocked::apply_op(...): Error vecs["<<k<<
"] "
167 <<
"of type \'"<<
typeName(*vecs[k])<<
"\' does not support the "
168 <<
"\'VectorMutableBlocked\' interface!"
172 Workspace<VectorMutableBlocked*>
173 targ_vecs_args(wss,num_targ_vecs);
174 {
for(
int k = 0; k < num_targ_vecs; ++k) {
179 ,
"VectorMutableBlocked::apply_op(...): Error targ_vecs["<<k<<
"] "
180 <<
"of type \'"<<
typeName(*targ_vecs[k])<<
"\' does not support the "
181 <<
"\'VectorMutableBlocked\' interface!"
190 ? this_dim - (first_ele_in - 1)
193 const int num_vec_spaces = vec_space_->num_vector_spaces();
194 Workspace<const Vector*>
195 sub_vecs(wss,num_vecs);
196 Workspace<VectorMutable*>
197 sub_targ_vecs(wss,num_targ_vecs);
199 for(
int k = 0; k < num_vec_spaces; ++k) {
201 if( g_off < 0 && -g_off > local_dim ) {
206 local_sub_dim = ( g_off >= 0
207 ? my_min( local_dim, num_elements_remaining )
208 : my_min( local_dim + g_off, num_elements_remaining ) );
209 if( local_sub_dim <= 0 )
211 for(
int i = 0; i < num_vecs; ++i )
212 sub_vecs[i] = vecs_args[i]->vecs_[k].
get();
213 for(
int j = 0; j < num_targ_vecs; ++j )
214 sub_targ_vecs[j] = targ_vecs_args[j]->vecs_[k].
get();
217 ,num_vecs,num_vecs?&sub_vecs[0]:NULL
218 ,num_targ_vecs,num_targ_vecs?&sub_targ_vecs[0]:NULL
220 ,g_off < 0 ? -g_off + 1 : 1
222 ,g_off < 0 ? global_offset_in : global_offset_in + g_off
225 num_elements_remaining -= local_sub_dim;
229 {
for(
int k = 0; k < num_targ_vecs; ++k) {
237 const int num_vec_spaces = vec_space_->num_vector_spaces();
239 for(
int k = 0; k < num_vec_spaces; ++k )
240 nz_ += vecs_[k]->
nz();
246 std::ostream& out_arg,
bool print_dim,
bool newline
253 *out << this->
dim() << std::endl;
255 const int num_vec_spaces = vec_space_->num_vector_spaces();
256 for(
int k = 0; k < num_vec_spaces; ++k ) {
257 vecs_[k]->output(*out,
false,
false,off);
258 off += vecs_[k]->dim();
267 int kth_vector_space = -1;
269 vec_space_->get_vector_space_position(i,&kth_vector_space,&kth_global_offset);
273 return vecs_[kth_vector_space]->get_ele( i - kth_global_offset );
278 #ifdef ALAP_VECTOR_MUTABLE_BLOCKED_IGNORE_CACHE_DATA
283 const int num_vec_spaces = vec_space_->num_vector_spaces();
285 for(
int k = 0; k < num_vec_spaces; ++k )
293 #ifdef ALAP_VECTOR_MUTABLE_BLOCKED_IGNORE_CACHE_DATA
298 const int num_vec_spaces = vec_space_->num_vector_spaces();
300 for(
int k = 0; k < num_vec_spaces; ++k )
315 int kth_vector_space = -1;
317 vec_space_->get_vector_space_position(rng.
lbound(),&kth_vector_space,&kth_global_offset);
321 if( rng.
lbound() + rng.
size() <= kth_global_offset + 1 + vecs_[kth_vector_space]->dim() ) {
324 rng - kth_global_offset, sub_vec );
339 if( sub_vec->
values() == NULL )
return;
340 int kth_vector_space = -1;
342 vec_space_->get_vector_space_position(
343 sub_vec->
globalOffset()+1,&kth_vector_space,&kth_global_offset);
347 if( sub_vec->
globalOffset() + sub_vec->
subDim() <= kth_global_offset + vecs_[kth_vector_space]->dim() ) {
350 vecs_[kth_vector_space].get()->free_sub_vector(sub_vec);
370 namespace rcp = MemMngPack;
376 dim < rng.
ubound(), std::out_of_range
377 ,
"VectorMutableBlocked::sub_view(...): Error, rng = "
378 <<
"["<<rng.
lbound()<<
","<<rng.
ubound()<<
"] is not in range [1,"<<dim<<
"]" );
380 vecs_t &vecs = this->vecs_;
391 int kth_vector_space = -1;
393 vec_space_->get_vector_space_position(rng.
lbound(),&kth_vector_space,&kth_global_offset);
395 const index_type* vec_spaces_offsets = vec_space_->vector_spaces_offsets();
399 if( rng.
lbound() == kth_global_offset + 1
400 && rng.
size() == vec_spaces_offsets[kth_vector_space+1] - vec_spaces_offsets[kth_vector_space] )
403 if( rng.
ubound() <= vec_spaces_offsets[kth_vector_space+1] )
405 return vecs[kth_vector_space]->
sub_view( rng - vec_spaces_offsets[kth_vector_space] );
408 int end_kth_vector_space = -1;
410 vec_space_->get_vector_space_position(rng.
ubound(),&end_kth_vector_space,&end_kth_global_offset);
418 &vecs[kth_vector_space]
420 &vector_spaces[kth_vector_space]
421 ,end_kth_vector_space - kth_vector_space + 1 ))
423 if( rng.
lbound() == kth_global_offset + 1
424 && rng.
size() == vec_spaces_offsets[end_kth_vector_space+1] - vec_spaces_offsets[kth_vector_space] )
432 rng.
lbound()-vec_spaces_offsets[kth_vector_space]
433 ,rng.
ubound()-vec_spaces_offsets[kth_vector_space] )
445 const int num_vec_spaces = vec_space_->num_vector_spaces();
446 for(
int k = 0; k < num_vec_spaces; ++k )
461 int kth_vector_space = -1;
463 vec_space_->get_vector_space_position(i,&kth_vector_space,&kth_global_offset);
467 vecs_[kth_vector_space]->set_ele( i - kth_global_offset, val );
473 int kth_vector_space = -1;
475 vec_space_->get_vector_space_position(
476 sub_vec.globalOffset()+1,&kth_vector_space,&kth_global_offset);
480 if( sub_vec.globalOffset() + sub_vec.subDim() <= kth_global_offset + vecs_[kth_vector_space]->dim() ) {
483 sub_vec_g.setGlobalOffset( sub_vec_g.globalOffset() - kth_global_offset );
484 vecs_[kth_vector_space]->set_sub_vector(sub_vec_g);
499 k >= vec_space_->num_vector_spaces(), std::logic_error
500 ,
"VectorMutableBlocked::assert_in_range(k) : Error, k = " << k <<
" is not "
501 "in range [0," << vec_space_->num_vector_spaces() <<
"]" );
void free_sub_vector(RTOpPack::SubVector *sub_vec) const
VectorMutable & operator=(value_type)
virtual void set_sub_vector(const RTOpPack::SparseSubVector &sub_vec)
Set a specific sub-vector.
std::string typeName(const T &t)
virtual void get_sub_vector(const Range1D &rng, RTOpPack::SubVector *sub_vec) const
Get a non-mutable explicit view of a sub-vector.
void set_sub_vector(const RTOpPack::SparseSubVector &sub_vec)
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
RTOp_index_type index_type
void axpy(value_type alpha, const Vector &x)
value_type norm_1() const
value_type inner_product(const Vector &) const
RTOp_value_type value_type
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Index size() const
Return the size of the range (ubound() - lbound() + 1)
Index ubound() const
Return upper bound of the range.
const Scalar * values() const
vec_mut_ptr_t sub_view(const Range1D &rng)
value_type norm_inf_
< 0, not initialized, > 0 already calculated
Concrete subclass for a blocked vector.
value_type get_ele(index_type i) const
void apply_op(const RTOpPack::RTOp &op, const size_t num_vecs, const Vector *vecs[], const size_t num_targ_vecs, VectorMutable *targ_vecs[], RTOpPack::ReductTarget *reduct_obj, const index_type first_ele, const index_type sub_dim, const index_type global_offset) const
void get_sub_vector(const Range1D &rng, RTOpPack::SubVector *sub_vec) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
. One-based subregion index range class.
virtual void has_changed() const
Must be called by any vector subclass that modifies this vector object!
void assert_in_range(int k) const
RTOpT< RTOp_value_type > RTOp
RTOp_index_type size_type
Teuchos_Ordinal subDim() const
Abstract interface for objects that represent a space for mutable coordinate vectors.
void copy(const f_int &N, const f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
void set_ele(index_type i, value_type val)
VectorSpace subclass for the composite of one or more VectorSpace objects.
bool full_range() const
Returns true if the range represents the entire region (constructed from Range1D()) ...
virtual void axpy(value_type alpha, const Vector &x)
Adds a linear combination of another vector to this vector object.
Concrete subclass for a sub-view of a VectorMutable object.
virtual void free_sub_vector(RTOpPack::SubVector *sub_vec) const
Free an explicit view of a sub-vector.
virtual bool is_compatible(const VectorSpace &vec_spc) const =0
Compare the compatibility of two vector spaces.
Teuchos_Ordinal globalOffset() const
Index lbound() const
Return lower bound of the range.
virtual VectorMutable & operator=(value_type alpha)
Assign the elements of this vector to a scalar.
void assert_initialized() const
std::ostream & output(std::ostream &out, bool print_dim, bool newline, index_type global_offset) const
Thrown if vector spaces are incompatible.
Abstract interface for mutable coordinate vectors {abstract}.
void apply_op(EApplyBy apply_by, const RTOpPack::RTOp &primary_op, const size_t num_multi_vecs, const MultiVector *multi_vecs[], const size_t num_targ_multi_vecs, MultiVectorMutable *targ_multi_vecs[], RTOpPack::ReductTarget *reduct_objs[]=NULL, const index_type primary_first_ele=1, const index_type primary_sub_dim=0, const index_type primary_global_offset=0, const index_type secondary_first_ele=1, const index_type secondary_sub_dim=0)
Apply a reduction/transformation operator column by column and return an array of the reduction objec...
void setGlobalOffset(Teuchos_Ordinal globalOffset)
SparseSubVectorT< RTOp_value_type > SparseSubVector
const VectorSpace & space() const
void initialize(VectorMutable::vec_mut_ptr_t *vecs, const vec_space_comp_ptr_t &vec_space)
Initialize given a list of constituent vectors.
std::vector< VectorMutable::vec_mut_ptr_t > vecs_t
Type for list of constituent vectors.
virtual value_type inner_product(const Vector &v) const
Return the inner product of *this with v.
value_type norm_inf() const
RangePack::Range1D Range1D
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Class for a non-mutable sub-vector.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
index_type nz_
dim() not initalized, < dim() already initialized!