11 #ifndef RTOPPACK_TOP_SET_SUB_VECTOR_DEF_HPP
12 #define RTOPPACK_TOP_SET_SUB_VECTOR_DEF_HPP
18 template<
class Scalar>
20 :
RTOpT<Scalar>(
"TOpSetSubVector")
24 template<
class Scalar>
26 :
RTOpT<Scalar>(
"TOpSetSubVector")
32 template<
class Scalar>
42 template<
class Scalar>
49 template<
class Scalar>
53 const Ptr<ReductTarget> &reduct_obj
61 validate_apply_op( *
this, 0, 1,
false, sub_vecs, targ_sub_vecs, reduct_obj.getConst() );
66 const index_type z_sub_dim = z.subDim();
67 iter_t z_val = z.values().begin();
68 const ptrdiff_t z_val_s = z.stride();
71 const index_type v_global_offset = sub_vec_.globalOffset();
72 const index_type v_sub_dim = sub_vec_.subDim();
73 const index_type v_sub_nz = sub_vec_.subNz();
74 const_iter_t v_val = sub_vec_.values().begin();
75 const ptrdiff_t v_val_s = sub_vec_.valuesStride();
76 const bool has_v_ind = !
is_null(sub_vec_.indices());
77 const_indices_iter_t v_ind = sub_vec_.indices().begin();
78 const ptrdiff_t v_ind_s = sub_vec_.indicesStride();
79 const ptrdiff_t v_l_off = sub_vec_.localOffset();
86 if( v_global_offset + v_sub_dim < z_global_offset + 1
87 || z_global_offset + z_sub_dim < v_global_offset + 1 )
98 index_type num_overlap;
99 if( v_global_offset <= z_global_offset ) {
100 if( v_global_offset + v_sub_dim >= z_global_offset + z_sub_dim )
101 num_overlap = z_sub_dim;
103 num_overlap = (v_global_offset + v_sub_dim) - z_global_offset;
106 if( z_global_offset + z_sub_dim >= v_global_offset + v_sub_dim )
107 num_overlap = v_sub_dim;
109 num_overlap = (z_global_offset + z_sub_dim) - v_global_offset;
116 if( v_global_offset >= z_global_offset )
117 z_val += (v_global_offset - z_global_offset) * z_val_s;
118 for( index_type k = 0; k < num_overlap; ++k, z_val += z_val_s )
121 z_val = targ_sub_vecs[0].values().begin();
122 for( index_type k = 0; k < v_sub_nz; ++k, v_val += v_val_s, v_ind += v_ind_s ) {
123 const index_type i = v_global_offset + v_l_off + (*v_ind);
124 if( z_global_offset < i && i <= z_global_offset + z_sub_dim )
125 z_val[ z_val_s * (i - z_global_offset - 1) ] = *v_val;
132 if( v_global_offset <= z_global_offset )
133 v_val += (z_global_offset - v_global_offset) * v_val_s;
135 z_val += (v_global_offset - z_global_offset) * z_val_s;
136 for( index_type k = 0; k < num_overlap; ++k, v_val += v_val_s, z_val += z_val_s )
145 #endif // RTOPPACK_TOP_SET_SUB_VECTOR_DEF_HPP
bool is_null(const boost::shared_ptr< T > &p)
bool coord_invariant_impl() const
void set_sub_vec(const SparseSubVectorT< Scalar > &sub_vec)
Ordinal globalOffset() const
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj) const