|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
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 00116 00119 SerialDenseVector<OrdinalType, ScalarType>& operator= (const ScalarType value) { this->putScalar(value); return(*this); } 00121 00123 00124 00125 00127 bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const; 00128 00130 00132 bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const; 00134 00136 00137 00139 00145 SerialDenseVector<OrdinalType,ScalarType>& operator = (const SerialDenseVector<OrdinalType,ScalarType>& Source); 00147 00149 00150 00151 00155 ScalarType& operator () (OrdinalType index); 00156 00158 00162 const ScalarType& operator () (OrdinalType index) const; 00163 00165 00169 ScalarType& operator [] (OrdinalType index); 00170 00172 00176 const ScalarType& operator [] (OrdinalType index) const; 00177 00179 00181 00182 00183 ScalarType dot( const SerialDenseVector<OrdinalType,ScalarType> &x) const; 00185 00187 00188 00189 OrdinalType length() const {return(this->numRows_);} 00191 00193 00194 00195 virtual void print(std::ostream& os) const; 00197 }; 00198 00199 template<typename OrdinalType, typename ScalarType> 00200 SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector() : SerialDenseMatrix<OrdinalType,ScalarType>() {} 00201 00202 template<typename OrdinalType, typename ScalarType> 00203 SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( OrdinalType length_in, bool zeroOut ) : SerialDenseMatrix<OrdinalType,ScalarType>( length_in, 1, zeroOut ) {} 00204 00205 template<typename OrdinalType, typename ScalarType> 00206 SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values_in, OrdinalType length_in) : 00207 SerialDenseMatrix<OrdinalType,ScalarType>( CV, values_in, length_in, length_in, 1 ) {} 00208 00209 template<typename OrdinalType, typename ScalarType> 00210 SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(const SerialDenseVector<OrdinalType, ScalarType> &Source) : 00211 SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {} 00212 00213 template<typename OrdinalType, typename ScalarType> 00214 SerialDenseVector<OrdinalType, ScalarType>::~SerialDenseVector() {} 00215 00216 template<typename OrdinalType, typename ScalarType> 00217 SerialDenseVector<OrdinalType, ScalarType>& SerialDenseVector<OrdinalType,ScalarType>::operator = (const SerialDenseVector<OrdinalType, ScalarType>& Source) 00218 { 00219 SerialDenseMatrix<OrdinalType,ScalarType>::operator=(Source); 00220 return(*this); 00221 } 00222 00223 template<typename OrdinalType, typename ScalarType> 00224 bool SerialDenseVector<OrdinalType, ScalarType>::operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const 00225 { 00226 bool result = 1; 00227 if(this->numRows_ != Operand.numRows_) 00228 { 00229 result = 0; 00230 } 00231 else 00232 { 00233 OrdinalType i; 00234 for(i = 0; i < this->numRows_; i++) { 00235 if((*this)(i) != Operand(i)) 00236 { 00237 return 0; 00238 } 00239 } 00240 } 00241 return result; 00242 } 00243 00244 template<typename OrdinalType, typename ScalarType> 00245 bool SerialDenseVector<OrdinalType, ScalarType>::operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const 00246 { 00247 return !((*this)==Operand); 00248 } 00249 00250 template<typename OrdinalType, typename ScalarType> 00251 ScalarType SerialDenseVector<OrdinalType, ScalarType>::dot( const SerialDenseVector<OrdinalType, ScalarType> &x) const 00252 { 00253 TEST_FOR_EXCEPTION(this->numRows_!= x.numRows_, std::invalid_argument, 00254 "SerialDenseVector<T>::dot : " << 00255 "Number of rows " << this->numRows_ << " not equal to x.numRows_ "<< x.numRows() ); 00256 00257 // Compute the dot product and return the result. 00258 return DOT(this->numRows_, this->values(), 1, x.values(), 1); 00259 } 00260 00261 template<typename OrdinalType, typename ScalarType> 00262 void SerialDenseVector<OrdinalType, ScalarType>::print(std::ostream& os) const 00263 { 00264 os << std::endl; 00265 if(this->valuesCopied_) 00266 os << "Values_copied : yes" << std::endl; 00267 else 00268 os << "Values_copied : no" << std::endl; 00269 os << "Length : " << this->numRows_ << std::endl; 00270 if(this->numRows_ == 0) { 00271 os << "(std::vector is empty, no values to display)" << std::endl; 00272 } else { 00273 for(OrdinalType i = 0; i < this->numRows_; i++) { 00274 os << (*this)(i) << " "; 00275 } 00276 os << std::endl; 00277 } 00278 } 00279 00280 //---------------------------------------------------------------------------------------------------- 00281 // Accessor methods 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 template<typename OrdinalType, typename ScalarType> 00294 inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index) const 00295 { 00296 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00297 this->checkIndex( index ); 00298 #endif 00299 return(this->values_[index]); 00300 } 00301 00302 template<typename OrdinalType, typename ScalarType> 00303 inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) const 00304 { 00305 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00306 this->checkIndex( index ); 00307 #endif 00308 return(this->values_[index]); 00309 } 00310 00311 template<typename OrdinalType, typename ScalarType> 00312 inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) 00313 { 00314 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00315 this->checkIndex( index ); 00316 #endif 00317 return(this->values_[index]); 00318 } 00319 00320 } // namespace Teuchos 00321 00322 #endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */
1.7.4