ProteoWizard
Functions | Variables
qrTest.cpp File Reference
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "Types.hpp"
#include "qr.hpp"

Go to the source code of this file.

Functions

template<class matrix_type >
bool isUpperTriangular (const matrix_type &A, double eps)
 
void testReflector ()
 
void testQR ()
 
void testRectangularQR ()
 
int main (int argc, char **argv)
 

Variables

ostream * os_ = 0
 
const double epsilon = 1e-12
 

Function Documentation

◆ isUpperTriangular()

template<class matrix_type >
bool isUpperTriangular ( const matrix_type &  A,
double  eps 
)

Definition at line 39 of file qrTest.cpp.

40{
41 typedef typename matrix_type::size_type size_type;
42 bool upper = true;
43
44 for (size_type i=1; i<A.size2() && upper; i++)
45 {
46 for (size_type j=0; j<i && upper; j++)
47 {
48 upper = fabs(A(i,j)) < eps;
49 }
50 }
51
52 return upper;
53}
#define A

References A.

Referenced by testQR(), and testRectangularQR().

◆ testReflector()

void testReflector ( )

Definition at line 56 of file qrTest.cpp.

57{
58 if (os_) *os_ << "testReflector() begin" << endl;
59
60 dmatrix F(3,3);
61 dvector x(3);
62
63 x(0) = 1;
64 x(1) = 1;
65 x(2) = 0;
66
67 Reflector(x, F);
68
69 dvector v = prod(F, x);
70
71 unit_assert_equal(fabs(v(0)), norm_2(x), epsilon);
72 unit_assert_equal(v(1), 0, epsilon);
73 unit_assert_equal(v(2), 0, epsilon);
74
75 x(0) = -1;
76 x(1) = 1;
77 x(2) = 0;
78
79 if (os_) *os_ << "testReflector() end" << endl;
80}
F
Definition Chemistry.hpp:81
KernelTraitsBase< Kernel >::space_type::abscissa_type x
boost::numeric::ublas::vector< double > dvector
Definition Types.hpp:34
boost::numeric::ublas::matrix< double > dmatrix
Definition Types.hpp:33
void Reflector(const vector_type &x, matrix_type &F)
Definition qr.hpp:39
const double epsilon
Definition qrTest.cpp:35
ostream * os_
Definition qrTest.cpp:34
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References epsilon, F, os_, pwiz::math::Reflector(), unit_assert_equal, and x.

Referenced by main().

◆ testQR()

void testQR ( )

Definition at line 82 of file qrTest.cpp.

83{
84 if (os_) *os_ << "testQR() begin" << endl;
85
86 dmatrix A(3,3);
87 dmatrix Q(3,3);
88 dmatrix R(3,3);
89
90 for (dmatrix::size_type i=0; i< A.size1(); i++)
91 {
92 for (dmatrix::size_type j=0; j<A.size2(); j++)
93 {
94 A(i,j) = ((i==j) || (j == 0));
95 }
96 }
97
98 try {
99 qr<dmatrix>(A, Q, R);
100
102
103 dmatrix diff = (A - prod(Q, R));
104
105 unit_assert_equal(norm_1(diff), 0, epsilon);
106
107 identity_matrix<dmatrix::value_type> eye(Q.size1());
108 diff = prod(Q, herm(Q)) - eye;
109
110 unit_assert_equal(norm_1(diff), 0, epsilon);
111 }
112 catch (boost::numeric::ublas::bad_argument ba)
113 {
114 if (os_) *os_ << "exception: " << ba.what() << endl;
115 }
116
117 if (os_) *os_ << "testQR() end" << endl;
118}
void diff(const string &filename1, const string &filename2)
bool isUpperTriangular(const matrix_type &A, double eps)
Definition qrTest.cpp:39
#define unit_assert(x)
Definition unit.hpp:85

References A, diff(), epsilon, isUpperTriangular(), os_, unit_assert, and unit_assert_equal.

Referenced by main().

◆ testRectangularQR()

void testRectangularQR ( )

Definition at line 120 of file qrTest.cpp.

121{
122 if (os_) *os_ << "testRectangularQR() begin" << endl;
123
124 dmatrix A(5,3);
125 dmatrix Q;
126 dmatrix R;
127
128 for (dmatrix::size_type i=0; i< A.size1(); i++)
129 {
130 for (dmatrix::size_type j=0; j<A.size2(); j++)
131 {
132 A(i,j) = ((i==j) || (j == 0));
133 }
134 }
135
136 try {
137 qr<dmatrix>(A, Q, R);
138
140
141 dmatrix diff = (A - prod(Q, R));
142
143 unit_assert_equal(norm_1(diff), 0, epsilon);
144
145 identity_matrix<dmatrix::value_type> eye(Q.size1());
146 diff = prod(Q, herm(Q)) - eye;
147
148 unit_assert_equal(norm_1(diff), 0, epsilon);
149 }
150 catch (boost::numeric::ublas::bad_argument ba)
151 {
152 if (os_) *os_ << "exception: " << ba.what() << endl;
153 }
154
155 if (os_) *os_ << "testRectangularQR() end" << endl;
156}

References A, diff(), epsilon, isUpperTriangular(), os_, unit_assert, and unit_assert_equal.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 158 of file qrTest.cpp.

159{
160 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
161 if (os_) *os_ << "qrTest\n";
163 testQR();
165
166 return 0;
167}
void testQR()
Definition qrTest.cpp:82
void testReflector()
Definition qrTest.cpp:56
void testRectangularQR()
Definition qrTest.cpp:120

References os_, testQR(), testRectangularQR(), and testReflector().

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 34 of file qrTest.cpp.

Referenced by main(), testQR(), testRectangularQR(), and testReflector().

◆ epsilon

const double epsilon = 1e-12

Definition at line 35 of file qrTest.cpp.

Referenced by testQR(), testRectangularQR(), and testReflector().