AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_GenPermMatrixSlice.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef GEN_PERM_MATRIX_SLICE_H
43 #define GEN_PERM_MATRIX_SLICE_H
44 
45 #include "AbstractLinAlgPack_GenPermMatrixSliceIterator.hpp"
46 
47 namespace AbstractLinAlgPack {
48 
66 public:
67 
70 
72  enum EIdentityOrZero { IDENTITY_MATRIX, ZERO_MATRIX };
73 
75  typedef GenPermMatrixSliceIteratorPack::EOrderedBy EOrderedBy;
76 
81  typedef ptrdiff_t difference_type;
82 
84 
87 
89  GenPermMatrixSlice( index_type rows, index_type cols, EIdentityOrZero type );
90 
108  void initialize( index_type rows, index_type cols, EIdentityOrZero type );
109 
151  void initialize(
152  index_type rows
153  ,index_type cols
154  ,index_type nz
155  ,difference_type row_off
156  ,difference_type col_off
157  ,EOrderedBy ordered_by
158  ,const index_type row_i[]
159  ,const index_type col_j[]
160  ,bool test_setup = false
161  );
162 
188  void initialize_and_sort(
189  index_type rows
190  ,index_type cols
191  ,index_type nz
192  ,difference_type row_off
193  ,difference_type col_off
194  ,EOrderedBy ordered_by
195  ,index_type row_i[]
196  ,index_type col_j[]
197  ,bool test_setup = false
198  );
199 
205  void bind( const GenPermMatrixSlice& gpms );
206 
208  index_type rows() const;
210  index_type cols() const;
212  index_type nz() const;
214  EOrderedBy ordered_by() const;
216  bool is_identity() const;
217 
234  index_type lookup_row_i(index_type col_j) const;
235 
252  index_type lookup_col_j(index_type row_i) const;
253 
256 
276  const_iterator begin() const;
277 
279  const_iterator end() const;
280 
282 
307  , EOrderedBy ordered_by ) const;
308 
309 private:
310 
311  // //////////////////////////////
312  // Private data members
313 
314  index_type rows_;
315  index_type cols_;
316  index_type nz_;
317  difference_type row_off_;
318  difference_type col_off_;
319  EOrderedBy ordered_by_;
320  const index_type *row_i_;
321  const index_type *col_j_;
322 
323  // //////////////////////////////
324  // Private static data members
325 
326  // ToDo: We could allocate a class-wide array, initialize
327  // it to [1,2,3 ...] and then use it for the iterators
328  // when is_idenity() == true! This would make implementing
329  // a lot of code a lot easier if we don't care about a little
330  // inefficiency! We could just allocate a large chunk
331  // of memory by default (or client could do this for us)
332  // and then construct it when needed. If a client ever
333  // requested an iterator when not enough storage was avalible
334  // then we would throw an exception.
335 
336  // //////////////////////////////
337  // Private member functions
338 
339  // Validate the input data (not the ordering!)
340  static void validate_input_data(
341  index_type rows
342  ,index_type cols
343  ,index_type nz
344  ,difference_type row_off
345  ,difference_type col_off
346  ,EOrderedBy ordered_by
347  ,const index_type row_i[]
348  ,const index_type col_j[]
349  ,std::ostringstream &omsg
350  );
351 
353  void validate_not_identity() const;
354 
356  GenPermMatrixSlice& operator=( const GenPermMatrixSlice& );
357 
358 }; // end class GenPermMatrixSlice
359 
360 // //////////////////////////////////////////////////////////
361 // Inline members for GenPermMatrixSlice
362 
363 inline
365 {
366  initialize(rows,cols,type);
367 }
368 
369 inline
370 index_type GenPermMatrixSlice::rows() const
371 {
372  return rows_;
373 }
374 
375 inline
376 index_type GenPermMatrixSlice::cols() const
377 {
378  return cols_;
379 }
380 
381 inline
382 index_type GenPermMatrixSlice::nz() const
383 {
384  return nz_;
385 }
386 
387 inline
389 {
390  return nz_ > 0 && row_i_ == NULL;
391 }
392 
393 inline
394 GenPermMatrixSlice::EOrderedBy GenPermMatrixSlice::ordered_by() const
395 {
396  return ordered_by_;
397 }
398 
399 } // end namespace AbstractLinAlgPack
400 
401 #endif // GEN_PERM_MATRIX_SLICE_H
GenPermMatrixSlice()
Construct to an uninitialzied, unsized matrix.
GenPermMatrixSliceIteratorPack::EOrderedBy EOrderedBy
void initialize(index_type rows, index_type cols, EIdentityOrZero type)
Initialize an identity or zero permutation.
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
const_iterator end() const
Return the end of this->const_iterator_begin().
void bind(const GenPermMatrixSlice &gpms)
Bind the view of another GenPermMatrixSlice object.
This is a full random access iterator for accessing row and colunmn indices.
const GenPermMatrixSlice create_submatrix(const Range1D &rng, EOrderedBy ordered_by) const
Create a submatrix by row, by column.
const_iterator begin() const
Return a random access iterator for accessing which row and column that each nonzero 1...
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
index_type lookup_row_i(index_type col_j) const
Lookup the ith row index for the nonzero entry in the jth column if it exists.
void initialize_and_sort(index_type rows, index_type cols, index_type nz, difference_type row_off, difference_type col_off, EOrderedBy ordered_by, index_type row_i[], index_type col_j[], bool test_setup=false)
Initialize and sort.
index_type lookup_col_j(index_type row_i) const
Lookup the jth column index for the nonzero entry in the ith row if it exists.
Concrete matrix type to represent general permutation (mapping) matrices.
GenPermMatrixSliceIteratorPack::row_col_iterator< const index_type > const_iterator