|
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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef COO_MATRIX_CLASS_H 00030 #define COO_MATRIX_CLASS_H 00031 00032 #include <valarray> 00033 #include <vector> 00034 00035 #include "AbstractLinAlgPack_Types.hpp" 00036 #include "MiRefCount.h" 00037 00038 namespace AbstractLinAlgPack { 00039 00048 class COOMatrix { 00049 public: 00050 // /////////////////////////////////////////////////////////////// 00051 // Friends 00052 00053 // /////////////////////////////////////////////////////////////// 00054 // Public interface 00055 00059 typedef AbstractLinAlgPack::size_type size_type; 00061 typedef AbstractLinAlgPack::indice_type indice_type; 00063 typedef AbstractLinAlgPack::value_type value_type; 00064 00066 00080 00082 COOMatrix(); 00083 00085 00091 COOMatrix& operator=(const COOMatrix& coom); 00092 00097 void resize(size_type rows, size_type cols, size_type nz); 00098 00100 size_type rows() const; 00102 size_type cols() const; 00104 size_type nz() const; 00105 00120 00121 value_type* val(); 00123 const value_type* val() const; 00125 const value_type* const_val() const; 00127 00128 indice_type* ivect(); 00130 const indice_type* ivect() const; 00132 const indice_type* const_ivect() const; 00134 indice_type* jvect(); 00136 const indice_type* jvect() const; 00138 const indice_type* const_jvect() const; 00139 00153 void initialize(std::istream& istrm); 00154 00155 private: 00156 // /////////////////////////////////////////////////////////////////////////// 00157 // Private types 00158 00159 typedef MemMngPack::RefCount< 00160 std::valarray<indice_type> > va_indice_ref_type; 00161 00162 typedef std::valarray<value_type> va_value_type; 00163 00164 typedef std::valarray<indice_type> va_indice_type; 00165 00166 // /////////////////////////////////////////////////////////////////////////// 00167 // Private data members 00168 00169 size_type rows_, // The number of rows this sparse matrix represents 00170 cols_, // The numner of columns this sparse matrix represents 00171 nz_; // The number of non-zero elements this matrix holds. 00172 va_value_type val_; // The vector of non-zero elements 00173 va_indice_ref_type ivect_ref_, // The vector of row indices 00174 jvect_ref_; // The vector of column indices 00175 00176 // /////////////////////////////////////////////////////////////////////////// 00177 // Private member functions 00178 00179 }; // end class COOMatrix 00180 00181 // /////////////////////////////////////////////////////////////////////////////////// 00182 // Inline member function definitions for COOMatrix 00183 00184 // constructors 00185 inline COOMatrix::COOMatrix() : rows_(0), cols_(0), nz_(0) 00186 {} 00187 // dimensions 00188 inline COOMatrix::size_type COOMatrix::rows() const { 00189 return rows_; 00190 } 00191 inline COOMatrix::size_type COOMatrix::cols() const { 00192 return cols_; 00193 } 00194 inline COOMatrix::size_type COOMatrix::nz() const { 00195 return nz_; 00196 } 00197 // representation vectors (val, ivect, jvect) 00198 inline COOMatrix::value_type* COOMatrix::val() { 00199 return &val_[0]; 00200 } 00201 inline const COOMatrix::value_type* COOMatrix::val() const { 00202 return const_val(); 00203 } 00204 inline const COOMatrix::value_type* COOMatrix::const_val() const { 00205 return &const_cast<va_value_type&>(val_)[0]; 00206 } 00207 inline COOMatrix::indice_type* COOMatrix::ivect() { 00208 return &(ivect_ref_.obj())[0]; 00209 } 00210 inline const COOMatrix::indice_type* COOMatrix::ivect() const { 00211 return const_ivect(); 00212 } 00213 inline const COOMatrix::indice_type* COOMatrix::const_ivect() const { 00214 return &const_cast<va_indice_type&>(ivect_ref_.const_obj())[0]; 00215 } 00216 inline COOMatrix::indice_type* COOMatrix::jvect() { 00217 return &jvect_ref_.obj()[0]; 00218 } 00219 inline const COOMatrix::indice_type* COOMatrix::jvect() const { 00220 return const_jvect(); 00221 } 00222 inline const COOMatrix::indice_type* COOMatrix::const_jvect() const { 00223 return &const_cast<va_indice_type&>(jvect_ref_.const_obj())[0]; 00224 } 00225 00226 } // end namespace AbstractLinAlgPack 00227 00228 #endif // COO_MATRIX_CLASS_H
1.7.4