42 #ifndef COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H
43 #define COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H
45 #include "AbstractLinAlgPack_SparseCOOPtrElement.hpp"
46 #include "AbstractLinAlgPack_TransSparseCOOElementViewIter.hpp"
47 #include "MiRefCount.h"
49 namespace AbstractLinAlgPack {
51 namespace COOMatrixPartitionedViewUtilityPack {
52 template <
class T_Indice,
class T_Value>
class Partition;
183 template <
class T_Indice,
class T_Value>
252 : num_row_part_(0), num_col_part_(0)
254 create_view(rows, cols, nz, val, ivect, jvect, inv_row_perm, inv_col_perm, num_row_part
255 , row_part, num_col_part, col_part, partition_order);
342 ,
const size_type inv_row_perm[]
343 ,
const size_type inv_col_perm[]
345 ,
const size_type row_part[]
347 ,
const size_type col_part[]
376 size_type
rows()
const;
379 size_type
cols()
const;
382 size_type
nz()
const;
490 typedef std::vector<indice_type> vector_indice_type;
491 typedef std::vector<size_type> vector_size_type;
492 typedef std::vector<element_type> ele_type;
493 typedef MemMngPack::RefCount<
494 vector_indice_type> ref_vector_indice_type;
495 typedef MemMngPack::RefCount<
496 vector_size_type> ref_vector_size_type;
497 typedef MemMngPack::RefCount<
498 ele_type> ref_ele_type;
503 size_type num_row_part_;
506 size_type num_col_part_;
509 ref_vector_size_type ref_row_part_;
522 ref_vector_size_type ref_col_part_;
538 ref_ele_type ref_ele_;
563 ref_vector_size_type ref_part_start_;
582 void assert_initialized()
const;
584 size_type imp_overall_part_num(size_type row_p, size_type col_p)
const;
586 size_type imp_row_part_num(size_type overall_p)
const;
588 size_type imp_col_part_num(size_type overall_p)
const;
595 size_type part_num(
const vector_size_type& part, size_type indice);
598 size_type overall_p_from_ij(
const vector_size_type& row_part
599 ,
const vector_size_type& col_part, size_type i, size_type j);
611 namespace COOMatrixPartitionedViewUtilityPack {
632 template <
class T_Indice,
class T_Value>
761 void assert_initialized()
const;
791 template <
class T_Indice,
class T_Value>
809 , std::random_access_iterator_tag
810 ,
typename element_type::indice_type
816 , std::random_access_iterator_tag
817 ,
typename element_type::indice_type
893 template<
class T_Indice,
class T_Value>
898 transposed_partition_type;
899 return transposed_partition_type(part);
905 namespace COOMatrixPartitionedViewUtilityPack {
912 template <
class T_Indice,
class T_Value>
914 : rows_(0), cols_(0), nz_(0), ele_(0), row_offset_(0), col_offset_(0)
917 template <
class T_Indice,
class T_Value>
925 : rows_(rows), cols_(cols), nz_(nz), ele_(ele), row_offset_(row_offset)
926 , col_offset_(col_offset)
929 template <
class T_Indice,
class T_Value>
942 row_offset_ = row_offset;
943 col_offset_ = col_offset;
946 template <
class T_Indice,
class T_Value>
948 initialize(partition.rows_,partition.cols_,partition.nz_,partition.ele_
949 ,partition.row_offset_,partition.col_offset_);
954 template <
class T_Indice,
class T_Value>
961 template <
class T_Indice,
class T_Value>
968 template <
class T_Indice,
class T_Value>
975 template <
class T_Indice,
class T_Value>
982 template <
class T_Indice,
class T_Value>
989 template <
class T_Indice,
class T_Value>
993 assert_initialized();
997 template <
class T_Indice,
class T_Value>
1001 assert_initialized();
1005 template <
class T_Indice,
class T_Value>
1009 assert_initialized();
1013 template <
class T_Indice,
class T_Value>
1017 assert_initialized();
1023 template <
class T_Indice,
class T_Value>
1026 throw std::logic_error(
"Partition<...> :"
1027 "The COO matrix was not initizlized");
1036 template <
class T_Indice,
class T_Value>
1038 : partition_(partition)
1041 template <
class T_Indice,
class T_Value>
1043 partition_.bind(partition);
1048 template <
class T_Indice,
class T_Value>
1052 return partition_.cols();
1055 template <
class T_Indice,
class T_Value>
1059 return partition_.rows();
1062 template <
class T_Indice,
class T_Value>
1066 return partition_.nz();
1069 template <
class T_Indice,
class T_Value>
1073 return partition_.col_offset();
1076 template <
class T_Indice,
class T_Value>
1080 return partition_.row_offset();
1083 template <
class T_Indice,
class T_Value>
1087 return iterator(partition_.begin());
1090 template <
class T_Indice,
class T_Value>
1097 template <
class T_Indice,
class T_Value>
1104 template <
class T_Indice,
class T_Value>
1119 template <
class T_Indice,
class T_Value>
1121 : num_row_part_(0), num_col_part_(0)
1124 template <
class T_Indice,
class T_Value>
1126 return ref_ele_.has_ref_set();
1131 template <
class T_Indice,
class T_Value>
1135 assert_initialized();
1136 const std::vector<size_type> &row_part = ref_row_part_.const_obj();
1137 return row_part[num_row_part_] - row_part[0];
1140 template <
class T_Indice,
class T_Value>
1144 assert_initialized();
1145 const std::vector<size_type> &col_part = ref_col_part_.const_obj();
1146 return col_part[num_col_part_] - col_part[0];
1149 template <
class T_Indice,
class T_Value>
1153 assert_initialized();
1154 return ref_part_start_.const_obj()[num_row_part_ * num_col_part_];
1157 template <
class T_Indice,
class T_Value>
1161 return num_row_part_;
1164 template <
class T_Indice,
class T_Value>
1168 return num_col_part_;
1171 template <
class T_Indice,
class T_Value>
1175 assert_initialized();
1176 return partition_order_;
1179 template <
class T_Indice,
class T_Value>
1183 assert_initialized();
1184 return imp_overall_part_num(row_p, col_p);
1187 template <
class T_Indice,
class T_Value>
1191 assert_initialized();
1192 return imp_row_part_num(overall_p);
1195 template <
class T_Indice,
class T_Value>
1199 assert_initialized();
1200 return imp_col_part_num(overall_p);
1219 template <
class T_Indice,
class T_Value>
1226 template <
class T_Indice,
class T_Value>
1233 template <
class T_Indice,
class T_Value>
1237 return partition(
Range1D(overall_p,overall_p));
1240 template <
class T_Indice,
class T_Value>
1244 return partition(
Range1D(overall_p,overall_p));
1247 template <
class T_Indice,
class T_Value>
1251 return partition(overall_part_num(row_p,col_p));
1254 template <
class T_Indice,
class T_Value>
1258 return partition(overall_part_num(row_p,col_p));
1261 template <
class T_Indice,
class T_Value>
1265 return create_partition(rng_overall_p);
1268 template <
class T_Indice,
class T_Value>
1272 return create_partition(rng_overall_p);
1277 template <
class T_Indice,
class T_Value>
1279 if(!is_initialized())
1280 throw UninitializedException(
"COOMatrixPartitionedView<..>::assert_initialized() :"
1281 " The partitioned view has not been initialized.");
1284 template <
class T_Indice,
class T_Value>
1286 COOMatrixPartitionedView<T_Indice,T_Value>::imp_overall_part_num(
size_type row_p,
size_type col_p)
const
1288 return (partition_order_ == PARTITION_BY_ROW) ?
1289 (row_p - 1) * num_col_part_ + col_p :
1290 (col_p - 1) * num_row_part_ + row_p;
1293 template <
class T_Indice,
class T_Value>
1295 COOMatrixPartitionedView<T_Indice,T_Value>::imp_row_part_num(
size_type overall_p)
const
1297 return (partition_order_ == PARTITION_BY_ROW) ?
1298 (overall_p - 1) / num_col_part_ + 1 :
1299 (overall_p - 1) % num_row_part_ + 1 ;
1302 template <
class T_Indice,
class T_Value>
1304 COOMatrixPartitionedView<T_Indice,T_Value>::imp_col_part_num(
size_type overall_p)
const
1306 return (partition_order_ == PARTITION_BY_COL) ?
1307 (overall_p - 1) / num_row_part_ + 1 :
1308 (overall_p - 1) % num_col_part_ + 1 ;
1311 template <
class T_Indice,
class T_Value>
1313 COOMatrixPartitionedView<T_Indice,T_Value>::overall_p_from_ij(
const vector_size_type& row_part
1316 return imp_overall_part_num( part_num(row_part,i)
1317 , part_num(col_part,j) );
1322 #endif // COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H
ptrdiff_t difference_type
TransposedPartition(const partition_type &partition)
Construct with the partition initialized.
difference_type col_offset() const
TransSparseCOOElementViewIter< const element_type *, std::random_access_iterator_tag, typename element_type::indice_type, const typename element_type::value_type &, difference_type > const_iterator
size_type cols() const
return the number of columns in the total view
void bind(const partition_type &partition)
bind to a partion.
size_type overall_part_num(size_type row_p, size_type col_p) const
Returns the overall partition number (1 to num_row_part() * num_col_part()#) given the row (1 to num_...
bool is_initialized() const
Returns true if a view has been initialized.
size_type row_part_num(size_type overall_p) const
Returns the row parition number (1-based) given the overall partition number (1-based) ...
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
void initialize(size_type rows, size_type cols, size_type nz, element_type *ele, difference_type row_offset, difference_type col_offset)
Initialize the COO matrix.
partition_type partition(size_type overall_p)
Return a partition object for a parition given its overall partition number (1-based).
size_type rows() const
return the number of rows of the total view
COO Matrix partitioning view class.
difference_type row_offset() const
void bind(const COOMatrixPartitionedView &coom_view)
Bind the view of another partitioned matrix.
EPartitionOrder partition_order() const
Returns whether the paritions or sorted by row or by column.
void get_row_part(indice_type row_part[]) const
get the array of row partitions.
COOMatrixPartitionedViewUtilityPack::TransposedPartition< T_Indice, T_Value > transposed_partition_type
const element_type * const_iterator
TransSparseCOOElementViewIter< element_type *, std::random_access_iterator_tag, typename element_type::indice_type, typename element_type::value_type &, difference_type > iterator
partition_type operator()()
Return a partition object for the entire view.
Partition< T_Indice, T_Value > partition_type
Partition< T_Indice, T_Value > partition_type
Templateded iterator for iterating through a set of COO Matix elements but viewing them in transpose...
void bind(const partition_type &partition)
bind to a partion.
Class for the transpose of a Partition.
AbstractLinAlgPack::size_type size_type
Sparse pointer element type for a COO matrix (val, ivect, jvect).
COOMatrixPartitionedView(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)
Construct with a view to a partitioned COO matrix set.
COOMatrixPartitionedView()
Construct with no view set.
difference_type row_offset() const
ptrdiff_t difference_type
AbstractLinAlgPack::size_type size_type
size_type col_part_num(size_type overall_p) const
Returns the column parition number (1-based) given the overall partition number (1-based) ...
size_type num_col_part() const
return the number column partitions
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.
size_type nz() const
return the number of nonzero elements in the total view
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.
AbstractLinAlgPack::size_type size_type
SparseCOOPtrElement< T_Indice, T_Value > element_type
COOMatrixPartitionedViewUtilityPack::Partition< T_Indice, T_Value > partition_type
SparseCOOPtrElement< T_Indice, T_Value > element_type
ptrdiff_t difference_type
Partition()
Constructs an uninitialized partition view.
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
size_type num_row_part() const
return the number row partitions
difference_type col_offset() const