|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H 00043 #define COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H 00044 00045 #include "AbstractLinAlgPack_SparseCOOPtrElement.hpp" 00046 #include "AbstractLinAlgPack_TransSparseCOOElementViewIter.hpp" 00047 #include "MiRefCount.h" 00048 00049 namespace AbstractLinAlgPack { 00050 00051 namespace COOMatrixPartitionedViewUtilityPack { 00052 template <class T_Indice, class T_Value> class Partition; 00053 template <class T_Indice, class T_Value> class TransposedPartition; 00054 } 00055 00056 // /////////////////////////////////////////////////////////////////////////////////////// 00057 // /////////////////////////////////////////////////////////////////////////////////////// 00183 template <class T_Indice, class T_Value> 00184 class COOMatrixPartitionedView { 00185 public: 00186 00187 // ////////////////////////////////////////////////////////////////////////// 00190 00192 typedef COOMatrixPartitionedViewUtilityPack::Partition<T_Indice,T_Value> 00193 partition_type; 00195 typedef COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00196 transposed_partition_type; 00198 typedef T_Indice indice_type; 00200 typedef AbstractLinAlgPack::size_type size_type; 00202 typedef ptrdiff_t difference_type; 00204 enum EPartitionOrder { PARTITION_BY_ROW, PARTITION_BY_COL }; 00206 class UninitializedException: public std::logic_error 00207 {public: UninitializedException(const std::string& what_arg) : std::logic_error(what_arg) {}}; 00208 00210 00211 // /////////////////////////////////////////////////////////////////////////////////////// 00214 00221 00231 COOMatrixPartitionedView(); 00232 00237 COOMatrixPartitionedView( 00238 size_type rows 00239 , size_type cols 00240 , size_type nz 00241 , value_type val[] 00242 , const indice_type ivect[] 00243 , const indice_type jvect[] 00244 , const size_type inv_row_perm[] 00245 , const size_type inv_col_perm[] 00246 , const size_type num_row_part 00247 , const size_type row_part[] 00248 , const size_type num_col_part 00249 , const size_type col_part[] 00250 , const EPartitionOrder partition_order ) 00251 00252 : num_row_part_(0), num_col_part_(0) 00253 { 00254 create_view(rows, cols, nz, val, ivect, jvect, inv_row_perm, inv_col_perm, num_row_part 00255 , row_part, num_col_part, col_part, partition_order); 00256 } 00257 // I tried defining this function else where as both an inlined and 00258 // noninlined function but MS VC++ 5.0 generated 00259 // a linking error saying that it could not find this function. 00260 // ToDo: Investagate this problem further at a latter time. 00261 00335 void create_view( 00336 size_type rows 00337 , size_type cols 00338 , size_type nz 00339 , value_type val[] 00340 , const indice_type ivect[] 00341 , const indice_type jvect[] 00342 , const size_type inv_row_perm[] 00343 , const size_type inv_col_perm[] 00344 , const size_type num_row_part 00345 , const size_type row_part[] 00346 , const size_type num_col_part 00347 , const size_type col_part[] 00348 , const EPartitionOrder partition_order ); 00349 00355 void bind(const COOMatrixPartitionedView& coom_view); 00356 00358 void free(); 00359 00361 bool is_initialized() const; 00362 00364 00374 00376 size_type rows() const; 00377 00379 size_type cols() const; 00380 00382 size_type nz() const; 00383 00385 size_type num_row_part() const; 00386 00388 size_type num_col_part() const; 00389 00395 void get_row_part(indice_type row_part[]) const; 00396 00402 void get_col_part(indice_type col_part[]) const; 00403 00405 EPartitionOrder partition_order() const; 00406 00410 size_type overall_part_num(size_type row_p, size_type col_p) const; 00411 00413 size_type row_part_num(size_type overall_p) const; 00414 00416 size_type col_part_num(size_type overall_p) const; 00417 00419 00429 00430 // /// 00431 // /** Allow an implicit conversion from a COOMatrixPartitionedView 00432 // * to a partition_type object. 00433 // * 00434 // * This conversion is equivalent to calling #partition(Range1D())#. 00435 // */ 00436 // operator partition_type(); 00437 // 00438 // /// 00439 // operator const partition_type() const; 00440 00443 partition_type operator()(); 00444 00446 const partition_type operator()() const; 00447 00450 partition_type partition(size_type overall_p); 00451 00453 const partition_type partition(size_type overall_p) const; 00454 00458 partition_type partition(size_type row_p, size_type col_p); 00459 00461 const partition_type partition(size_type row_p, size_type col_p) const; 00462 00476 partition_type partition(Range1D rng_overall_p); 00477 00479 const partition_type partition(Range1D rng_overall_p) const; 00480 00482 00484 00485 private: 00486 // //////////////////////////////////////////////////////////////// 00487 // Private types 00488 00489 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00490 typedef std::vector<indice_type> vector_indice_type; 00491 typedef std::vector<size_type> vector_size_type; 00492 typedef std::vector<element_type> ele_type; 00493 typedef MemMngPack::RefCount< 00494 vector_indice_type> ref_vector_indice_type; 00495 typedef MemMngPack::RefCount< 00496 vector_size_type> ref_vector_size_type; 00497 typedef MemMngPack::RefCount< 00498 ele_type> ref_ele_type; 00499 00500 // /////////////////////////////////////////////////////////////// 00501 // Private data members 00502 00503 size_type num_row_part_; 00504 // The number of partions the COO matrix is sliced up into by rows. 00505 00506 size_type num_col_part_; 00507 // The number of partions the COO matrix is sliced up into by columns. 00508 00509 ref_vector_size_type ref_row_part_; 00510 // 00511 // row_part = { row_p_1_i, row_p_2_i,...,row_p_nrp_i, row_p_nrp_last_i + 1 } 00512 // where: row_p_k_i is the row indice for row partition k 00513 // nrp = num_row_part 00514 // row_p_nrp_last_i is the last row indice in the last row partition 00515 // 00516 // vector (length num_row_part_ + 1) of row indices for the start of the row partitions. 00517 // row_part[i - 1] is the row indice for the start of the ith row partition (i = 1,...,num_row_part_). 00518 // The last indice gives the row indice that is one past the last row of the last 00519 // row partition. It is included for the efficient calculation of the number of rows 00520 // in a partition or a set of partitions. 00521 00522 ref_vector_size_type ref_col_part_; 00523 // 00524 // col_part = { col_p_1_i, col_p_2_i,...,col_p_nrp_i, col_p_nrp_last_i + 1 } 00525 // where: col_p_k_i is the col indice for col partition k 00526 // nrp = num_col_part 00527 // col_p_nrp_last_i is the last col indice in the last col partition 00528 // 00529 // vector (length num_row_part_ + 1) of column indices for the start of the columns partitions. 00530 // col_part[j - 1] is the column indice for the start of the jth column partition (j = 1,...,num_col_part_). 00531 // The last indice gives the column indice that is one past the last column of the last 00532 // column partition. It is included for the efficient calculation of the number of columns 00533 // in a partition or a set of partitions. 00534 00535 EPartitionOrder partition_order_; 00536 // Specifies wheather the partitions are to be orded by columns or rows 00537 00538 ref_ele_type ref_ele_; 00539 // ToDo: replace with a RefCount<std::vector<element_type>> when you get compiler bug fix. 00540 // The storage array (dynamically allocated) for the elements in the COO matrix. 00541 // The elements in this array are ordered into partitions defined by the partition_order_. 00542 // 00543 // ele_ 00544 // --------------------- 00545 // |pval row_i col_i| 00546 // || | | | | ||- 00547 // || | | | | || parition 1 00548 // || | | | | || 00549 // || | | | | ||- 00550 // || | | | | || parition 2 00551 // || | | | | || 00552 // || | | | | ||- 00553 // || | | | | || . 00554 // || | | | | || . 00555 // || | | | | || . 00556 // || | | | | || 00557 // || | | | | ||- 00558 // || | | | | || partition num_row_part * num_col_part 00559 // || | | | | || 00560 // || | | | | ||- 00561 // --------------------- 00562 00563 ref_vector_size_type ref_part_start_; 00564 // 00565 // part_start = { start_1 = 0, start_2,..., start_n, total_nz } 00566 // 00567 // vector (length num_row_part * num_col_part_ + 1) of the start for the elements in 00568 // each partition. ele_[part_start_[overall_p - 1]] gives the first element of partion 00569 // overal_p and ele_[part_start_[overall_p] - 1] gives the last element in the partition. 00570 // This array is also used to calculate the number of nonzero elements in each parition 00571 // and in the overall partition. The last element part_start_[num_row_part * num_col_part_] 00572 // gives the total number of nonzeros in all of the partitions and is also used 00573 // to allow the calculation of the number of nonzero elements in the last partition. 00574 00575 // When the view is uninitialized then ele_, row_part_, col_part_ and part_start_ will 00576 // all uninitialized. 00577 00578 // /////////////////////////////////////////////////////////////// 00579 // Private member functions 00580 00581 // assert that the object is initialized 00582 void assert_initialized() const; 00583 00584 size_type imp_overall_part_num(size_type row_p, size_type col_p) const; 00585 00586 size_type imp_row_part_num(size_type overall_p) const; 00587 00588 size_type imp_col_part_num(size_type overall_p) const; 00589 00590 // Return the partition number given an indice. 00591 // Passing the partition vector is an optimization 00592 // that allows us to only call .obj() once 00593 // on the reference object and thus same some 00594 // unnecessary work. 00595 size_type part_num(const vector_size_type& part, size_type indice); 00596 00597 // Return the overall partition number 00598 size_type overall_p_from_ij(const vector_size_type& row_part 00599 , const vector_size_type& col_part, size_type i, size_type j); 00600 00601 // Return a non-const partition. This is the function 00602 // that implements all partition creations. 00603 partition_type create_partition(Range1D rng_overall_p) const; 00604 00605 // Not defined and not to be called 00606 COOMatrixPartitionedView& operator=(const COOMatrixPartitionedView&); 00607 00608 }; // end class COOMatrixPartitionedView 00609 00610 00611 namespace COOMatrixPartitionedViewUtilityPack { 00612 00617 00618 // /////////////////////////////////////////////////////////////////////// 00619 // /////////////////////////////////////////////////////////////////////// 00632 template <class T_Indice, class T_Value> 00633 class Partition { 00634 public: 00635 // ///////////////////////////////////////////////////// 00638 00640 typedef AbstractLinAlgPack::size_type size_type; 00642 typedef Partition<T_Indice,T_Value> partition_type; 00644 typedef ptrdiff_t difference_type; 00646 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00648 typedef element_type* iterator; 00650 typedef const element_type* const_iterator; 00651 00653 00654 // ///////////////////////////////////////////////////// 00657 00664 00676 Partition(); 00677 00682 Partition( 00683 size_type rows 00684 , size_type cols 00685 , size_type nz 00686 , element_type* ele 00687 , difference_type row_offset 00688 , difference_type col_offset ); 00689 00701 void initialize( 00702 size_type rows 00703 , size_type cols 00704 , size_type nz 00705 , element_type* ele 00706 , difference_type row_offset 00707 , difference_type col_offset ); 00708 00713 void bind(const partition_type& partition); 00714 00716 00719 00721 size_type rows() const; 00723 size_type cols() const ; 00725 size_type nz() const; 00727 difference_type row_offset() const; 00729 difference_type col_offset() const; 00731 iterator begin(); 00733 const_iterator begin() const; 00735 iterator end(); 00737 const_iterator end() const; 00738 00740 00742 00743 private: 00744 // ////////////////////////////////////////////////////// 00745 // Private types 00746 00747 // ////////////////////////////////////////////////////// 00748 // Private data members 00749 00750 size_type rows_, // The number of rows in this COO matrix 00751 cols_, // The number of columns in this COO matrix 00752 nz_; // The number of nonzero elements in this COO matrix 00753 element_type *ele_; // pointer to array of elements in this COO matrix 00754 difference_type row_offset_, // offset for each row indice stored in ele 00755 col_offset_; // offset for each column indice stored in ele 00756 00757 // ////////////////////////////////////////////////////// 00758 // Private member functions 00759 00760 // assert that we are initialized 00761 void assert_initialized() const; 00762 00763 // not defined and not to be called 00764 Partition& operator=(const Partition&); 00765 00766 }; // end class Partition 00767 00768 // ///////////////////////////////////////////////////////////////////////////////////// 00769 // ///////////////////////////////////////////////////////////////////////////////////// 00791 template <class T_Indice, class T_Value> 00792 class TransposedPartition { 00793 public: 00794 // ///////////////////////////////////////////////////// 00797 00799 typedef Partition<T_Indice,T_Value> partition_type; 00801 typedef AbstractLinAlgPack::size_type size_type; 00803 typedef ptrdiff_t difference_type; 00805 typedef SparseCOOPtrElement<T_Indice,T_Value> element_type; 00807 typedef TransSparseCOOElementViewIter< 00808 element_type* 00809 , std::random_access_iterator_tag 00810 , typename element_type::indice_type 00811 , typename element_type::value_type& 00812 , difference_type> iterator; 00814 typedef TransSparseCOOElementViewIter< 00815 const element_type* 00816 , std::random_access_iterator_tag 00817 , typename element_type::indice_type 00818 , const typename element_type::value_type& 00819 , difference_type> const_iterator; 00820 00822 00823 // ///////////////////////////////////////////////////// 00826 00833 00838 TransposedPartition(const partition_type& partition); 00839 00844 void bind(const partition_type& partition); 00845 00847 00850 00852 size_type rows() const; 00854 size_type cols() const; 00856 size_type nz() const; 00858 difference_type row_offset() const; 00860 difference_type col_offset() const; 00862 iterator begin(); 00864 const_iterator begin() const; 00866 iterator end(); 00868 const_iterator end() const; 00869 00871 00873 00874 private: 00875 partition_type partition_; // actually stores a partition object. 00876 00877 // Not defined and not to be called 00878 TransposedPartition& operator=(const TransposedPartition&); 00879 00880 }; // end class TransposedPartition 00881 00882 // end COOMatrixPartitionedViewUtilityPack 00884 00885 } // end namespace COOMatrixPartitionedViewUtilityPack 00886 00887 00888 // ////////////////////////////////////////////////////////////////////////// 00889 // Nonmember functions 00890 00893 template<class T_Indice, class T_Value> 00894 inline COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00895 trans(COOMatrixPartitionedViewUtilityPack::Partition<T_Indice,T_Value>& part) 00896 { 00897 typedef COOMatrixPartitionedViewUtilityPack::TransposedPartition<T_Indice,T_Value> 00898 transposed_partition_type; 00899 return transposed_partition_type(part); 00900 } 00901 00902 // /////////////////////////////////////////////////////////////////////////// 00903 // Inline member function definitions 00904 00905 namespace COOMatrixPartitionedViewUtilityPack { 00906 00907 // /////////////////////////////////////////////////////////////////////////// 00908 // Inline members for class COOMatrixPartitionedViewUtilityPack::Partition<> 00909 00910 // Constructors and initializes 00911 00912 template <class T_Indice, class T_Value> 00913 inline Partition<T_Indice,T_Value>::Partition() 00914 : rows_(0), cols_(0), nz_(0), ele_(0), row_offset_(0), col_offset_(0) 00915 {} 00916 00917 template <class T_Indice, class T_Value> 00918 inline Partition<T_Indice,T_Value>::Partition( 00919 size_type rows 00920 , size_type cols 00921 , size_type nz 00922 , element_type* ele 00923 , difference_type row_offset 00924 , difference_type col_offset ) 00925 : rows_(rows), cols_(cols), nz_(nz), ele_(ele), row_offset_(row_offset) 00926 , col_offset_(col_offset) 00927 {} 00928 00929 template <class T_Indice, class T_Value> 00930 inline void Partition<T_Indice,T_Value>::initialize( 00931 size_type rows 00932 , size_type cols 00933 , size_type nz 00934 , element_type* ele 00935 , difference_type row_offset 00936 , difference_type col_offset ) 00937 { 00938 rows_ = rows; 00939 cols_ = cols; 00940 nz_ = nz; 00941 ele_ = ele; 00942 row_offset_ = row_offset; 00943 col_offset_ = col_offset; 00944 } 00945 00946 template <class T_Indice, class T_Value> 00947 inline void Partition<T_Indice,T_Value>::bind(const partition_type& partition) { 00948 initialize(partition.rows_,partition.cols_,partition.nz_,partition.ele_ 00949 ,partition.row_offset_,partition.col_offset_); 00950 } 00951 00952 // COOMatrixTemplateInterface interface 00953 00954 template <class T_Indice, class T_Value> 00955 inline Partition<T_Indice,T_Value>::size_type 00956 Partition<T_Indice,T_Value>::rows() const 00957 { 00958 return rows_; 00959 } 00960 00961 template <class T_Indice, class T_Value> 00962 inline Partition<T_Indice,T_Value>::size_type 00963 Partition<T_Indice,T_Value>::cols() const 00964 { 00965 return cols_; 00966 } 00967 00968 template <class T_Indice, class T_Value> 00969 inline Partition<T_Indice,T_Value>::size_type 00970 Partition<T_Indice,T_Value>::nz() const 00971 { 00972 return nz_; 00973 } 00974 00975 template <class T_Indice, class T_Value> 00976 inline Partition<T_Indice,T_Value>::difference_type 00977 Partition<T_Indice,T_Value>::row_offset() const 00978 { 00979 return row_offset_; 00980 } 00981 00982 template <class T_Indice, class T_Value> 00983 inline Partition<T_Indice,T_Value>::difference_type 00984 Partition<T_Indice,T_Value>::col_offset() const 00985 { 00986 return col_offset_; 00987 } 00988 00989 template <class T_Indice, class T_Value> 00990 inline Partition<T_Indice,T_Value>::iterator 00991 Partition<T_Indice,T_Value>::begin() 00992 { 00993 assert_initialized(); 00994 return ele_; 00995 } 00996 00997 template <class T_Indice, class T_Value> 00998 inline Partition<T_Indice,T_Value>::const_iterator 00999 Partition<T_Indice,T_Value>::begin() const 01000 { 01001 assert_initialized(); 01002 return ele_; 01003 } 01004 01005 template <class T_Indice, class T_Value> 01006 inline Partition<T_Indice,T_Value>::iterator 01007 Partition<T_Indice,T_Value>::end() 01008 { 01009 assert_initialized(); 01010 return ele_ + nz_; 01011 } 01012 01013 template <class T_Indice, class T_Value> 01014 inline Partition<T_Indice,T_Value>::const_iterator 01015 Partition<T_Indice,T_Value>::end() const 01016 { 01017 assert_initialized(); 01018 return ele_ + nz_; 01019 } 01020 01021 // Private member functions 01022 01023 template <class T_Indice, class T_Value> 01024 inline void Partition<T_Indice,T_Value>::assert_initialized() const { 01025 if(!ele_) 01026 throw std::logic_error("Partition<...> :" 01027 "The COO matrix was not initizlized"); 01028 } 01029 01030 01031 // /////////////////////////////////////////////////////////////////////////// 01032 // Inline members for class COOMatrixPartitionedViewUtilityPack::TransposedPartition<> 01033 01034 // Constructors and initializes 01035 01036 template <class T_Indice, class T_Value> 01037 inline TransposedPartition<T_Indice,T_Value>::TransposedPartition(const partition_type& partition) 01038 : partition_(partition) 01039 {} 01040 01041 template <class T_Indice, class T_Value> 01042 inline void TransposedPartition<T_Indice,T_Value>::bind(const partition_type& partition) { 01043 partition_.bind(partition); 01044 } 01045 01046 // COOMatrixTemplateInterface interface 01047 01048 template <class T_Indice, class T_Value> 01049 inline TransposedPartition<T_Indice,T_Value>::size_type 01050 TransposedPartition<T_Indice,T_Value>::rows() const 01051 { 01052 return partition_.cols(); 01053 } 01054 01055 template <class T_Indice, class T_Value> 01056 inline TransposedPartition<T_Indice,T_Value>::size_type 01057 TransposedPartition<T_Indice,T_Value>::cols() const 01058 { 01059 return partition_.rows(); 01060 } 01061 01062 template <class T_Indice, class T_Value> 01063 inline TransposedPartition<T_Indice,T_Value>::size_type 01064 TransposedPartition<T_Indice,T_Value>::nz() const 01065 { 01066 return partition_.nz(); 01067 } 01068 01069 template <class T_Indice, class T_Value> 01070 inline TransposedPartition<T_Indice,T_Value>::difference_type 01071 TransposedPartition<T_Indice,T_Value>::row_offset() const 01072 { 01073 return partition_.col_offset(); 01074 } 01075 01076 template <class T_Indice, class T_Value> 01077 inline TransposedPartition<T_Indice,T_Value>::difference_type 01078 TransposedPartition<T_Indice,T_Value>::col_offset() const 01079 { 01080 return partition_.row_offset(); 01081 } 01082 01083 template <class T_Indice, class T_Value> 01084 inline TransposedPartition<T_Indice,T_Value>::iterator 01085 TransposedPartition<T_Indice,T_Value>::begin() 01086 { 01087 return iterator(partition_.begin()); 01088 } 01089 01090 template <class T_Indice, class T_Value> 01091 inline TransposedPartition<T_Indice,T_Value>::const_iterator 01092 TransposedPartition<T_Indice,T_Value>::begin() const 01093 { 01094 return const_iterator(partition_.begin()); 01095 } 01096 01097 template <class T_Indice, class T_Value> 01098 inline TransposedPartition<T_Indice,T_Value>::iterator 01099 TransposedPartition<T_Indice,T_Value>::end() 01100 { 01101 return iterator(partition_.end()); 01102 } 01103 01104 template <class T_Indice, class T_Value> 01105 inline TransposedPartition<T_Indice,T_Value>::const_iterator 01106 TransposedPartition<T_Indice,T_Value>::end() const 01107 { 01108 return const_iterator(partition_.end()); 01109 } 01110 01111 } // end namespace COOMatrixPartitionViewUtilityPack 01112 01113 01114 // /////////////////////////////////////////////////////////////////////////// 01115 // Inline members for class COOMatrixPartitionedView<> 01116 01117 // Constructors and initializes 01118 01119 template <class T_Indice, class T_Value> 01120 inline COOMatrixPartitionedView<T_Indice,T_Value>::COOMatrixPartitionedView() 01121 : num_row_part_(0), num_col_part_(0) 01122 {} 01123 01124 template <class T_Indice, class T_Value> 01125 inline bool COOMatrixPartitionedView<T_Indice,T_Value>::is_initialized() const { 01126 return ref_ele_.has_ref_set(); 01127 } 01128 01129 // Partitioning information 01130 01131 template <class T_Indice, class T_Value> 01132 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01133 COOMatrixPartitionedView<T_Indice,T_Value>::rows() const 01134 { 01135 assert_initialized(); 01136 const std::vector<size_type> &row_part = ref_row_part_.const_obj(); 01137 return row_part[num_row_part_] - row_part[0]; 01138 } 01139 01140 template <class T_Indice, class T_Value> 01141 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01142 COOMatrixPartitionedView<T_Indice,T_Value>::cols() const 01143 { 01144 assert_initialized(); 01145 const std::vector<size_type> &col_part = ref_col_part_.const_obj(); 01146 return col_part[num_col_part_] - col_part[0]; 01147 } 01148 01149 template <class T_Indice, class T_Value> 01150 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01151 COOMatrixPartitionedView<T_Indice,T_Value>::nz() const 01152 { 01153 assert_initialized(); 01154 return ref_part_start_.const_obj()[num_row_part_ * num_col_part_]; 01155 } 01156 01157 template <class T_Indice, class T_Value> 01158 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01159 COOMatrixPartitionedView<T_Indice,T_Value>::num_row_part() const 01160 { 01161 return num_row_part_; 01162 } 01163 01164 template <class T_Indice, class T_Value> 01165 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01166 COOMatrixPartitionedView<T_Indice,T_Value>::num_col_part() const 01167 { 01168 return num_col_part_; 01169 } 01170 01171 template <class T_Indice, class T_Value> 01172 inline COOMatrixPartitionedView<T_Indice,T_Value>::EPartitionOrder 01173 COOMatrixPartitionedView<T_Indice,T_Value>::partition_order() const 01174 { 01175 assert_initialized(); 01176 return partition_order_; 01177 } 01178 01179 template <class T_Indice, class T_Value> 01180 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01181 COOMatrixPartitionedView<T_Indice,T_Value>::overall_part_num(size_type row_p, size_type col_p) const 01182 { 01183 assert_initialized(); 01184 return imp_overall_part_num(row_p, col_p); 01185 } 01186 01187 template <class T_Indice, class T_Value> 01188 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01189 COOMatrixPartitionedView<T_Indice,T_Value>::row_part_num(size_type overall_p) const 01190 { 01191 assert_initialized(); 01192 return imp_row_part_num(overall_p); 01193 } 01194 01195 template <class T_Indice, class T_Value> 01196 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01197 COOMatrixPartitionedView<T_Indice,T_Value>::col_part_num(size_type overall_p) const 01198 { 01199 assert_initialized(); 01200 return imp_col_part_num(overall_p); 01201 } 01202 01203 // Partition access 01204 01205 //template <class T_Indice, class T_Value> 01206 //inline COOMatrixPartitionedView<T_Indice,T_Value>::operator 01207 //COOMatrixPartitionedView<T_Indice,T_Value>::partition_type() 01208 //{ 01209 // return partition(Range1D()); 01210 //} 01211 01212 //template <class T_Indice, class T_Value> 01213 //inline COOMatrixPartitionedView<T_Indice,T_Value>::operator 01214 //const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type() const 01215 //{ 01216 // return partition(Range1D()); 01217 //} 01218 01219 template <class T_Indice, class T_Value> 01220 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01221 COOMatrixPartitionedView<T_Indice,T_Value>::operator()() 01222 { 01223 return partition(Range1D()); 01224 } 01225 01226 template <class T_Indice, class T_Value> 01227 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01228 COOMatrixPartitionedView<T_Indice,T_Value>::operator()() const 01229 { 01230 return partition(Range1D()); 01231 } 01232 01233 template <class T_Indice, class T_Value> 01234 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01235 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type overall_p) 01236 { 01237 return partition(Range1D(overall_p,overall_p)); 01238 } 01239 01240 template <class T_Indice, class T_Value> 01241 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01242 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type overall_p) const 01243 { 01244 return partition(Range1D(overall_p,overall_p)); 01245 } 01246 01247 template <class T_Indice, class T_Value> 01248 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01249 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type row_p, size_type col_p) 01250 { 01251 return partition(overall_part_num(row_p,col_p)); 01252 } 01253 01254 template <class T_Indice, class T_Value> 01255 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01256 COOMatrixPartitionedView<T_Indice,T_Value>::partition(size_type row_p, size_type col_p) const 01257 { 01258 return partition(overall_part_num(row_p,col_p)); 01259 } 01260 01261 template <class T_Indice, class T_Value> 01262 inline COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01263 COOMatrixPartitionedView<T_Indice,T_Value>::partition(Range1D rng_overall_p) 01264 { 01265 return create_partition(rng_overall_p); 01266 } 01267 01268 template <class T_Indice, class T_Value> 01269 inline const COOMatrixPartitionedView<T_Indice,T_Value>::partition_type 01270 COOMatrixPartitionedView<T_Indice,T_Value>::partition(Range1D rng_overall_p) const 01271 { 01272 return create_partition(rng_overall_p); 01273 } 01274 01275 // Private member functions 01276 01277 template <class T_Indice, class T_Value> 01278 inline void COOMatrixPartitionedView<T_Indice,T_Value>::assert_initialized() const { 01279 if(!is_initialized()) 01280 throw UninitializedException("COOMatrixPartitionedView<..>::assert_initialized() :" 01281 " The partitioned view has not been initialized."); 01282 } 01283 01284 template <class T_Indice, class T_Value> 01285 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01286 COOMatrixPartitionedView<T_Indice,T_Value>::imp_overall_part_num(size_type row_p, size_type col_p) const 01287 { 01288 return (partition_order_ == PARTITION_BY_ROW) ? 01289 (row_p - 1) * num_col_part_ + col_p : 01290 (col_p - 1) * num_row_part_ + row_p; 01291 } 01292 01293 template <class T_Indice, class T_Value> 01294 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01295 COOMatrixPartitionedView<T_Indice,T_Value>::imp_row_part_num(size_type overall_p) const 01296 { 01297 return (partition_order_ == PARTITION_BY_ROW) ? 01298 (overall_p - 1) / num_col_part_ + 1 : 01299 (overall_p - 1) % num_row_part_ + 1 ; 01300 } 01301 01302 template <class T_Indice, class T_Value> 01303 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01304 COOMatrixPartitionedView<T_Indice,T_Value>::imp_col_part_num(size_type overall_p) const 01305 { 01306 return (partition_order_ == PARTITION_BY_COL) ? 01307 (overall_p - 1) / num_row_part_ + 1 : 01308 (overall_p - 1) % num_col_part_ + 1 ; 01309 } 01310 01311 template <class T_Indice, class T_Value> 01312 inline COOMatrixPartitionedView<T_Indice,T_Value>::size_type 01313 COOMatrixPartitionedView<T_Indice,T_Value>::overall_p_from_ij(const vector_size_type& row_part 01314 , const vector_size_type& col_part, size_type i, size_type j) 01315 { 01316 return imp_overall_part_num( part_num(row_part,i) 01317 , part_num(col_part,j) ); 01318 } 01319 01320 } // end namespace AbstractLinAlgPack 01321 01322 #endif // COO_MATRIX_PARTITIONED_VIEW_CLASS_DECL_H
1.7.6.1