|
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 GEN_PERM_MATRIX_SLICE_H 00030 #define GEN_PERM_MATRIX_SLICE_H 00031 00032 #include "AbstractLinAlgPack_GenPermMatrixSliceIterator.hpp" 00033 00034 namespace AbstractLinAlgPack { 00035 00052 class GenPermMatrixSlice { 00053 public: 00054 00057 00059 enum EIdentityOrZero { IDENTITY_MATRIX, ZERO_MATRIX }; 00060 00062 typedef GenPermMatrixSliceIteratorPack::EOrderedBy EOrderedBy; 00063 00065 typedef GenPermMatrixSliceIteratorPack::row_col_iterator<const index_type> 00066 const_iterator; 00068 typedef ptrdiff_t difference_type; 00069 00071 00073 GenPermMatrixSlice(); 00074 00076 GenPermMatrixSlice( index_type rows, index_type cols, EIdentityOrZero type ); 00077 00095 void initialize( index_type rows, index_type cols, EIdentityOrZero type ); 00096 00138 void initialize( 00139 index_type rows 00140 ,index_type cols 00141 ,index_type nz 00142 ,difference_type row_off 00143 ,difference_type col_off 00144 ,EOrderedBy ordered_by 00145 ,const index_type row_i[] 00146 ,const index_type col_j[] 00147 ,bool test_setup = false 00148 ); 00149 00175 void initialize_and_sort( 00176 index_type rows 00177 ,index_type cols 00178 ,index_type nz 00179 ,difference_type row_off 00180 ,difference_type col_off 00181 ,EOrderedBy ordered_by 00182 ,index_type row_i[] 00183 ,index_type col_j[] 00184 ,bool test_setup = false 00185 ); 00186 00192 void bind( const GenPermMatrixSlice& gpms ); 00193 00195 index_type rows() const; 00197 index_type cols() const; 00199 index_type nz() const; 00201 EOrderedBy ordered_by() const; 00203 bool is_identity() const; 00204 00221 index_type lookup_row_i(index_type col_j) const; 00222 00239 index_type lookup_col_j(index_type row_i) const; 00240 00243 00263 const_iterator begin() const; 00264 00266 const_iterator end() const; 00267 00269 00293 const GenPermMatrixSlice create_submatrix( const Range1D& rng 00294 , EOrderedBy ordered_by ) const; 00295 00296 private: 00297 00298 // ////////////////////////////// 00299 // Private data members 00300 00301 index_type rows_; 00302 index_type cols_; 00303 index_type nz_; 00304 difference_type row_off_; 00305 difference_type col_off_; 00306 EOrderedBy ordered_by_; 00307 const index_type *row_i_; 00308 const index_type *col_j_; 00309 00310 // ////////////////////////////// 00311 // Private static data members 00312 00313 // ToDo: We could allocate a class-wide array, initialize 00314 // it to [1,2,3 ...] and then use it for the iterators 00315 // when is_idenity() == true! This would make implementing 00316 // a lot of code a lot easier if we don't care about a little 00317 // inefficiency! We could just allocate a large chunk 00318 // of memory by default (or client could do this for us) 00319 // and then construct it when needed. If a client ever 00320 // requested an iterator when not enough storage was avalible 00321 // then we would throw an exception. 00322 00323 // ////////////////////////////// 00324 // Private member functions 00325 00326 // Validate the input data (not the ordering!) 00327 static void validate_input_data( 00328 index_type rows 00329 ,index_type cols 00330 ,index_type nz 00331 ,difference_type row_off 00332 ,difference_type col_off 00333 ,EOrderedBy ordered_by 00334 ,const index_type row_i[] 00335 ,const index_type col_j[] 00336 ,std::ostringstream &omsg 00337 ); 00338 00340 void validate_not_identity() const; 00341 00343 GenPermMatrixSlice& operator=( const GenPermMatrixSlice& ); 00344 00345 }; // end class GenPermMatrixSlice 00346 00347 // ////////////////////////////////////////////////////////// 00348 // Inline members for GenPermMatrixSlice 00349 00350 inline 00351 GenPermMatrixSlice::GenPermMatrixSlice( index_type rows, index_type cols, EIdentityOrZero type ) 00352 { 00353 initialize(rows,cols,type); 00354 } 00355 00356 inline 00357 index_type GenPermMatrixSlice::rows() const 00358 { 00359 return rows_; 00360 } 00361 00362 inline 00363 index_type GenPermMatrixSlice::cols() const 00364 { 00365 return cols_; 00366 } 00367 00368 inline 00369 index_type GenPermMatrixSlice::nz() const 00370 { 00371 return nz_; 00372 } 00373 00374 inline 00375 bool GenPermMatrixSlice::is_identity() const 00376 { 00377 return nz_ > 0 && row_i_ == NULL; 00378 } 00379 00380 inline 00381 GenPermMatrixSlice::EOrderedBy GenPermMatrixSlice::ordered_by() const 00382 { 00383 return ordered_by_; 00384 } 00385 00386 } // end namespace AbstractLinAlgPack 00387 00388 #endif // GEN_PERM_MATRIX_SLICE_H
1.7.4