|
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 COO_MATRIX_CLASS_H 00043 #define COO_MATRIX_CLASS_H 00044 00045 #include <valarray> 00046 #include <vector> 00047 00048 #include "AbstractLinAlgPack_Types.hpp" 00049 #include "MiRefCount.h" 00050 00051 namespace AbstractLinAlgPack { 00052 00061 class COOMatrix { 00062 public: 00063 // /////////////////////////////////////////////////////////////// 00064 // Friends 00065 00066 // /////////////////////////////////////////////////////////////// 00067 // Public interface 00068 00072 typedef AbstractLinAlgPack::size_type size_type; 00074 typedef AbstractLinAlgPack::indice_type indice_type; 00076 typedef AbstractLinAlgPack::value_type value_type; 00077 00079 00093 00095 COOMatrix(); 00096 00098 00104 COOMatrix& operator=(const COOMatrix& coom); 00105 00110 void resize(size_type rows, size_type cols, size_type nz); 00111 00113 size_type rows() const; 00115 size_type cols() const; 00117 size_type nz() const; 00118 00133 00134 value_type* val(); 00136 const value_type* val() const; 00138 const value_type* const_val() const; 00140 00141 indice_type* ivect(); 00143 const indice_type* ivect() const; 00145 const indice_type* const_ivect() const; 00147 indice_type* jvect(); 00149 const indice_type* jvect() const; 00151 const indice_type* const_jvect() const; 00152 00166 void initialize(std::istream& istrm); 00167 00168 private: 00169 // /////////////////////////////////////////////////////////////////////////// 00170 // Private types 00171 00172 typedef MemMngPack::RefCount< 00173 std::valarray<indice_type> > va_indice_ref_type; 00174 00175 typedef std::valarray<value_type> va_value_type; 00176 00177 typedef std::valarray<indice_type> va_indice_type; 00178 00179 // /////////////////////////////////////////////////////////////////////////// 00180 // Private data members 00181 00182 size_type rows_, // The number of rows this sparse matrix represents 00183 cols_, // The numner of columns this sparse matrix represents 00184 nz_; // The number of non-zero elements this matrix holds. 00185 va_value_type val_; // The vector of non-zero elements 00186 va_indice_ref_type ivect_ref_, // The vector of row indices 00187 jvect_ref_; // The vector of column indices 00188 00189 // /////////////////////////////////////////////////////////////////////////// 00190 // Private member functions 00191 00192 }; // end class COOMatrix 00193 00194 // /////////////////////////////////////////////////////////////////////////////////// 00195 // Inline member function definitions for COOMatrix 00196 00197 // constructors 00198 inline COOMatrix::COOMatrix() : rows_(0), cols_(0), nz_(0) 00199 {} 00200 // dimensions 00201 inline COOMatrix::size_type COOMatrix::rows() const { 00202 return rows_; 00203 } 00204 inline COOMatrix::size_type COOMatrix::cols() const { 00205 return cols_; 00206 } 00207 inline COOMatrix::size_type COOMatrix::nz() const { 00208 return nz_; 00209 } 00210 // representation vectors (val, ivect, jvect) 00211 inline COOMatrix::value_type* COOMatrix::val() { 00212 return &val_[0]; 00213 } 00214 inline const COOMatrix::value_type* COOMatrix::val() const { 00215 return const_val(); 00216 } 00217 inline const COOMatrix::value_type* COOMatrix::const_val() const { 00218 return &const_cast<va_value_type&>(val_)[0]; 00219 } 00220 inline COOMatrix::indice_type* COOMatrix::ivect() { 00221 return &(ivect_ref_.obj())[0]; 00222 } 00223 inline const COOMatrix::indice_type* COOMatrix::ivect() const { 00224 return const_ivect(); 00225 } 00226 inline const COOMatrix::indice_type* COOMatrix::const_ivect() const { 00227 return &const_cast<va_indice_type&>(ivect_ref_.const_obj())[0]; 00228 } 00229 inline COOMatrix::indice_type* COOMatrix::jvect() { 00230 return &jvect_ref_.obj()[0]; 00231 } 00232 inline const COOMatrix::indice_type* COOMatrix::jvect() const { 00233 return const_jvect(); 00234 } 00235 inline const COOMatrix::indice_type* COOMatrix::const_jvect() const { 00236 return &const_cast<va_indice_type&>(jvect_ref_.const_obj())[0]; 00237 } 00238 00239 } // end namespace AbstractLinAlgPack 00240 00241 #endif // COO_MATRIX_CLASS_H
1.7.6.1