Teuchos - Trilinos Tools Package Version of the Day
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 // 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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 
00043 #ifndef _TEUCHOS_SERIALDENSEVECTOR_HPP_
00044 #define _TEUCHOS_SERIALDENSEVECTOR_HPP_
00045 
00050 #include "Teuchos_ConfigDefs.hpp"
00051 #include "Teuchos_Object.hpp" 
00052 #include "Teuchos_SerialDenseMatrix.hpp"
00053 
00057 namespace Teuchos {
00058 
00059   template<typename OrdinalType, typename ScalarType>
00060   class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
00061     
00062   public:
00064 
00065 
00067 
00069     SerialDenseVector();
00070 
00072 
00079     SerialDenseVector(OrdinalType length, bool zeroOut = true);
00080 
00082 
00087     SerialDenseVector(DataAccess CV, ScalarType* values, OrdinalType length);
00088 
00090     SerialDenseVector(const SerialDenseVector<OrdinalType,ScalarType>& Source);
00091 
00093     virtual ~SerialDenseVector ();
00095 
00097 
00098 
00100 
00107     int size(OrdinalType length_in)
00108       {return(SerialDenseMatrix<OrdinalType, ScalarType>::shape(length_in, 1));}
00109 
00111     int sizeUninitialized(OrdinalType length_in)
00112       {return(SerialDenseMatrix<OrdinalType, ScalarType>::shapeUninitialized(length_in, 1));}
00113 
00115 
00121     int resize(OrdinalType length_in)
00122       {return(SerialDenseMatrix<OrdinalType,ScalarType>::reshape(length_in, 1));}
00124 
00126 
00127 
00129 
00132     SerialDenseVector<OrdinalType, ScalarType>& operator= (const ScalarType value) { this->putScalar(value); return(*this); }
00134 
00136 
00137 
00138 
00140     bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
00141 
00143 
00145     bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
00147 
00149 
00150 
00152 
00158     SerialDenseVector<OrdinalType,ScalarType>& operator = (const SerialDenseVector<OrdinalType,ScalarType>& Source);
00160 
00162 
00163 
00164 
00168     ScalarType& operator () (OrdinalType index);
00169     
00171 
00175     const ScalarType& operator () (OrdinalType index) const;
00176 
00178 
00182     ScalarType& operator [] (OrdinalType index);
00183 
00185 
00189     const ScalarType& operator [] (OrdinalType index) const;
00190 
00192 
00194 
00195 
00196     ScalarType dot( const SerialDenseVector<OrdinalType,ScalarType> &x) const;
00198 
00200 
00201 
00202     OrdinalType length() const {return(this->numRows_);}
00204 
00206 
00207 
00208     virtual void print(std::ostream& os) const;
00210 };
00211 
00212   template<typename OrdinalType, typename ScalarType>
00213   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector() : SerialDenseMatrix<OrdinalType,ScalarType>() {}
00214 
00215   template<typename OrdinalType, typename ScalarType>
00216   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( OrdinalType length_in, bool zeroOut ) : SerialDenseMatrix<OrdinalType,ScalarType>( length_in, 1, zeroOut ) {}
00217 
00218   template<typename OrdinalType, typename ScalarType>
00219   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values_in, OrdinalType length_in) : 
00220     SerialDenseMatrix<OrdinalType,ScalarType>( CV, values_in, length_in, length_in, 1 ) {}
00221 
00222   template<typename OrdinalType, typename ScalarType>
00223   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(const SerialDenseVector<OrdinalType, ScalarType> &Source) :
00224     SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {}
00225 
00226   template<typename OrdinalType, typename ScalarType>
00227   SerialDenseVector<OrdinalType, ScalarType>::~SerialDenseVector() {}
00228   
00229   template<typename OrdinalType, typename ScalarType>
00230   SerialDenseVector<OrdinalType, ScalarType>& SerialDenseVector<OrdinalType,ScalarType>::operator = (const SerialDenseVector<OrdinalType, ScalarType>& Source) 
00231   {
00232     SerialDenseMatrix<OrdinalType,ScalarType>::operator=(Source); 
00233     return(*this);
00234   }
00235 
00236   template<typename OrdinalType, typename ScalarType>
00237   bool SerialDenseVector<OrdinalType, ScalarType>::operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const 
00238   {
00239     bool result = 1;
00240     if(this->numRows_ != Operand.numRows_)
00241       {
00242   result = 0;
00243       }
00244     else
00245       {
00246   OrdinalType i;
00247   for(i = 0; i < this->numRows_; i++) {
00248     if((*this)(i) != Operand(i))
00249       {
00250         return 0;
00251       }
00252   }
00253       }
00254     return result;
00255   }
00256 
00257   template<typename OrdinalType, typename ScalarType>
00258   bool SerialDenseVector<OrdinalType, ScalarType>::operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const
00259   {
00260     return !((*this)==Operand);
00261   }
00262 
00263   template<typename OrdinalType, typename ScalarType>
00264   ScalarType SerialDenseVector<OrdinalType, ScalarType>::dot( const SerialDenseVector<OrdinalType, ScalarType> &x) const
00265   {
00266     TEST_FOR_EXCEPTION(this->numRows_!= x.numRows_, std::invalid_argument,
00267     "SerialDenseVector<T>::dot : " << 
00268     "Number of rows " << this->numRows_ << " not equal to x.numRows_ "<< x.numRows() );
00269    
00270     // Compute the dot product and return the result. 
00271     return BLAS<OrdinalType, ScalarType>::DOT(this->numRows_, this->values(), 1, x.values(), 1); 
00272   } 
00273 
00274   template<typename OrdinalType, typename ScalarType>
00275   void SerialDenseVector<OrdinalType, ScalarType>::print(std::ostream& os) const
00276   {
00277     os << std::endl;
00278     if(this->valuesCopied_)
00279       os << "Values_copied : yes" << std::endl;
00280     else
00281       os << "Values_copied : no" << std::endl;
00282       os << "Length : " << this->numRows_ << std::endl;
00283     if(this->numRows_ == 0) {
00284       os << "(std::vector is empty, no values to display)" << std::endl;
00285     } else {
00286       for(OrdinalType i = 0; i < this->numRows_; i++) {
00287     os << (*this)(i) << " ";
00288       }
00289       os << std::endl;
00290     }
00291   }
00292 
00293   //----------------------------------------------------------------------------------------------------
00294   //   Accessor methods 
00295   //----------------------------------------------------------------------------------------------------
00296 
00297   template<typename OrdinalType, typename ScalarType>
00298   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index)
00299   {
00300 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00301     this->checkIndex( index );
00302 #endif
00303     return(this->values_[index]);
00304   }
00305   
00306   template<typename OrdinalType, typename ScalarType>
00307   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index) const
00308   {
00309 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00310     this->checkIndex( index );
00311 #endif
00312     return(this->values_[index]);
00313   }
00314   
00315   template<typename OrdinalType, typename ScalarType>
00316   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) const
00317   {
00318 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00319     this->checkIndex( index );
00320 #endif
00321     return(this->values_[index]);
00322   }
00323   
00324   template<typename OrdinalType, typename ScalarType>
00325   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index)
00326   {
00327 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00328     this->checkIndex( index );
00329 #endif
00330     return(this->values_[index]);
00331   }
00332 
00333 } // namespace Teuchos
00334 
00335 #endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines