CppNoddy  0.92
Loading...
Searching...
No Matches
Functions
DenseVector.cpp File Reference

Some simple sanity checks for the NVector class with both double and complex types. More...

#include <algorithm>
#include <Types.h>
#include <Timer.h>
#include <Utility.h>
#include <Functors.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Some simple sanity checks for the NVector class with both double and complex types.

Definition in file DenseVector.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 18 of file DenseVector.cpp.

19{
20
21 cout << "\n";
22 cout << "=== Vector: (dense) double/complex Example =========\n";
23 cout << "\n";
24
25 const unsigned N = 1000000; // size of vectors
26
27 cout << " Using vectors of size " << N << " \n";
28
29 const double tol = 1.e-13;
30 bool failed = false;
31
33 // a real vector of random entries
34 DenseVector<double> V( N, 0.0 );
36 // a complex vector initialised with the same real vector
37 DenseVector<D_complex> CExample( V );
38
39 // another real vector of random entries
40 DenseVector<double> DExample( N, 0.0 );
41 Utils_Fill::fill_random( DExample );
42
43 const unsigned M = 100; // number of repeats
44 for ( unsigned i = 0; i < M; ++i )
45 {
46 Utility::dot( V, DExample );
47 }
48
49 cout << " \nComplex vectors \n";
50 cout << " Testing norms, nearest_index, max/minabs_index\n";
51 if ( abs( CExample.inf_norm() - *min_element( CExample.begin(), CExample.end(), absDiff_predicate<D_complex>( 1.0 ) ) ) >
52 tol )
53 {
54 std::cout << " - Failed inf_norm/nearest_index Example" << "\n";
55 failed = true;
56 }
57 if ( abs( CExample.inf_norm() - *max_element( CExample.begin(), CExample.end(), abs_predicate<D_complex>() ) )
58 > tol )
59 {
60 std::cout << " - Failed inf_norm/maxabs_index Example" << "\n";
61 failed = true;
62 }
63
64 CExample.one_norm();
65 CExample.two_norm();
66 CExample.inf_norm();
67
68 cout << "\n";
69 cout << " Double vectors \n";
70
71 cout << " Testing norms, nearest_index, max/minabs_index\n";
72 if ( abs( DExample.inf_norm() - *min_element( DExample.begin(), DExample.end(), absDiff_predicate<double>( 1.0 ) ) )
73 > tol )
74 {
75 std::cout << " - Failed inf_norm/nearest_index Example" << "\n";
76 failed = true;
77 }
78 if ( abs( DExample.inf_norm() - *max_element( DExample.begin(), DExample.end(), abs_predicate<double>() ) )
79 > tol )
80 {
81 std::cout << " - Failed inf_norm/maxabs_index Example" << "\n";
82 failed = true;
83 }
84
85 DExample.one_norm();
86 DExample.two_norm();
87 DExample.inf_norm();
88
89 if ( failed )
90 {
91 cout << "\033[1;31;48m * FAILED \033[0m\n";
92 return 1;
93 }
94 else
95 {
96 cout << "\033[1;32;48m * PASSED \033[0m\n";
97 return 0;
98 }
99
100}
@ V
Definition: BVPKarman.cpp:20
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A function object predicate that first computes the absolute difference between two elements and a sp...
Definition: Functors.h:30
A function object predicate that compares the absolute value of two elements and returns a true of el...
Definition: Functors.h:15
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:314
void time_seed()
initialise RNG
Definition: Utils_Fill.h:14
void fill_random(CppNoddy::SparseVector< double > &V, const unsigned &num_of_elts)
Definition: Utils_Fill.h:53

References CppNoddy::DenseVector< _Type >::begin(), CppNoddy::Utility::dot(), CppNoddy::DenseVector< _Type >::end(), Utils_Fill::fill_random(), CppNoddy::DenseVector< _Type >::inf_norm(), CppNoddy::DenseVector< _Type >::one_norm(), Utils_Fill::time_seed(), CppNoddy::DenseVector< _Type >::two_norm(), and V.

© 2012

R.E. Hewitt