Matrix_Cholesky_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include <iostream>
40 
41 #include "Matrix.hpp"
42 #include "Vector.hpp"
43 #include "TestUtil.hpp"
44 
45 using namespace std;
46 
47 void choleskyTest(size_t r, size_t c,
48  double xA[], double xB[], double xBSref[],
49  gnsstk::TestUtil& testFramework, const std::string& str)
50 {
51  testFramework.changeSourceMethod(str);
52  double eps=5*DBL_EPSILON;
54  A = xA;
56  C(A);
57 
58  TUASSERTFEPS( A, C.L * transpose(C.L), eps);
59  TUASSERTFEPS( A, C.U * transpose(C.U), eps);
60 
61  gnsstk::Vector<double> B(r), BSref(r);
62  B = xB;
63  BSref = xBSref;
64  C.backSub(B);
65  TUASSERTFEPS( B, BSref, eps);
66 }
67 
68 
69 void choleskyCroutTest(size_t r, size_t c,
70  double xA[], double xB[], double xBSref[],
71  gnsstk::TestUtil& testFramework, const std::string& str)
72 {
73  testFramework.changeSourceMethod(str);
74  double eps=5*DBL_EPSILON;
76  A = xA;
78  C(A);
79 
80  TUASSERTFEPS( A, C.L * transpose(C.L), eps);
81  TUASSERTFEPS( A, transpose(C.U) * C.U, eps);
82 
83  gnsstk::Vector<double> B(r), BSref(r);
84  B = xB;
85  BSref = xBSref;
86  C.backSub(B);
87  TUASSERTFEPS( B, BSref, eps);
88 }
89 
90 
91 int main()
92 {
93  double a22[4] = {2,1,1,2};
94  double b2[2] = {1,2};
95  double bs2[2] = {0,1};
96 
97  double a33[9] = {2,-1,0,-1,2,-1,0,-1,2};
98  double b3[3] = {7,-3,2};
99  double bs3[3] = {4.25,1.5,1.75};
100 
101  double a44[16] = {2,-1,0,0,-1,2,-1,0,0,-1,2,-1,0,0,-1,2};
102  double b4[4] = {5,1,-2,6};
103  double bs4[4] ={5,5,4,5};
104 
105  gnsstk::TestUtil testFramework("Matrix Cholesky", "--", __FILE__, __LINE__);
106  choleskyTest(2, 2, a22, b2, bs2, testFramework, "2x2");
107  choleskyTest(3, 3, a33, b3, bs3, testFramework, "3x3");
108  choleskyTest(4, 4, a44, b4, bs4, testFramework, "4x4");
109 
110  gnsstk::TestUtil testFramework2("Matrix CholeskyCrout", "--", __FILE__, __LINE__);
111  choleskyCroutTest(2, 2, a22, b2, bs2, testFramework2, "2x2");
112  choleskyCroutTest(3, 3, a33, b3, bs3, testFramework2, "3x3");
113  choleskyCroutTest(4, 4, a44, b4, bs4, testFramework2, "4x4");
114 
115  unsigned tf = testFramework.countFails() + testFramework2.countFails();
116  std::cout << "Total Failures for " << __FILE__ << ": " << tf << std::endl;
117 
118  return tf;
119 }
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::Cholesky
Cholesky<double> Ch;.
Definition: MatrixFunctors.hpp:591
choleskyTest
void choleskyTest(size_t r, size_t c, double xA[], double xB[], double xBSref[], gnsstk::TestUtil &testFramework, const std::string &str)
Definition: Matrix_Cholesky_T.cpp:47
gnsstk::Cholesky::L
Matrix< T > L
Lower triangular and Upper triangular Cholesky decompositions.
Definition: MatrixFunctors.hpp:684
gnsstk::TestUtil::changeSourceMethod
void changeSourceMethod(const std::string &newMethod)
Definition: TestUtil.hpp:785
TestUtil.hpp
gnsstk::transpose
SparseMatrix< T > transpose(const SparseMatrix< T > &M)
transpose
Definition: SparseMatrix.hpp:829
gnsstk::Matrix< double >
gnsstk::Cholesky::backSub
void backSub(RefVectorBase< T, BaseClass2 > &b) const
Definition: MatrixFunctors.hpp:656
TUASSERTFEPS
#define TUASSERTFEPS(EXP, GOT, EPS)
Definition: TestUtil.hpp:126
gnsstk::Vector< double >
main
int main()
Definition: Matrix_Cholesky_T.cpp:91
std
Definition: Angle.hpp:142
Matrix.hpp
gnsstk::CholeskyCrout
Definition: MatrixFunctors.hpp:700
gnsstk::TestUtil
Definition: TestUtil.hpp:265
gnsstk::Cholesky::U
Matrix< T > U
Definition: MatrixFunctors.hpp:684
Vector.hpp
choleskyCroutTest
void choleskyCroutTest(size_t r, size_t c, double xA[], double xB[], double xBSref[], gnsstk::TestUtil &testFramework, const std::string &str)
Definition: Matrix_Cholesky_T.cpp:69


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39