Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_SerialDenseVector.cpp
Go to the documentation of this file.
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
44 //=============================================================================
47 {
48  SetLabel("Epetra::SerialDenseVector");
49 }
50 
51 //=============================================================================
53  : Epetra_SerialDenseMatrix(length, 1)
54 {
55  SetLabel("Epetra::SerialDenseVector");
56 }
57 
58 //=============================================================================
60  : Epetra_SerialDenseMatrix(CV_in, values, length, length, 1)
61 {
62  SetLabel("Epetra::SerialDenseVector");
63 }
64 
65 //=============================================================================
67  : Epetra_SerialDenseMatrix(Source)
68 {}
69 
70 //=============================================================================
72 {}
73 
74 //=========================================================================
76  Epetra_SerialDenseMatrix::operator=(Source); // call this->Epetra_SerialDenseMatrix::operator =
77  return(*this);
78 }
79 
80 //=========================================================================
82  int errorcode = Epetra_SerialDenseMatrix::Random();
83  return(errorcode);
84 }
85 
86 //=========================================================================
88 
89 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
90  if (Length()!=x.Length())
91  throw ReportError("Length of this object = " +
92  toString(Length()) + " is not equal to length of x = " + toString(x.Length()), -1);
93 #endif
94 
95  // dot-product of this and x.
96 
97  double result = DOT(Length(), Values(), x.Values());
98 
99  UpdateFlops(2*Length());
100 
101  return(result);
102 }
103 
104 //=========================================================================
106 
107  // 1-norm of vector
108 
109  double result = ASUM(Length(), Values());
110 
111  UpdateFlops(2*Length());
112 
113  return(result);
114 }
115 
116 //=========================================================================
118 
119  // 2-norm of vector
120 
121  double result = NRM2(Length(), Values());
122 
123  UpdateFlops(2*Length());
124 
125  return(result);
126 }
127 //=========================================================================
129 
130  // Inf-norm of vector
131  double result = 0.0;
132  int j = IAMAX(Length(), Values()); // Location of max (-1) if length zero
133 
134  if (j>-1) result = std::abs( (*this)[j]);
135 
136  // UpdateFlops(2*Length()); // Technically there are no FLOPS
137 
138  return(result);
139 }
140 //=========================================================================
141 void Epetra_SerialDenseVector::Print(std::ostream& os) const {
142  if(CV_ == Copy)
143  os << "Data access mode: Copy" << std::endl;
144  else
145  os << "Data access mode: View" << std::endl;
146  if(A_Copied_)
147  os << "A_Copied: yes" << std::endl;
148  else
149  os << "A_Copied: no" << std::endl;
150  os << "Length(M): " << M_ << std::endl;
151  if(M_ == 0)
152  os << "(vector is empty, no values to display)";
153  else
154  for(int i = 0; i < M_; i++)
155  os << (*this)(i) << " ";
156  os << std::endl;
157 }
int Random()
Set matrix values to random numbers.
double Norm2() const
Compute 2-norm of each vector in multi-vector.
float NRM2(const int N, const float *X, const int INCX=1) const
Epetra_BLAS norm function (SNRM2).
Definition: Epetra_BLAS.cpp:81
virtual void SetLabel(const char *const Label)
Epetra_Object Label definition using char *.
double NormInf() const
Compute Inf-norm of each vector in multi-vector.
Epetra_SerialDenseMatrix: A class for constructing and using real double precision general dense matr...
Epetra_SerialDenseVector & operator=(const Epetra_SerialDenseVector &Source)
Value copy from one vector to another.
virtual void Print(std::ostream &os) const
Print service methods; defines behavior of ostream &lt;&lt; operator.
Epetra_SerialDenseVector: A class for constructing and using dense vectors.
std::string toString(const int &x) const
float ASUM(const int N, const float *X, const int INCX=1) const
Epetra_BLAS one norm function (SASUM).
Definition: Epetra_BLAS.cpp:65
int Length() const
Returns length of vector.
Epetra_SerialDenseMatrix & operator=(const Epetra_SerialDenseMatrix &Source)
Value copy from one matrix to another.
int Random()
Set vector values to random numbers.
double Norm1() const
Compute 1-norm of each vector in multi-vector.
Epetra_SerialDenseVector()
Default constructor; defines a zero size object.
int IAMAX(const int N, const float *X, const int INCX=1) const
Epetra_BLAS arg maximum of absolute value function (ISAMAX)
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
float DOT(const int N, const float *X, const float *Y, const int INCX=1, const int INCY=1) const
Epetra_BLAS dot product function (SDOT).
Definition: Epetra_BLAS.cpp:73
double Dot(const Epetra_SerialDenseVector &x) const
Compute 1-norm of each vector in multi-vector.
double * Values() const
Returns pointer to the values in vector.
Epetra_DataAccess
void UpdateFlops(int Flops_in) const
Increment Flop count for this object.
virtual ~Epetra_SerialDenseVector()
Epetra_SerialDenseVector destructor.