|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H 00030 #define COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H 00031 00032 #include "AbstractLinAlgPack_SparseCOOPtrElement.hpp" 00033 #include "AbstractLinAlgPack_TransSparseCOOElementViewIter.hpp" 00034 #include "MiRefCount.h" 00035 00036 namespace AbstractLinAlgPack { 00037 00038 namespace COOMatrixPartitionedViewUtilityPack { 00039 template <class T_Indice, class T_Value> class Partition; 00040 template <class T_Indice, class T_Value> class TransposedPartition; 00041 } 00042 00043 // /////////////////////////////////////////////////////////////////////////////////////// 00044 // /////////////////////////////////////////////////////////////////////////////////////// 00170 template <class T_Indice, class T_Value> 00171 class COOMatrixPartitionedView { 00172 public: 00173 00174 // ////////////////////////////////////////////////////////////////////////// 00177 00179 typedef COOMatrixPartitionedViewUtilityPack::Partition<T_Indice,T_Value> 00180 partition_type; 00182 typedef COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00183 transposed_partition_type; 00185 typedef T_Indice indice_type; 00187 typedef AbstractLinAlgPack::size_type size_type; 00189 typedef ptrdiff_t difference_type; 00191 enum EPartitionOrder { PARTITION_BY_ROW, PARTITION_BY_COL }; 00193 class UninitializedException: public std::logic_error 00194 {public: UninitializedException(const std::string& what_arg) : std::logic_error(what_arg) {}}; 00195 00197 00198 // /////////////////////////////////////////////////////////////////////////////////////// 00201 00208 00218 COOMatrixPartitionedView(); 00219 00224 COOMatrixPartitionedView( 00225 size_type rows 00226 , size_type cols 00227 , size_type nz 00228 , value_type val[] 00229 , const indice_type ivect[] 00230 , const indice_type jvect[] 00231 , const size_type inv_row_perm[] 00232 , const size_type inv_col_perm[] 00233 , const size_type num_row_part 00234 , const size_type row_part[] 00235 , const size_type num_col_part 00236 , const size_type col_part[] 00237 , const EPartitionOrder partition_order ) 00238 00239 : num_row_part_(0), num_col_part_(0) 00240 { 00241 create_view(rows, cols, nz, val, ivect, jvect, inv_row_perm, inv_col_perm, num_row_part 00242 , row_part, num_col_part, col_part, partition_order); 00243 } 00244 // I tried defining this function else where as both an inlined and 00245 // noninlined function but MS VC++ 5.0 generated 00246 // a linking error saying that it could not find this function. 00247 // ToDo: Investagate this problem further at a latter time. 00248 00322 void create_view( 00323 size_type rows 00324 , size_type cols 00325 , size_type nz 00326 , value_type val[] 00327 , const indice_type ivect[] 00328 , const indice_type jvect[] 00329 , const size_type inv_row_perm[] 00330 , const size_type inv_col_perm[] 00331 , const size_type num_row_part 00332 , const size_type row_part[] 00333 , const size_type num_col_part 00334 , const size_type col_part[] 00335 , const EPartitionOrder partition_order ); 00336 00342 void bind(const COOMatrixPartitionedView& coom_view); 00343 00345 void free(); 00346 00348 bool is_initialized() const; 00349 00351 00361 00363 size_type rows() const; 00364 00366 size_type cols() const; 00367 00369 size_type nz() const; 00370 00372 size_type num_row_part() const; 00373 00375 size_type num_col_part() const; 00376 00382 void get_row_part(indice_type row_part[]) const; 00383 00389 void get_col_part(indice_type col_part[]) const; 00390 00392 EPartitionOrder partition_order() const; 00393 00397 size_type overall_part_num(size_type row_p, size_type col_p) const; 00398 00400 size_type row_part_num(size_type overall_p) const; 00401 00403 size_type col_part_num(size_type overall_p) const; 00404 00406 00416 00417 // /// 00418 // /** Allow an implicit conversion from a COOMatrixPartitionedView 00419 // * to a partition_type object. 00420 // * 00421 // * This conversion is equivalent to calling #partition(Range1D())#. 00422 // */ 00423 // operator partition_type(); 00424 // 00425 // /// 00426 // operator const partition_type() const; 00427 00430 partition_type operator()(); 00431 00433 const partition_type operator()() const; 00434 00437 partition_type partition(size_type overall_p); 00438 00440 const partition_type partition(size_type overall_p) const; 00441 00445 partition_type partition(size_type row_p, size_type col_p); 00446 00448 const partition_type partition(size_type row_p, size_type col_p) const; 00449 00463 partition_type partition(Range1D rng_overall_p); 00464 00466 const partition_type partition(Range1D rng_overall_p) const; 00467 00469 00471 00472 private: 00473 // //////////////////////////////////////////////////////////////// 00474 // Private types 00475 00476 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00477 typedef std::vector<indice_type> vector_indice_type; 00478 typedef std::vector<size_type> vector_size_type; 00479 typedef std::vector<element_type> ele_type; 00480 typedef MemMngPack::RefCount< 00481 vector_indice_type> ref_vector_indice_type; 00482 typedef MemMngPack::RefCount< 00483 vector_size_type> ref_vector_size_type; 00484 typedef MemMngPack::RefCount< 00485 ele_type> ref_ele_type; 00486 00487 // /////////////////////////////////////////////////////////////// 00488 // Private data members 00489 00490 size_type num_row_part_; 00491 // The number of partions the COO matrix is sliced up into by rows. 00492 00493 size_type num_col_part_; 00494 // The number of partions the COO matrix is sliced up into by columns. 00495 00496 ref_vector_size_type ref_row_part_; 00497 // 00498 // row_part = { row_p_1_i, row_p_2_i,...,row_p_nrp_i, row_p_nrp_last_i + 1 } 00499 // where: row_p_k_i is the row indice for row partition k 00500 // nrp = num_row_part 00501 // row_p_nrp_last_i is the last row indice in the last row partition 00502 // 00503 // vector (length num_row_part_ + 1) of row indices for the start of the row partitions. 00504 // row_part[i - 1] is the row indice for the start of the ith row partition (i = 1,...,num_row_part_). 00505 // The last indice gives the row indice that is one past the last row of the last 00506 // row partition. It is included for the efficient calculation of the number of rows 00507 // in a partition or a set of partitions. 00508 00509 ref_vector_size_type ref_col_part_; 00510 // 00511 // col_part = { col_p_1_i, col_p_2_i,...,col_p_nrp_i, col_p_nrp_last_i + 1 } 00512 // where: col_p_k_i is the col indice for col partition k 00513 // nrp = num_col_part 00514 // col_p_nrp_last_i is the last col indice in the last col partition 00515 // 00516 // vector (length num_row_part_ + 1) of column indices for the start of the columns partitions. 00517 // col_part[j - 1] is the column indice for the start of the jth column partition (j = 1,...,num_col_part_). 00518 // The last indice gives the column indice that is one past the last column of the last 00519 // column partition. It is included for the efficient calculation of the number of columns 00520 // in a partition or a set of partitions. 00521 00522 EPartitionOrder partition_order_; 00523 // Specifies wheather the partitions are to be orded by columns or rows 00524 00525 ref_ele_type ref_ele_; 00526 // ToDo: replace with a RefCount<std::vector<element_type>> when you get compiler bug fix. 00527 // The storage array (dynamically allocated) for the elements in the COO matrix. 00528 // The elements in this array are ordered into partitions defined by the partition_order_. 00529 // 00530 // ele_ 00531 // --------------------- 00532 // |pval row_i col_i| 00533 // || | | | | ||- 00534 // || | | | | || parition 1 00535 // || | | | | || 00536 // || | | | | ||- 00537 // || | | | | || parition 2 00538 // || | | | | || 00539 // || | | | | ||- 00540 // || | | | | || . 00541 // || | | | | || . 00542 // || | | | | || . 00543 // || | | | | || 00544 // || | | | | ||- 00545 // || | | | | || partition num_row_part * num_col_part 00546 // || | | | | || 00547 // || | | | | ||- 00548 // --------------------- 00549 00550 ref_vector_size_type ref_part_start_; 00551 // 00552 // part_start = { start_1 = 0, start_2,..., start_n, total_nz } 00553 // 00554 // vector (length num_row_part * num_col_part_ + 1) of the start for the elements in 00555 // each partition. ele_[part_start_[overall_p - 1]] gives the first element of partion 00556 // overal_p and ele_[part_start_[overall_p] - 1] gives the last element in the partition. 00557 // This array is also used to calculate the number of nonzero elements in each parition 00558 // and in the overall partition. The last element part_start_[num_row_part * num_col_part_] 00559 // gives the total number of nonzeros in all of the partitions and is also used 00560 // to allow the calculation of the number of nonzero elements in the last partition. 00561 00562 // When the view is uninitialized then ele_, row_part_, col_part_ and part_start_ will 00563 // all uninitialized. 00564 00565 // /////////////////////////////////////////////////////////////// 00566 // Private member functions 00567 00568 // assert that the object is initialized 00569 void assert_initialized() const; 00570 00571 size_type imp_overall_part_num(size_type row_p, size_type col_p) const; 00572 00573 size_type imp_row_part_num(size_type overall_p) const; 00574 00575 size_type imp_col_part_num(size_type overall_p) const; 00576 00577 // Return the partition number given an indice. 00578 // Passing the partition vector is an optimization 00579 // that allows us to only call .obj() once 00580 // on the reference object and thus same some 00581 // unnecessary work. 00582 size_type part_num(const vector_size_type& part, size_type indice); 00583 00584 // Return the overall partition number 00585 size_type overall_p_from_ij(const vector_size_type& row_part 00586 , const vector_size_type& col_part, size_type i, size_type j); 00587 00588 // Return a non-const partition. This is the function 00589 // that implements all partition creations. 00590 partition_type create_partition(Range1D rng_overall_p) const; 00591 00592 // Not defined and not to be called 00593 COOMatrixPartitionedView& operator=(const COOMatrixPartitionedView&); 00594 00595 }; // end class COOMatrixPartitionedView 00596 00597 00598 namespace COOMatrixPartitionedViewUtilityPack { 00599 00604 00605 // /////////////////////////////////////////////////////////////////////// 00606 // /////////////////////////////////////////////////////////////////////// 00619 template <class T_Indice, class T_Value> 00620 class Partition { 00621 public: 00622 // ///////////////////////////////////////////////////// 00625 00627 typedef AbstractLinAlgPack::size_type size_type; 00629 typedef Partition<T_Indice,T_Value> partition_type; 00631 typedef ptrdiff_t difference_type; 00633 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00635 typedef element_type* iterator; 00637 typedef const element_type* const_iterator; 00638 00640 00641 // ///////////////////////////////////////////////////// 00644 00651 00663 Partition(); 00664 00669 Partition( 00670 size_type rows 00671 , size_type cols 00672 , size_type nz 00673 , element_type* ele 00674 , difference_type row_offset 00675 , difference_type col_offset ); 00676 00688 void initialize( 00689 size_type rows 00690 , size_type cols 00691 , size_type nz 00692 , element_type* ele 00693 , difference_type row_offset 00694 , difference_type col_offset ); 00695 00700 void bind(const partition_type& partition); 00701 00703 00706 00708 size_type rows() const; 00710 size_type cols() const ; 00712 size_type nz() const; 00714 difference_type row_offset() const; 00716 difference_type col_offset() const; 00718 iterator begin(); 00720 const_iterator begin() const; 00722 iterator end(); 00724 const_iterator end() const; 00725 00727 00729 00730 private: 00731 // ////////////////////////////////////////////////////// 00732 // Private types 00733 00734 // ////////////////////////////////////////////////////// 00735 // Private data members 00736 00737 size_type rows_, // The number of rows in this COO matrix 00738 cols_, // The number of columns in this COO matrix 00739 nz_; // The number of nonzero elements in this COO matrix 00740 element_type *ele_; // pointer to array of elements in this COO matrix 00741 difference_type row_offset_, // offset for each row indice stored in ele 00742 col_offset_; // offset for each column indice stored in ele 00743 00744 // ////////////////////////////////////////////////////// 00745 // Private member functions 00746 00747 // assert that we are initialized 00748 void assert_initialized() const; 00749 00750 // not defined and not to be called 00751 Partition& operator=(const Partition&); 00752 00753 }; // end class Partition 00754 00755 // ///////////////////////////////////////////////////////////////////////////////////// 00756 // ///////////////////////////////////////////////////////////////////////////////////// 00778 template <class T_Indice, class T_Value> 00779 class TransposedPartition { 00780 public: 00781 // ///////////////////////////////////////////////////// 00784 00786 typedef Partition<T_Indice,T_Value> partition_type; 00788 typedef AbstractLinAlgPack::size_type size_type; 00790 typedef ptrdiff_t difference_type; 00792 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00794 typedef TransSparseCOOElementViewIter< 00795 element_type* 00796 , std::random_access_iterator_tag 00797 , typename element_type::indice_type 00798 , typename element_type::value_type& 00799 , difference_type> iterator; 00801 typedef TransSparseCOOElementViewIter< 00802 const element_type* 00803 , std::random_access_iterator_tag 00804 , typename element_type::indice_type 00805 , const typename element_type::value_type& 00806 , difference_type> const_iterator; 00807 00809 00810 // ///////////////////////////////////////////////////// 00813 00820 00825 TransposedPartition(const partition_type& partition); 00826 00831 void bind(const partition_type& partition); 00832 00834 00837 00839 size_type rows() const; 00841 size_type cols() const; 00843 size_type nz() const; 00845 difference_type row_offset() const; 00847 difference_type col_offset() const; 00849 iterator begin(); 00851 const_iterator begin() const; 00853 iterator end(); 00855 const_iterator end() const; 00856 00858 00860 00861 private: 00862 partition_type partition_; // actually stores a partition object. 00863 00864 // Not defined and not to be called 00865 TransposedPartition& operator=(const TransposedPartition&); 00866 00867 }; // end class TransposedPartition 00868 00869 // end COOMatrixPartitionedViewUtilityPack 00871 00872 } // end namespace COOMatrixPartitionedViewUtilityPack 00873 00874 00875 // ////////////////////////////////////////////////////////////////////////// 00876 // Nonmember functions 00877 00880 template<class T_Indice, class T_Value> 00881 inline COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00882 trans(COOMatrixPartitionedViewUtilityPack::Partition<T_Indice,T_Value>& part) 00883 { 00884 typedef COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00885 transposed_partition_type; 00886 return transposed_partition_type(part); 00887 } 00888 00889 // /////////////////////////////////////////////////////////////////////////// 00890 // Inline member function definitions 00891 00892 namespace COOMatrixPartitionedViewUtilityPack { 00893 00894 // /////////////////////////////////////////////////////////////////////////// 00895 // Inline members for class COOMatrixPartitionedViewUtilityPack::Partition<> 00896 00897 // Constructors and initializes 00898 00899 template <class T_Indice, class T_Value> 00900 inline Partition<T_Indice,T_Value>::Partition() 00901 : rows_(0), cols_(0), nz_(0), ele_(0), row_offset_(0), col_offset_(0) 00902 {} 00903 00904 template <class T_Indice, class T_Value> 00905 inline Partition<T_Indice,T_Value>::Partition( 00906 size_type rows 00907 , size_type cols 00908 , size_type nz 00909 , element_type* ele 00910 , difference_type row_offset 00911 , difference_type col_offset ) 00912 : rows_(rows), cols_(cols), nz_(nz), ele_(ele), row_offset_(row_offset) 00913 , col_offset_(col_offset) 00914 {} 00915 00916 template <class T_Indice, class T_Value> 00917 inline void Partition<T_Indice,T_Value>::initialize( 00918 size_type rows 00919 , size_type cols 00920 , size_type nz 00921 , element_type* ele 00922 , difference_type row_offset 00923 , difference_type col_offset ) 00924 { 00925 rows_ = rows; 00926 cols_ = cols; 00927 nz_ = nz; 00928 ele_ = ele; 00929 row_offset_ = row_offset; 00930 col_offset_ = col_offset; 00931 } 00932 00933 template <class T_Indice, class T_Value> 00934 inline void Partition<T_Indice,T_Value>::bind(const partition_type& partition) { 00935 initialize(partition.rows_,partition.cols_,partition.nz_,partition.ele_ 00936 ,partition.row_offset_,partition.col_offset_); 00937 } 00938 00939 // COOMatrixTemplateInterface interface 00940 00941 template <class T_Indice, class T_Value> 00942 inline Partition<T_Indice,T_Value>::size_type 00943 Partition<T_Indice,T_Value>::rows() const 00944 { 00945 return rows_; 00946 } 00947 00948 template <class T_Indice, class T_Value> 00949 inline Partition<T_Indice,T_Value>::size_type 00950 Partition<T_Indice,T_Value>::cols() const 00951 { 00952 return cols_; 00953 } 00954 00955 template <class T_Indice, class T_Value> 00956 inline Partition<T_Indice,T_Value>::size_type 00957 Partition<T_Indice,T_Value>::nz() const 00958 { 00959 return nz_; 00960 } 00961 00962 template <class T_Indice, class T_Value> 00963 inline Partition<T_Indice,T_Value>::difference_type 00964 Partition<T_Indice,T_Value>::row_offset() const 00965 { 00966 return row_offset_; 00967 } 00968 00969 template <class T_Indice, class T_Value> 00970 inline Partition<T_Indice,T_Value>::difference_type 00971 Partition<T_Indice,T_Value>::col_offset() const 00972 { 00973 return col_offset_; 00974 } 00975 00976 template <class T_Indice, class T_Value> 00977 inline Partition<T_Indice,T_Value>::iterator 00978 Partition<T_Indice,T_Value>::begin() 00979 { 00980 assert_initialized(); 00981 return ele_; 00982 } 00983 00984 template <class T_Indice, class T_Value> 00985 inline Partition<T_Indice,T_Value>::const_iterator 00986 Partition<T_Indice,T_Value>::begin() const 00987 { 00988 assert_initialized(); 00989 return ele_; 00990 } 00991 00992 template <class T_Indice, class T_Value> 00993 inline Partition<T_Indice,T_Value>::iterator 00994 Partition<T_Indice,T_Value>::end() 00995 { 00996 assert_initialized(); 00997 return ele_ + nz_; 00998 } 00999 01000 template <class T_Indice, class T_Value> 01001 inline Partition<T_Indice,T_Value>::const_iterator 01002 Partition<T_Indice,T_Value>::end() const 01003 { 01004 assert_initialized(); 01005 return ele_ + nz_; 01006 } 01007 01008 // Private member functions 01009 01010 template <class T_Indice, class T_Value> 01011 inline void Partition<T_Indice,T_Value>::assert_initialized() const { 01012 if(!ele_) 01013 throw std::logic_error("Partition<...> :" 01014 "The COO matrix was not initizlized"); 01015 } 01016 01017 01018 // /////////////////////////////////////////////////////////////////////////// 01019 // Inline members for class COOMatrixPartitionedViewUtilityPack::TransposedPartition<> 01020 01021 // Constructors and initializes 01022 01023 template <class T_Indice, class T_Value> 01024 inline TransposedPartition<T_Indice,T_Value>::TransposedPartition(const partition_type& partition) 01025 : partition_(partition) 01026 {} 01027 01028 template <class T_Indice, class T_Value> 01029 inline void TransposedPartition<T_Indice,T_Value>::bind(const partition_type& partition) { 01030 partition_.bind(partition); 01031 } 01032 01033 // COOMatrixTemplateInterface interface 01034 01035 template <class T_Indice, class T_Value> 01036 inline TransposedPartition<T_Indice,T_Value>::size_type 01037 TransposedPartition<T_Indice,T_Value>::rows() const 01038 { 01039 return partition_.cols(); 01040 } 01041 01042 template <class T_Indice, class T_Value> 01043 inline TransposedPartition<T_Indice,T_Value>::size_type 01044 TransposedPartition<T_Indice,T_Value>::cols() const 01045 { 01046 return partition_.rows(); 01047 } 01048 01049 template <class T_Indice, class T_Value> 01050 inline TransposedPartition<T_Indice,T_Value>::size_type 01051 TransposedPartition<T_Indice,T_Value>::nz() const 01052 { 01053 return partition_.nz(); 01054 } 01055 01056 template <class T_Indice, class T_Value> 01057 inline TransposedPartition<T_Indice,T_Value>::difference_type 01058 TransposedPartition<T_Indice,T_Value>::row_offset() const 01059 { 01060 return partition_.col_offset(); 01061 } 01062 01063 template <class T_Indice, class T_Value> 01064 inline TransposedPartition<T_Indice,T_Value>::difference_type 01065 TransposedPartition<T_Indice,T_Value>::col_offset() const 01066 { 01067 return partition_.row_offset(); 01068 } 01069 01070 template <class T_Indice, class T_Value> 01071 inline TransposedPartition<T_Indice,T_Value>::iterator 01072 TransposedPartition<T_Indice,T_Value>::begin() 01073 { 01074 return iterator(partition_.begin()); 01075 } 01076 01077 template <class T_Indice, class T_Value> 01078 inline TransposedPartition<T_Indice,T_Value>::const_iterator 01079 TransposedPartition<T_Indice,T_Value>::begin() const 01080 { 01081 return const_iterator(partition_.begin()); 01082 } 01083 01084 template <class T_Indice, class T_Value> 01085 inline TransposedPartition<T_Indice,T_Value>::iterator 01086 TransposedPartition<T_Indice,T_Value>::end() 01087 { 01088 return iterator(partition_.end()); 01089 } 01090 01091 template <class T_Indice, class T_Value> 01092 inline TransposedPartition<T_Indice,T_Value>::const_iterator 01093 TransposedPartition<T_Indice,T_Value>::end() const 01094 { 01095 return const_iterator(partition_.end()); 01096 } 01097 01098 } // end namespace COOMatrixPartitionViewUtilityPack 01099 01100 01101 // /////////////////////////////////////////////////////////////////////////// 01102 // Inline members for class COOMatrixPartitionedView<> 01103 01104 // Constructors and initializes 01105 01106 template <class T_Indice, class T_Value> 01107 inline COOMatrixPartitionedView<T_Indice,T_Value>::COOMatrixPartitionedView() 01108 : num_row_part_(0), num_col_part_(0) 01109 {} 01110 01111 template <class T_Indice, class T_Value> 01112 inline bool COOMatrixPartitionedView<T_Indice,T_Value>::is_initialized() const { 01113 return ref_ele_.has_ref_set(); 01114 } 01115 01116 // Partitioning information 01117 01118 template <class T_Indice, class T_Value> 01119 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01120 COOMatrixPartitionedView<T_Indice,T_Value>::rows() const 01121 { 01122 assert_initialized(); 01123 const std::vector<size_type> &row_part = ref_row_part_.const_obj(); 01124 return row_part[num_row_part_] - row_part[0]; 01125 } 01126 01127 template <class T_Indice, class T_Value> 01128 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01129 COOMatrixPartitionedView<T_Indice,T_Value>::cols() const 01130 { 01131 assert_initialized(); 01132 const std::vector<size_type> &col_part = ref_col_part_.const_obj(); 01133 return col_part[num_col_part_] - col_part[0]; 01134 } 01135 01136 template <class T_Indice, class T_Value> 01137 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01138 COOMatrixPartitionedView<T_Indice,T_Value>::nz() const 01139 { 01140 assert_initialized(); 01141 return ref_part_start_.const_obj()[num_row_part_ * num_col_part_]; 01142 } 01143 01144 template <class T_Indice, class T_Value> 01145 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01146 COOMatrixPartitionedView<T_Indice,T_Value>::num_row_part() const 01147 { 01148 return num_row_part_; 01149 } 01150 01151 template <class T_Indice, class T_Value> 01152 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01153 COOMatrixPartitionedView<T_Indice,T_Value>::num_col_part() const 01154 { 01155 return num_col_part_; 01156 } 01157 01158 template <class T_Indice, class T_Value> 01159 inline COOMatrixPartitionedView<T_Indice,T_Value>::EPartitionOrder 01160 COOMatrixPartitionedView<T_Indice,T_Value>::partition_order() const 01161 { 01162 assert_initialized(); 01163 return partition_order_; 01164 } 01165 01166 template <class T_Indice, class T_Value> 01167 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01168 COOMatrixPartitionedView<T_Indice,T_Value>::overall_part_num(size_type row_p, size_type col_p) const 01169 { 01170 assert_initialized(); 01171 return imp_overall_part_num(row_p, col_p); 01172 } 01173 01174 template <class T_Indice, class T_Value> 01175 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01176 COOMatrixPartitionedView<T_Indice,T_Value>::row_part_num(size_type overall_p) const 01177 { 01178 assert_initialized(); 01179 return imp_row_part_num(overall_p); 01180 } 01181 01182 template <class T_Indice, class T_Value> 01183 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01184 COOMatrixPartitionedView<T_Indice,T_Value>::col_part_num(size_type overall_p) const 01185 { 01186 assert_initialized(); 01187 return imp_col_part_num(overall_p); 01188 } 01189 01190 // Partition access 01191 01192 //template <class T_Indice, class T_Value> 01193 //inline COOMatrixPartitionedView<T_Indice,T_Value>::operator 01194 //COOMatrixPartitionedView<T_Indice,T_Value>::partition_type() 01195 //{ 01196 // return partition(Range1D()); 01197 //} 01198 01199 //template <class T_Indice, class T_Value> 01200 //inline COOMatrixPartitionedView<T_Indice,T_Value>::operator 01201 //const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type() const 01202 //{ 01203 // return partition(Range1D()); 01204 //} 01205 01206 template <class T_Indice, class T_Value> 01207 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01208 COOMatrixPartitionedView<T_Indice,T_Value>::operator()() 01209 { 01210 return partition(Range1D()); 01211 } 01212 01213 template <class T_Indice, class T_Value> 01214 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01215 COOMatrixPartitionedView<T_Indice,T_Value>::operator()() const 01216 { 01217 return partition(Range1D()); 01218 } 01219 01220 template <class T_Indice, class T_Value> 01221 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01222 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type overall_p) 01223 { 01224 return partition(Range1D(overall_p,overall_p)); 01225 } 01226 01227 template <class T_Indice, class T_Value> 01228 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01229 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type overall_p) const 01230 { 01231 return partition(Range1D(overall_p,overall_p)); 01232 } 01233 01234 template <class T_Indice, class T_Value> 01235 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01236 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type row_p, size_type col_p) 01237 { 01238 return partition(overall_part_num(row_p,col_p)); 01239 } 01240 01241 template <class T_Indice, class T_Value> 01242 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01243 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type row_p, size_type col_p) const 01244 { 01245 return partition(overall_part_num(row_p,col_p)); 01246 } 01247 01248 template <class T_Indice, class T_Value> 01249 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01250 COOMatrixPartitionedView<T_Indice,T_Value>::partition(Range1D rng_overall_p) 01251 { 01252 return create_partition(rng_overall_p); 01253 } 01254 01255 template <class T_Indice, class T_Value> 01256 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01257 COOMatrixPartitionedView<T_Indice,T_Value>::partition(Range1D rng_overall_p) const 01258 { 01259 return create_partition(rng_overall_p); 01260 } 01261 01262 // Private member functions 01263 01264 template <class T_Indice, class T_Value> 01265 inline void COOMatrixPartitionedView<T_Indice,T_Value>::assert_initialized() const { 01266 if(!is_initialized()) 01267 throw UninitializedException("COOMatrixPartitionedView<..>::assert_initialized() :" 01268 " The partitioned view has not been initialized."); 01269 } 01270 01271 template <class T_Indice, class T_Value> 01272 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01273 COOMatrixPartitionedView<T_Indice,T_Value>::imp_overall_part_num(size_type row_p, size_type col_p) const 01274 { 01275 return (partition_order_ == PARTITION_BY_ROW) ? 01276 (row_p - 1) * num_col_part_ + col_p : 01277 (col_p - 1) * num_row_part_ + row_p; 01278 } 01279 01280 template <class T_Indice, class T_Value> 01281 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01282 COOMatrixPartitionedView<T_Indice,T_Value>::imp_row_part_num(size_type overall_p) const 01283 { 01284 return (partition_order_ == PARTITION_BY_ROW) ? 01285 (overall_p - 1) / num_col_part_ + 1 : 01286 (overall_p - 1) % num_row_part_ + 1 ; 01287 } 01288 01289 template <class T_Indice, class T_Value> 01290 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01291 COOMatrixPartitionedView<T_Indice,T_Value>::imp_col_part_num(size_type overall_p) const 01292 { 01293 return (partition_order_ == PARTITION_BY_COL) ? 01294 (overall_p - 1) / num_row_part_ + 1 : 01295 (overall_p - 1) % num_col_part_ + 1 ; 01296 } 01297 01298 template <class T_Indice, class T_Value> 01299 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01300 COOMatrixPartitionedView<T_Indice,T_Value>::overall_p_from_ij(const vector_size_type& row_part 01301 , const vector_size_type& col_part, size_type i, size_type j) 01302 { 01303 return imp_overall_part_num( part_num(row_part,i) 01304 , part_num(col_part,j) ); 01305 } 01306 01307 } // end namespace AbstractLinAlgPack 01308 01309 #endif // COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H
1.7.4