Teuchos_SerialDenseVector.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 
00030 #ifndef _TEUCHOS_SERIALDENSEVECTOR_HPP_
00031 #define _TEUCHOS_SERIALDENSEVECTOR_HPP_
00032 
00037 #include "Teuchos_ConfigDefs.hpp"
00038 #include "Teuchos_Object.hpp" 
00039 #include "Teuchos_SerialDenseMatrix.hpp"
00040 
00044 namespace Teuchos {
00045 
00046   template<typename OrdinalType, typename ScalarType>
00047   class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
00048     
00049   public:
00051 
00052 
00054 
00056     SerialDenseVector();
00057 
00059 
00066     SerialDenseVector(OrdinalType length, bool zeroOut = true);
00067 
00069 
00074     SerialDenseVector(DataAccess CV, ScalarType* values, OrdinalType length);
00075 
00077     SerialDenseVector(const SerialDenseVector<OrdinalType,ScalarType>& Source);
00078 
00080     virtual ~SerialDenseVector ();
00082 
00084 
00085 
00087 
00094     int size(OrdinalType length_in)
00095       {return(SerialDenseMatrix<OrdinalType, ScalarType>::shape(length_in, 1));}
00096 
00098     int sizeUninitialized(OrdinalType length_in)
00099       {return(SerialDenseMatrix<OrdinalType, ScalarType>::shapeUninitialized(length_in, 1));}
00100 
00102 
00108     int resize(OrdinalType length_in)
00109       {return(SerialDenseMatrix<OrdinalType,ScalarType>::reshape(length_in, 1));}
00111 
00113 
00114 
00115 
00117     bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand);
00118 
00120 
00122     bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand);
00124 
00126 
00127 
00129 
00135     SerialDenseVector<OrdinalType,ScalarType>& operator = (const SerialDenseVector<OrdinalType,ScalarType>& Source);
00137 
00139 
00140 
00141 
00145     ScalarType& operator () (OrdinalType index);
00146     
00148 
00152     const ScalarType& operator () (OrdinalType index) const;
00153 
00155 
00159     ScalarType& operator [] (OrdinalType index);
00160 
00162 
00166     const ScalarType& operator [] (OrdinalType index) const;
00167 
00169 
00171 
00172 
00173     OrdinalType length() const {return(this->numRows_);}
00175 
00177 
00178 
00179     virtual void print(std::ostream& os) const;
00181 };
00182 
00183   template<typename OrdinalType, typename ScalarType>
00184   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector() : SerialDenseMatrix<OrdinalType,ScalarType>() {}
00185 
00186   template<typename OrdinalType, typename ScalarType>
00187   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( OrdinalType length_in, bool zeroOut ) : SerialDenseMatrix<OrdinalType,ScalarType>( length_in, 1, zeroOut ) {}
00188 
00189   template<typename OrdinalType, typename ScalarType>
00190   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values_in, OrdinalType length_in) : 
00191     SerialDenseMatrix<OrdinalType,ScalarType>( CV, values_in, length_in, length_in, 1 ) {}
00192 
00193   template<typename OrdinalType, typename ScalarType>
00194   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(const SerialDenseVector<OrdinalType, ScalarType> &Source) :
00195     SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {}
00196 
00197   template<typename OrdinalType, typename ScalarType>
00198   SerialDenseVector<OrdinalType, ScalarType>::~SerialDenseVector() {}
00199   
00200   template<typename OrdinalType, typename ScalarType>
00201   SerialDenseVector<OrdinalType, ScalarType>& SerialDenseVector<OrdinalType,ScalarType>::operator = (const SerialDenseVector<OrdinalType, ScalarType>& Source) 
00202   {
00203     SerialDenseMatrix<OrdinalType,ScalarType>::operator=(Source); 
00204     return(*this);
00205   }
00206 
00207   template<typename OrdinalType, typename ScalarType>
00208   bool SerialDenseVector<OrdinalType, ScalarType>::operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) 
00209   {
00210     bool result = 1;
00211     if(this->numRows_ != Operand.numRows_)
00212       {
00213   result = 0;
00214       }
00215     else
00216       {
00217   OrdinalType i;
00218   for(i = 0; i < this->numRows_; i++) {
00219     if((*this)(i) != Operand(i))
00220       {
00221         return 0;
00222       }
00223   }
00224       }
00225     return result;
00226   }
00227 
00228   template<typename OrdinalType, typename ScalarType>
00229   bool SerialDenseVector<OrdinalType, ScalarType>::operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand)
00230   {
00231     return !((*this)==Operand);
00232   }
00233 
00234   template<typename OrdinalType, typename ScalarType>
00235   void SerialDenseVector<OrdinalType, ScalarType>::print(std::ostream& os) const
00236   {
00237     os << std::endl;
00238     if(this->valuesCopied_)
00239       os << "Values_copied : yes" << std::endl;
00240     else
00241       os << "Values_copied : no" << std::endl;
00242       os << "Length : " << this->numRows_ << std::endl;
00243     if(this->numRows_ == 0) {
00244       os << "(std::vector is empty, no values to display)" << std::endl;
00245     } else {
00246       for(OrdinalType i = 0; i < this->numRows_; i++) {
00247     os << (*this)(i) << " ";
00248       }
00249       os << std::endl;
00250     }
00251   }
00252 
00253   //----------------------------------------------------------------------------------------------------
00254   //   Accessor methods 
00255   //----------------------------------------------------------------------------------------------------
00256 
00257   template<typename OrdinalType, typename ScalarType>
00258   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index)
00259   {
00260 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00261     this->checkIndex( index );
00262 #endif
00263     return(this->values_[index]);
00264   }
00265   
00266   template<typename OrdinalType, typename ScalarType>
00267   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index) const
00268   {
00269 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00270     this->checkIndex( index );
00271 #endif
00272     return(this->values_[index]);
00273   }
00274   
00275   template<typename OrdinalType, typename ScalarType>
00276   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) const
00277   {
00278 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00279     this->checkIndex( index );
00280 #endif
00281     return(this->values_[index]);
00282   }
00283   
00284   template<typename OrdinalType, typename ScalarType>
00285   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index)
00286   {
00287 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00288     this->checkIndex( index );
00289 #endif
00290     return(this->values_[index]);
00291   }
00292 
00293 } // namespace Teuchos
00294 
00295 #endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */

Generated on Wed May 12 21:40:32 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7