|
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 GEN_PERM_MATRIX_SLICE_H 00043 #define GEN_PERM_MATRIX_SLICE_H 00044 00045 #include "AbstractLinAlgPack_GenPermMatrixSliceIterator.hpp" 00046 00047 namespace AbstractLinAlgPack { 00048 00065 class GenPermMatrixSlice { 00066 public: 00067 00070 00072 enum EIdentityOrZero { IDENTITY_MATRIX, ZERO_MATRIX }; 00073 00075 typedef GenPermMatrixSliceIteratorPack::EOrderedBy EOrderedBy; 00076 00078 typedef GenPermMatrixSliceIteratorPack::row_col_iterator<const index_type> 00079 const_iterator; 00081 typedef ptrdiff_t difference_type; 00082 00084 00086 GenPermMatrixSlice(); 00087 00089 GenPermMatrixSlice( index_type rows, index_type cols, EIdentityOrZero type ); 00090 00108 void initialize( index_type rows, index_type cols, EIdentityOrZero type ); 00109 00151 void initialize( 00152 index_type rows 00153 ,index_type cols 00154 ,index_type nz 00155 ,difference_type row_off 00156 ,difference_type col_off 00157 ,EOrderedBy ordered_by 00158 ,const index_type row_i[] 00159 ,const index_type col_j[] 00160 ,bool test_setup = false 00161 ); 00162 00188 void initialize_and_sort( 00189 index_type rows 00190 ,index_type cols 00191 ,index_type nz 00192 ,difference_type row_off 00193 ,difference_type col_off 00194 ,EOrderedBy ordered_by 00195 ,index_type row_i[] 00196 ,index_type col_j[] 00197 ,bool test_setup = false 00198 ); 00199 00205 void bind( const GenPermMatrixSlice& gpms ); 00206 00208 index_type rows() const; 00210 index_type cols() const; 00212 index_type nz() const; 00214 EOrderedBy ordered_by() const; 00216 bool is_identity() const; 00217 00234 index_type lookup_row_i(index_type col_j) const; 00235 00252 index_type lookup_col_j(index_type row_i) const; 00253 00256 00276 const_iterator begin() const; 00277 00279 const_iterator end() const; 00280 00282 00306 const GenPermMatrixSlice create_submatrix( const Range1D& rng 00307 , EOrderedBy ordered_by ) const; 00308 00309 private: 00310 00311 // ////////////////////////////// 00312 // Private data members 00313 00314 index_type rows_; 00315 index_type cols_; 00316 index_type nz_; 00317 difference_type row_off_; 00318 difference_type col_off_; 00319 EOrderedBy ordered_by_; 00320 const index_type *row_i_; 00321 const index_type *col_j_; 00322 00323 // ////////////////////////////// 00324 // Private static data members 00325 00326 // ToDo: We could allocate a class-wide array, initialize 00327 // it to [1,2,3 ...] and then use it for the iterators 00328 // when is_idenity() == true! This would make implementing 00329 // a lot of code a lot easier if we don't care about a little 00330 // inefficiency! We could just allocate a large chunk 00331 // of memory by default (or client could do this for us) 00332 // and then construct it when needed. If a client ever 00333 // requested an iterator when not enough storage was avalible 00334 // then we would throw an exception. 00335 00336 // ////////////////////////////// 00337 // Private member functions 00338 00339 // Validate the input data (not the ordering!) 00340 static void validate_input_data( 00341 index_type rows 00342 ,index_type cols 00343 ,index_type nz 00344 ,difference_type row_off 00345 ,difference_type col_off 00346 ,EOrderedBy ordered_by 00347 ,const index_type row_i[] 00348 ,const index_type col_j[] 00349 ,std::ostringstream &omsg 00350 ); 00351 00353 void validate_not_identity() const; 00354 00356 GenPermMatrixSlice& operator=( const GenPermMatrixSlice& ); 00357 00358 }; // end class GenPermMatrixSlice 00359 00360 // ////////////////////////////////////////////////////////// 00361 // Inline members for GenPermMatrixSlice 00362 00363 inline 00364 GenPermMatrixSlice::GenPermMatrixSlice( index_type rows, index_type cols, EIdentityOrZero type ) 00365 { 00366 initialize(rows,cols,type); 00367 } 00368 00369 inline 00370 index_type GenPermMatrixSlice::rows() const 00371 { 00372 return rows_; 00373 } 00374 00375 inline 00376 index_type GenPermMatrixSlice::cols() const 00377 { 00378 return cols_; 00379 } 00380 00381 inline 00382 index_type GenPermMatrixSlice::nz() const 00383 { 00384 return nz_; 00385 } 00386 00387 inline 00388 bool GenPermMatrixSlice::is_identity() const 00389 { 00390 return nz_ > 0 && row_i_ == NULL; 00391 } 00392 00393 inline 00394 GenPermMatrixSlice::EOrderedBy GenPermMatrixSlice::ordered_by() const 00395 { 00396 return ordered_by_; 00397 } 00398 00399 } // end namespace AbstractLinAlgPack 00400 00401 #endif // GEN_PERM_MATRIX_SLICE_H
1.7.6.1