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_COOMatrixClass.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_CLASS_H
43 #define COO_MATRIX_CLASS_H
44 
45 #include <valarray>
46 #include <vector>
47 
48 #include "AbstractLinAlgPack_Types.hpp"
49 #include "MiRefCount.h"
50 
51 namespace AbstractLinAlgPack {
52 
61 class COOMatrix {
62 public:
63  // ///////////////////////////////////////////////////////////////
64  // Friends
65 
66  // ///////////////////////////////////////////////////////////////
67  // Public interface
68 
72  typedef AbstractLinAlgPack::size_type size_type;
74  typedef AbstractLinAlgPack::indice_type indice_type;
76  typedef AbstractLinAlgPack::value_type value_type;
77 
79 
93 
95  COOMatrix();
96 
98 
104  COOMatrix& operator=(const COOMatrix& coom);
105 
111 
113  size_type rows() const;
115  size_type cols() const;
117  size_type nz() const;
118 
133  value_type* val();
136  const value_type* val() const;
138  const value_type* const_val() const;
140  indice_type* ivect();
143  const indice_type* ivect() const;
145  const indice_type* const_ivect() const;
147  indice_type* jvect();
149  const indice_type* jvect() const;
151  const indice_type* const_jvect() const;
152 
166  void initialize(std::istream& istrm);
167 
168 private:
169  // ///////////////////////////////////////////////////////////////////////////
170  // Private types
171 
172  typedef MemMngPack::RefCount<
173  std::valarray<indice_type> > va_indice_ref_type;
174 
175  typedef std::valarray<value_type> va_value_type;
176 
177  typedef std::valarray<indice_type> va_indice_type;
178 
179  // ///////////////////////////////////////////////////////////////////////////
180  // Private data members
181 
182  size_type rows_, // The number of rows this sparse matrix represents
183  cols_, // The numner of columns this sparse matrix represents
184  nz_; // The number of non-zero elements this matrix holds.
185  va_value_type val_; // The vector of non-zero elements
186  va_indice_ref_type ivect_ref_, // The vector of row indices
187  jvect_ref_; // The vector of column indices
188 
189  // ///////////////////////////////////////////////////////////////////////////
190  // Private member functions
191 
192 }; // end class COOMatrix
193 
194 // ///////////////////////////////////////////////////////////////////////////////////
195 // Inline member function definitions for COOMatrix
196 
197 // constructors
198 inline COOMatrix::COOMatrix() : rows_(0), cols_(0), nz_(0)
199 {}
200 // dimensions
202  return rows_;
203 }
205  return cols_;
206 }
207 inline COOMatrix::size_type COOMatrix::nz() const {
208  return nz_;
209 }
210 // representation vectors (val, ivect, jvect)
212  return &val_[0];
213 }
214 inline const COOMatrix::value_type* COOMatrix::val() const {
215  return const_val();
216 }
218  return &const_cast<va_value_type&>(val_)[0];
219 }
221  return &(ivect_ref_.obj())[0];
222 }
224  return const_ivect();
225 }
227  return &const_cast<va_indice_type&>(ivect_ref_.const_obj())[0];
228 }
230  return &jvect_ref_.obj()[0];
231 }
233  return const_jvect();
234 }
236  return &const_cast<va_indice_type&>(jvect_ref_.const_obj())[0];
237 }
238 
239 } // end namespace AbstractLinAlgPack
240 
241 #endif // COO_MATRIX_CLASS_H
value_type * val()
Return pointer to raw storage array (length #nz()#) for the values of the non-zero elements...
void resize(size_type rows, size_type cols, size_type nz)
Resize for a rows# by cols# sparse matrix with #nz# elements.
COOMatrix()
Consturct with no storage allocated.
COOMatrix & operator=(const COOMatrix &coom)
Assignment operator.
AbstractLinAlgPack::indice_type indice_type
Sparse Coordinate Matrix abstraction storage class.
size_type cols() const
Returns the number of columns in the column access view.
indice_type * jvect()
Return pointer to raw storage array (length #nz()#) for the column indices of the non-zero elements...
void initialize(std::istream &istrm)
Initialize from an input stream.
size_type rows() const
Return the number of rows in the row access view.