CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
SparseVector.cpp
Go to the documentation of this file.
1/// \file SparseVector_petscd.cpp
2/// \ingroup Tests
3/// \ingroup Vector
4/// A superficial sanity check of one_norm and
5/// vector arithmetic for the sparse vector class.
6
7#include <SparseVector.h>
8#include "../Utils_Fill.h"
9
10using namespace std;
11using namespace CppNoddy;
12
13int main()
14{
15
16 cout << "\n";
17 cout << "=== Vector: sparse class example ===================\n";
18 cout << "\n";
19
20 SparseVector<double> vecA( 100 );
21 Utils_Fill::fill_random( vecA, 25 );
22 double oneA = vecA.one_norm();
23
24 SparseVector<double> vecB( 100 );
25 Utils_Fill::fill_random( vecB, 25 );
26 double oneB = vecB.one_norm();
27
28 SparseVector<double> vecC( 100 );
29 vecC = vecA * 2. + vecB * 2.;
30
31 double tol = 1.e-13;
32 if ( vecC.one_norm() - ( 2 * oneA + 2 * oneB ) > tol )
33 {
34 cout << "\033[1;31;48m * FAILED \033[0m\n";
35 return 1;
36 }
37 cout << "\033[1;32;48m * PASSED \033[0m\n";
38 return 0;
39
40}
41
42
43
A templated SparseVector class – a sparse, variable size, vector object.
int main()
An SparseVector class – a sparse vector object.
Definition: SparseVector.h:20
double one_norm() const
l1-norm.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
void fill_random(CppNoddy::SparseVector< double > &V, const unsigned &num_of_elts)
Definition: Utils_Fill.h:53

© 2012

R.E. Hewitt