42 #ifndef COO_MATRIX_PARTITIONED_VIEW_CLASS_DEF_H
43 #define COO_MATRIX_PARTITIONED_VIEW_CLASS_DEF_H
51 namespace AbstractLinAlgPack {
56 template <
class T_Indice,
class T_Value>
78 throw std::out_of_range(
79 "COOMatrixPartitionedView<...>::create_view() : Input error, "
80 "nz can not be greater than rows * cols");
84 if(num_row_part > rows || num_col_part > rows)
85 throw std::out_of_range(
86 "COOMatrixPartitionedView<...>::create_view() : Input error, "
87 "num_rows_part and num_col_part can not be greater than"
88 " rows and cols respectivly");
90 if(row_part[num_row_part] > rows + 1)
91 throw std::out_of_range(
92 "COOMatrixPartitionedView<...>::create_view() : Input error, "
93 "row_part[num_row_part] can not be greater than rows");
95 if(col_part[num_col_part] > cols + 1)
96 throw std::out_of_range(
97 "COOMatrixPartitionedView<...>::create_view() : Input error, "
98 "col_part[num_col_part] can not be greater than cols");
100 {
for(
size_type i = 1; i < num_row_part + 1; ++i)
101 if(row_part[i-1] >= row_part[i])
102 throw std::domain_error(
103 "COOMatrixPartitionedView<...>::create_view() : Input error, "
104 "row_part[i-1] < row_part[i] does not hold");}
106 {
for(
size_type i = 1; i < num_col_part + 1; ++i)
107 if(col_part[i-1] >= col_part[i])
108 throw std::domain_error(
109 "COOMatrixPartitionedView<...>::create_view() : Input error, "
110 "col_part[i-1] < col_part[i] does not hold");}
113 std::vector<size_type>
114 &_row_part = ref_row_part_.obj(),
115 &_col_part = ref_col_part_.obj(),
116 &_part_start = ref_part_start_.obj();
118 &_ele = ref_ele_.obj();
121 num_row_part_ = num_row_part;
122 num_col_part_ = num_col_part;
123 _row_part.resize(num_row_part_ + 1);
124 std::copy(row_part, row_part+ num_row_part_+1, _row_part.begin());
125 _col_part.resize(num_col_part_ + 1);
126 std::copy(col_part, col_part+ num_col_part_+1, _col_part.begin());
127 partition_order_ = partition_order;
129 _part_start.resize(num_row_part_ * num_col_part_+1);
130 _part_start.assign(_part_start.size(),0);
141 size_type *num_in_part = &_part_start[0] + 1;
147 *ivect_itr_end = ivect +
nz,
150 for(;ivect_itr != ivect_itr_end; ++ivect_itr, ++jvect_itr) {
155 if(i_org < 1 || i_org > rows || j_org < 1 || j_org > cols) {
156 std::ostringstream omsg;
157 omsg <<
"COOMatrixPartitionedView<...>::create_view() : "
158 " Error, element k = " << ivect_itr - ivect
159 <<
" in the non-permuted matrix"
160 " is out of range with rows = " << rows
161 <<
", cols = " << cols <<
", i = " << i_org
162 <<
", and j = " << j_org;
163 throw std::out_of_range(omsg.str());
167 j = inv_col_perm[j_org - 1];
169 if(i < 1 || i > rows || j < 1 || j > cols) {
170 std::ostringstream omsg;
171 omsg <<
"COOMatrixPartitionedView<...>::create_view() : "
172 " Error, element k = " << ivect_itr - ivect
173 <<
" in the permuted matrix"
174 " is out of range with rows = " << rows
175 <<
", cols = " << cols <<
", i = " << i
176 <<
", and j = " << j;
177 throw std::out_of_range(omsg.str());
180 size_type overall_p = overall_p_from_ij(_row_part,_col_part,i,j);
182 num_in_part[overall_p - 1]++;
191 {
for(
size_type i = 2; i < num_row_part_ * num_col_part_; ++i)
192 _part_start[i] += _part_start[i-1];}
198 {
for(
size_type i = num_row_part_ * num_col_part_; i > 0; --i)
199 _part_start[i] = _part_start[i-1];}
209 size_type *next_ele_insert = &_part_start[0] + 1;
215 *val_itr_end = val +
nz;
219 for(;val_itr != val_itr_end; ++val_itr, ++ivect_itr, ++jvect_itr) {
222 j = inv_col_perm[*jvect_itr - 1];
224 size_type overall_p = overall_p_from_ij(_row_part,_col_part,i,j);
226 _ele[next_ele_insert[overall_p - 1]++].initialize(val_itr,i,j);
237 template <
class T_Indice,
class T_Value>
249 template <
class T_Indice,
class T_Value>
253 num_row_part_ = num_col_part_ = 0;
254 if(ref_row_part_.has_ref_set()) ref_row_part_.obj().resize(0);
255 if(ref_col_part_.has_ref_set()) ref_col_part_.obj().resize(0);
256 if(ref_ele_.has_ref_set()) ref_ele_.obj().resize(0,
element_type());
257 if(ref_part_start_.has_ref_set()) ref_part_start_.obj().resize(0);
260 template <
class T_Indice,
class T_Value>
263 assert_initialized();
264 const std::vector<size_type> &_row_part = ref_row_part_.const_obj();
265 std::copy(_row_part.begin(), _row_part.end(), row_part);
268 template <
class T_Indice,
class T_Value>
271 assert_initialized();
272 const std::vector<size_type> &_col_part = ref_col_part_.const_obj();
273 std::copy(_col_part.begin(), _col_part.end(), col_part);
276 template <
class T_Indice,
class T_Value>
281 return std::upper_bound(part.begin(),part.end(),indice) - part.begin();
284 template <
class T_Indice,
class T_Value>
288 assert_initialized();
290 const std::vector<size_type>
291 &row_part = ref_row_part_.const_obj(),
292 &col_part = ref_col_part_.const_obj(),
293 &part_start = ref_part_start_.const_obj();
297 rng_overall_p = DenseLinAlgPack::full_range(rng_overall_p,1,num_row_part_*num_col_part_);
299 u_p = rng_overall_p.
ubound(),
300 l_r_p = imp_row_part_num(l_p),
301 l_c_p = imp_col_part_num(l_p),
302 u_r_p = imp_row_part_num(u_p),
303 u_c_p = imp_col_part_num(u_p);
306 rows = row_part[u_r_p] - row_part[l_r_p - 1],
307 cols = col_part[u_c_p] - col_part[l_c_p - 1],
308 nz = part_start[u_p] - part_start[l_p - 1];
310 *ele = &_ele[0] + part_start[l_p - 1];
312 row_offset = - (row_part[l_r_p - 1] - 1),
313 col_offset = - (col_part[l_c_p - 1] - 1);
320 #endif // COO_MATRIX_PARTITIONED_VIEW_CLASS_DEF_H
ref_vector_size_type ref_part_start_
RTOp_value_type value_type
std::vector< size_type > vector_size_type
Index ubound() const
Return upper bound of the range.
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return rows of a possible transposed matrix.
COO Matrix partitioning view class.
void bind(const COOMatrixPartitionedView &coom_view)
Bind the view of another partitioned matrix.
void get_row_part(indice_type row_part[]) const
get the array of row partitions.
std::vector< element_type > ele_type
const f_int f_dbl_prec const f_int const f_int const f_int jvect[]
. One-based subregion index range class.
void copy(const f_int &N, const f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
EPartitionOrder partition_order_
AbstractLinAlgPack::size_type size_type
ref_vector_size_type ref_row_part_
Sparse pointer element type for a COO matrix (val, ivect, jvect).
MemMngPack::RefCount< ele_type > ref_ele_type
const f_int f_dbl_prec const f_int const f_int ivect[]
ref_vector_size_type ref_col_part_
ptrdiff_t difference_type
Index lbound() const
Return lower bound of the range.
partition_type create_partition(Range1D rng_overall_p) const
size_type part_num(const vector_size_type &part, size_type indice)
void create_view(size_type rows, size_type cols, size_type nz, value_type val[], const indice_type ivect[], const indice_type jvect[], const size_type inv_row_perm[], const size_type inv_col_perm[], const size_type num_row_part, const size_type row_part[], const size_type num_col_part, const size_type col_part[], const EPartitionOrder partition_order)
Crete a view to a COO matrix.
void free()
Free the allocated memory and make uninitialized.
void get_col_part(indice_type col_part[]) const
get the array of column partitions.
Class for a partition or a set of continous partitions in a partitioned COO matrix.
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.