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_COOMatrixWithPartitionedView.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 COO_MATRIX_WITH_PARTITIONED_VIEW_H
43 #define COO_MATRIX_WITH_PARTITIONED_VIEW_H
44 
45 #include "AbstractLinAlgPack_COOMatrixClass.hpp"
46 #include "AbstractLinAlgPack_COOMatrixPartitionedViewClass.hpp"
47 
48 namespace AbstractLinAlgPack {
49 
67 public:
68 
69  // /////////////////////////////////////////////////////////////
72 
79 
81 
83  size_type rows() const {
84  return coom_view_.is_initialized() ? coom_view_.rows() : coom_.rows();
85  }
86 
88  size_type cols() const {
89  return coom_view_.is_initialized() ? coom_view_.cols() : coom_.cols();
90  }
91 
94  coom_ = m.coom_;
95  coom_view_.bind(coom_view_);
96  return *this;
97  }
98 
104  coom_ = m;
105  coom_view_.free();
106  return *this;
107  }
108 
109  // /////////////////////////////////////////////////////////////
115 
120  void resize(size_type rows, size_type cols, size_type nz) {
121  coom_view_.free();
122  coom_.resize(rows,cols,nz);
123  }
124 
129  value_type* val() {
130  return coom_.val();
131  }
136  indice_type* ivect() {
137  coom_view_.free();
138  return coom_.ivect();
139  }
144  indice_type* jvect() {
145  coom_view_.free();
146  return coom_.jvect();
147  }
148 
153  void initialize(std::istream& istrm) {
154  coom_view_.free();
155  coom_.initialize(istrm);
156  }
157 
159 
161  const COOMatrix& coom() const {
162  return coom_;
163  }
164 
165  // ////////////////////////////////////////////////////////////////
168 
175  const size_type row_perm[]
176  , const size_type col_perm[]
177  , const size_type num_row_part
178  , const size_type row_part[]
179  , const size_type num_col_part
180  , const size_type col_part[]
181  , const EPartitionOrder partition_order )
182  {
183  coom_view_.create_view(coom_.rows(),coom_.cols(),coom_.nz(),coom_.val(),coom_.const_ivect()
184  ,coom_.const_jvect(),row_perm,col_perm,num_row_part,row_part,num_col_part,col_part
185  ,partition_order);
186  }
187 
189  partition_type partition(size_type overall_p) {
190  return coom_view_.partition(overall_p);
191  }
192 
194  partition_type partition(size_type row_p, size_type col_p) {
195  return coom_view_.partition(row_p, col_p);
196  }
197 
200  return coom_view_.partition(rng_overall_p);
201  }
202 
204 
207  return coom_view_;
208  }
209 
210 
211 private:
212  COOMatrix coom_;
213  partitioned_view_type coom_view_;
214 
215 
216 }; // end class COOMatrixWithPartitionedView
217 
218 
219 } // end namespace AbstractLinAlgPack
220 
221 #endif // COO_MATRIX_WITH_PARTITIONED_VIEW_H
value_type * val()
Return pointer to raw storage array (length #nz()#) for the values of the non-zero elements...
size_type cols() const
return the number of columns in the total view
const COOMatrix & coom() const
Return a const referece to the COOMatrix.
indice_type * jvect()
Return pointer to raw storage array (length #nz()#) for the column indices of the non-zero elements...
value_type * val()
Return pointer to raw storage array (length #nz()#) for the values of the non-zero elements...
bool is_initialized() const
Returns true if a view has been initialized.
indice_type * ivect()
Return pointer to raw storage array (length #nz()#) for the row indices of the non-zero elements...
partition_type partition(size_type overall_p)
Return a partition object for a parition given its overall partition number (1-based).
size_type rows() const
return the number of rows of the total view
void resize(size_type rows, size_type cols, size_type nz)
Resize for a rows# by cols# sparse matrix with #nz# elements.
void bind(const COOMatrixPartitionedView &coom_view)
Bind the view of another partitioned matrix.
void initialize(std::istream &istrm)
Initialize from an input stream.
Sparse Coordinate Matrix abstraction storage class.
size_type cols() const
Returns the number of columns in the column access view.
size_type rows() const
Calls coom_view().rows() if the partitioned view has been initialize and coom().rows() if not...
COOMatrixPartitionedView< indice_type, value_type > partitioned_view_type
COOMatrixWithPartitionedView & operator=(const COOMatrix &m)
Allow assignment to a COOMatrix.
size_type cols() const
Calls coom_view().cols() if the partitioned view has been initialize and coom().cols() if not...
void create_view(size_type rows, size_type cols, size_type nz, value_type val[], const indice_type ivect[], const indice_type jvect[], const size_type inv_row_perm[], const size_type inv_col_perm[], const size_type num_row_part, const size_type row_part[], const size_type num_col_part, const size_type col_part[], const EPartitionOrder partition_order)
Crete a view to a COO matrix.
void create_view(const size_type row_perm[], const size_type col_perm[], const size_type num_row_part, const size_type row_part[], const size_type num_col_part, const size_type col_part[], const EPartitionOrder partition_order)
Crete a view to the COO matrix.
void free()
Free the allocated memory and make uninitialized.
COOMatrixWithPartitionedView & operator=(const COOMatrixWithPartitionedView &m)
Assignment operator.
Aggregation of a COO matrix and a partitioned view of it.
Class for a partition or a set of continous partitions in a partitioned COO matrix.
void resize(size_type rows, size_type cols, size_type nz)
Resize for a rows# by cols# sparse matrix with #nz# elements.
indice_type * jvect()
Return pointer to raw storage array (length #nz()#) for the column indices of the non-zero elements...
const partitioned_view_type & coom_view() const
Return a const referece to the COOMatrixPartitionedView object.
void initialize(std::istream &istrm)
Initialize from an input stream.
size_type rows() const
Return the number of rows in the row access view.