Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_SerialDenseVector.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 #ifndef _TEUCHOS_SERIALDENSEVECTOR_HPP_
44 #define _TEUCHOS_SERIALDENSEVECTOR_HPP_
45 
50 #include "Teuchos_ConfigDefs.hpp"
51 #include "Teuchos_Object.hpp"
53 
57 namespace Teuchos {
58 
59  template<typename OrdinalType, typename ScalarType>
60  class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
61 
62  public:
64 
65 
67 
70 
72 
79  SerialDenseVector(OrdinalType length, bool zeroOut = true);
80 
82 
87  SerialDenseVector(DataAccess CV, ScalarType* values, OrdinalType length);
88 
91 
93 
96 
98  virtual ~SerialDenseVector ();
100 
102 
103 
105 
112  int size(OrdinalType length_in)
114 
116  int sizeUninitialized(OrdinalType length_in)
118 
120 
126  int resize(OrdinalType length_in)
129 
131 
132 
134 
137  SerialDenseVector<OrdinalType, ScalarType>& operator= (const ScalarType value) { this->putScalar(value); return(*this); }
139 
141 
142 
145  bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
146 
148 
150  bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
152 
154 
155 
157 
165 
167 
168 
173  ScalarType& operator () (OrdinalType index);
174 
176 
180  const ScalarType& operator () (OrdinalType index) const;
181 
183 
187  ScalarType& operator [] (OrdinalType index);
188 
190 
194  const ScalarType& operator [] (OrdinalType index) const;
195 
197 
199 
200  ScalarType dot( const SerialDenseVector<OrdinalType,ScalarType> &x) const;
203 
205 
206  OrdinalType length() const {return(this->numRows_);}
209 
211 
212  std::ostream& print(std::ostream& os) const;
215 };
216 
217  template<typename OrdinalType, typename ScalarType>
219 
220  template<typename OrdinalType, typename ScalarType>
221  SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( OrdinalType length_in, bool zeroOut ) : SerialDenseMatrix<OrdinalType,ScalarType>( length_in, 1, zeroOut ) {}
222 
223  template<typename OrdinalType, typename ScalarType>
224  SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values_in, OrdinalType length_in) :
225  SerialDenseMatrix<OrdinalType,ScalarType>( CV, values_in, length_in, length_in, 1 ) {}
226 
227  template<typename OrdinalType, typename ScalarType>
229  SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {}
230 
231  template<typename OrdinalType, typename ScalarType>
233  SerialDenseMatrix<OrdinalType,ScalarType>( CV, Source ) {}
234 
235  template<typename OrdinalType, typename ScalarType>
237 
238  template<typename OrdinalType, typename ScalarType>
240  {
242  return(*this);
243  }
244 
245  template<typename OrdinalType, typename ScalarType>
247  {
248  bool result = 1;
249  if(this->numRows_ != Operand.numRows_)
250  {
251  result = 0;
252  }
253  else
254  {
255  OrdinalType i;
256  for(i = 0; i < this->numRows_; i++) {
257  if((*this)(i) != Operand(i))
258  {
259  return 0;
260  }
261  }
262  }
263  return result;
264  }
265 
266  template<typename OrdinalType, typename ScalarType>
268  {
269  return !((*this)==Operand);
270  }
271 
272  template<typename OrdinalType, typename ScalarType>
274  {
275  TEUCHOS_TEST_FOR_EXCEPTION(this->numRows_!= x.numRows_, std::invalid_argument,
276  "SerialDenseVector<T>::dot : " <<
277  "Number of rows " << this->numRows_ << " not equal to x.numRows_ "<< x.numRows() );
278 
279  // Compute the dot product and return the result.
280  return BLAS<OrdinalType, ScalarType>::DOT(this->numRows_, this->values(), 1, x.values(), 1);
281  }
282 
283  template<typename OrdinalType, typename ScalarType>
284  std::ostream& SerialDenseVector<OrdinalType, ScalarType>::print(std::ostream& os) const
285  {
286  os << std::endl;
287  if(this->valuesCopied_)
288  os << "Values_copied : yes" << std::endl;
289  else
290  os << "Values_copied : no" << std::endl;
291  os << "Length : " << this->numRows_ << std::endl;
292  if(this->numRows_ == 0) {
293  os << "(std::vector is empty, no values to display)" << std::endl;
294  } else {
295  for(OrdinalType i = 0; i < this->numRows_; i++) {
296  os << (*this)(i) << " ";
297  }
298  os << std::endl;
299  }
300  return os;
301  }
302 
303  //----------------------------------------------------------------------------------------------------
304  // Accessor methods
305  //----------------------------------------------------------------------------------------------------
306 
307  template<typename OrdinalType, typename ScalarType>
308  inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index)
309  {
310 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
311  this->checkIndex( index );
312 #endif
313  return(this->values_[index]);
314  }
315 
316  template<typename OrdinalType, typename ScalarType>
317  inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index) const
318  {
319 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
320  this->checkIndex( index );
321 #endif
322  return(this->values_[index]);
323  }
324 
325  template<typename OrdinalType, typename ScalarType>
326  inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) const
327  {
328 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
329  this->checkIndex( index );
330 #endif
331  return(this->values_[index]);
332  }
333 
334  template<typename OrdinalType, typename ScalarType>
335  inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index)
336  {
337 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
338  this->checkIndex( index );
339 #endif
340  return(this->values_[index]);
341  }
342 
344 template<typename OrdinalType, typename ScalarType>
346 public:
350  : obj(obj_in) {}
351 };
352 
354 template<typename OrdinalType, typename ScalarType>
355 std::ostream&
356 operator<<(std::ostream &out,
358 {
359  printer.obj.print(out);
360  return out;
361 }
362 
364 template<typename OrdinalType, typename ScalarType>
365 SerialDenseVectorPrinter<OrdinalType,ScalarType>
367 {
369 }
370 
371 
372 } // namespace Teuchos
373 
374 #endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */
ScalarType * values() const
Data array access method.
ScalarType & operator[](OrdinalType index)
Element access method (non-const).
Templated serial dense matrix class.
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
ScalarType dot(const SerialDenseVector< OrdinalType, ScalarType > &x) const
Compute the dot product of this vector and x.
std::ostream & print(std::ostream &os) const
Print method. Define the behavior of the std::ostream &lt;&lt; operator inherited from the Object class...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
int resize(OrdinalType length_in)
Resizing method for changing the size of a SerialDenseVector, keeping the entries.
This class creates and provides basic support for dense vectors of templated type as a specialization...
SerialDenseVector()
Default Constructor.
SerialDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool operator==(const SerialDenseVector< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
ScalarType DOT(const OrdinalType &n, const x_type *x, const OrdinalType &incx, const y_type *y, const OrdinalType &incy) const
Form the dot product of the vectors x and y.
OrdinalType length() const
Returns the length of this vector.
Ostream manipulator for SerialDenseVector.
SerialDenseVector< OrdinalType, ScalarType > & operator=(const ScalarType value)
Set all values in the matrix to a constant value.
The base Teuchos object.
int size(OrdinalType length_in)
Size method for changing the size of a SerialDenseVector, initializing entries to zero...
ScalarType & operator()(OrdinalType index)
Element access method (non-const).
bool operator!=(const SerialDenseVector< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
OrdinalType numRows() const
Returns the row dimension of this matrix.
int sizeUninitialized(OrdinalType length_in)
Same as size() except leaves values uninitialized.
This class creates and provides basic support for dense rectangular matrix of templated type...