Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
51#include "Teuchos_Object.hpp"
53
57namespace Teuchos {
58
59 template<typename OrdinalType, typename ScalarType>
60 class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
61
62 public:
64
65
67
70
72
80
82
88
91
93
96
98 virtual ~SerialDenseVector ();
100
102
103
105
114
118
120
129
131
132
134
137 SerialDenseVector<OrdinalType, ScalarType>& operator= (const ScalarType value) { this->putScalar(value); return(*this); }
139
141
142
146
148
152
154
155
157
165
167
168
174
176
180 const ScalarType& operator () (OrdinalType index) const;
181
183
188
190
194 const ScalarType& operator [] (OrdinalType index) const;
195
197
199
200
203
205
206
207 OrdinalType length() const {return(this->numRows_);}
209
211
212
213 std::ostream& print(std::ostream& os) const;
215};
216
217 template<typename OrdinalType, typename ScalarType>
219
220 template<typename OrdinalType, typename ScalarType>
222
223 template<typename OrdinalType, typename ScalarType>
226
227 template<typename OrdinalType, typename ScalarType>
230
231 template<typename OrdinalType, typename ScalarType>
234
235 template<typename OrdinalType, typename ScalarType>
237
238 template<typename OrdinalType, typename ScalarType>
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 {
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>
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>
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>
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>
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>
336 {
337#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
338 this->checkIndex( index );
339#endif
340 return(this->values_[index]);
341 }
342
344template<typename OrdinalType, typename ScalarType>
352
354template<typename OrdinalType, typename ScalarType>
355std::ostream&
356operator<<(std::ostream &out,
358{
359 printer.obj.print(out);
360 return out;
361}
362
364template<typename OrdinalType, typename ScalarType>
365SerialDenseVectorPrinter<OrdinalType,ScalarType>
370
371
372} // namespace Teuchos
373
374#endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
The base Teuchos object.
Templated serial dense matrix class.
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.
Concrete serial communicator subclass.
This class creates and provides basic support for dense rectangular matrix of templated type.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
SerialDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
ScalarType * values() const
Data array access method.
This class creates and provides basic support for dense vectors of templated type as a specialization...
bool operator==(const SerialDenseVector< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
OrdinalType length() const
Returns the length of this vector.
bool operator!=(const SerialDenseVector< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
ScalarType & operator[](OrdinalType index)
Element access method (non-const).
int resize(OrdinalType length_in)
Resizing method for changing the size of a SerialDenseVector, keeping the entries.
ScalarType dot(const SerialDenseVector< OrdinalType, ScalarType > &x) const
Compute the dot product of this vector and x.
int size(OrdinalType length_in)
Size method for changing the size of a SerialDenseVector, initializing entries to zero.
int sizeUninitialized(OrdinalType length_in)
Same as size() except leaves values uninitialized.
ScalarType & operator()(OrdinalType index)
Element access method (non-const).
std::ostream & print(std::ostream &os) const
Print method. Define the behavior of the std::ostream << operator inherited from the Object class.
SerialDenseVector< OrdinalType, ScalarType > & operator=(const ScalarType value)
Set all values in the matrix to a constant value.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
Ostream manipulator for SerialDenseVector.
SerialDenseVectorPrinter(const SerialDenseVector< OrdinalType, ScalarType > &obj_in)
const SerialDenseVector< OrdinalType, ScalarType > & obj