Teuchos Package Browser (Single Doxygen Collection)  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 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef _TEUCHOS_SERIALDENSEVECTOR_HPP_
11 #define _TEUCHOS_SERIALDENSEVECTOR_HPP_
12 
17 #include "Teuchos_ConfigDefs.hpp"
18 #include "Teuchos_Object.hpp"
20 
24 namespace Teuchos {
25 
26  template<typename OrdinalType, typename ScalarType>
27  class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
28 
29  public:
31 
32 
34 
37 
39 
46  SerialDenseVector(OrdinalType length, bool zeroOut = true);
47 
49 
54  SerialDenseVector(DataAccess CV, ScalarType* values, OrdinalType length);
55 
58 
60 
63 
65  virtual ~SerialDenseVector ();
67 
69 
70 
72 
79  int size(OrdinalType length_in)
81 
83  int sizeUninitialized(OrdinalType length_in)
85 
87 
93  int resize(OrdinalType length_in)
96 
98 
99 
101 
104  SerialDenseVector<OrdinalType, ScalarType>& operator= (const ScalarType value) { this->putScalar(value); return(*this); }
106 
108 
109 
112  bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
113 
115 
117  bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand) const;
119 
121 
122 
124 
132 
134 
135 
140  ScalarType& operator () (OrdinalType index);
141 
143 
147  const ScalarType& operator () (OrdinalType index) const;
148 
150 
154  ScalarType& operator [] (OrdinalType index);
155 
157 
161  const ScalarType& operator [] (OrdinalType index) const;
162 
164 
166 
167  ScalarType dot( const SerialDenseVector<OrdinalType,ScalarType> &x) const;
170 
172 
173  OrdinalType length() const {return(this->numRows_);}
176 
178 
179  std::ostream& print(std::ostream& os) const;
182 };
183 
184  template<typename OrdinalType, typename ScalarType>
186 
187  template<typename OrdinalType, typename ScalarType>
188  SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( OrdinalType length_in, bool zeroOut ) : SerialDenseMatrix<OrdinalType,ScalarType>( length_in, 1, zeroOut ) {}
189 
190  template<typename OrdinalType, typename ScalarType>
191  SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values_in, OrdinalType length_in) :
192  SerialDenseMatrix<OrdinalType,ScalarType>( CV, values_in, length_in, length_in, 1 ) {}
193 
194  template<typename OrdinalType, typename ScalarType>
196  SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {}
197 
198  template<typename OrdinalType, typename ScalarType>
200  SerialDenseMatrix<OrdinalType,ScalarType>( CV, Source ) {}
201 
202  template<typename OrdinalType, typename ScalarType>
204 
205  template<typename OrdinalType, typename ScalarType>
207  {
209  return(*this);
210  }
211 
212  template<typename OrdinalType, typename ScalarType>
214  {
215  bool result = 1;
216  if(this->numRows_ != Operand.numRows_)
217  {
218  result = 0;
219  }
220  else
221  {
222  OrdinalType i;
223  for(i = 0; i < this->numRows_; i++) {
224  if((*this)(i) != Operand(i))
225  {
226  return 0;
227  }
228  }
229  }
230  return result;
231  }
232 
233  template<typename OrdinalType, typename ScalarType>
235  {
236  return !((*this)==Operand);
237  }
238 
239  template<typename OrdinalType, typename ScalarType>
241  {
242  TEUCHOS_TEST_FOR_EXCEPTION(this->numRows_!= x.numRows_, std::invalid_argument,
243  "SerialDenseVector<T>::dot : " <<
244  "Number of rows " << this->numRows_ << " not equal to x.numRows_ "<< x.numRows() );
245 
246  // Compute the dot product and return the result.
247  return BLAS<OrdinalType, ScalarType>::DOT(this->numRows_, this->values(), 1, x.values(), 1);
248  }
249 
250  template<typename OrdinalType, typename ScalarType>
251  std::ostream& SerialDenseVector<OrdinalType, ScalarType>::print(std::ostream& os) const
252  {
253  os << std::endl;
254  if(this->valuesCopied_)
255  os << "Values_copied : yes" << std::endl;
256  else
257  os << "Values_copied : no" << std::endl;
258  os << "Length : " << this->numRows_ << std::endl;
259  if(this->numRows_ == 0) {
260  os << "(std::vector is empty, no values to display)" << std::endl;
261  } else {
262  for(OrdinalType i = 0; i < this->numRows_; i++) {
263  os << (*this)(i) << " ";
264  }
265  os << std::endl;
266  }
267  return os;
268  }
269 
270  //----------------------------------------------------------------------------------------------------
271  // Accessor methods
272  //----------------------------------------------------------------------------------------------------
273 
274  template<typename OrdinalType, typename ScalarType>
275  inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index)
276  {
277 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
278  this->checkIndex( index );
279 #endif
280  return(this->values_[index]);
281  }
282 
283  template<typename OrdinalType, typename ScalarType>
284  inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (OrdinalType index) const
285  {
286 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
287  this->checkIndex( index );
288 #endif
289  return(this->values_[index]);
290  }
291 
292  template<typename OrdinalType, typename ScalarType>
293  inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index) const
294  {
295 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
296  this->checkIndex( index );
297 #endif
298  return(this->values_[index]);
299  }
300 
301  template<typename OrdinalType, typename ScalarType>
302  inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (OrdinalType index)
303  {
304 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
305  this->checkIndex( index );
306 #endif
307  return(this->values_[index]);
308  }
309 
311 template<typename OrdinalType, typename ScalarType>
313 public:
317  : obj(obj_in) {}
318 };
319 
321 template<typename OrdinalType, typename ScalarType>
322 std::ostream&
323 operator<<(std::ostream &out,
325 {
326  printer.obj.print(out);
327  return out;
328 }
329 
331 template<typename OrdinalType, typename ScalarType>
332 SerialDenseVectorPrinter<OrdinalType,ScalarType>
334 {
336 }
337 
338 
339 } // namespace Teuchos
340 
341 #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.
const SerialDenseVector< OrdinalType, ScalarType > & obj
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
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).
SerialDenseVectorPrinter(const SerialDenseVector< OrdinalType, ScalarType > &obj_in)
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...