Commit 09162b2fc58b8a74630e11528697aa6a27743e87

Authored by Jürgen Knödlseder
1 parent b2b844a4

Adapt code to renamed matrix classes.

test/test_GLinalg.py
1 1 # ==========================================================================
2 2 # This module performs unit tests for the GammaLib linalg module.
3 3 #
4   -# Copyright (C) 2012 Juergen Knoedlseder
  4 +# Copyright (C) 2012-2013 Juergen Knoedlseder
5 5 #
6 6 # This program is free software: you can redistribute it and/or modify
7 7 # it under the terms of the GNU General Public License as published by
... ... @@ -49,9 +49,9 @@ class Test(GPythonTestSuite):
49 49 self.name("linalg")
50 50  
51 51 # Append tests
52   - self.append(self.test_matrix, "Test GMatrix")
53   - self.append(self.test_sym_matrix, "Test GSymMatrix")
54   - self.append(self.test_sparse_matrix, "Test GSparseMatrix")
  52 + self.append(self.test_matrix, "Test GMatrix")
  53 + self.append(self.test_matrix_sparse, "Test GMatrixSparse")
  54 + self.append(self.test_matrix_symmetric, "Test GMatrixSymmetric")
55 55  
56 56 # Return
57 57 return
... ... @@ -82,17 +82,17 @@ class Test(GPythonTestSuite):
82 82 # Return
83 83 return
84 84  
85   - # Test GSymMatrix class
86   - def test_sym_matrix(self):
  85 + # Test GMatrixSparse class
  86 + def test_matrix_sparse(self):
87 87 """
88   - Test GSymMatrix class.
  88 + Test GMatrixSparse class.
89 89 """
90 90 # Set matrix size
91   - nrows = 3
  91 + nrows = 5
92 92 ncols = 3
93 93  
94 94 # Allocate matrix
95   - m = GSymMatrix(nrows, ncols)
  95 + m = GMatrixSparse(nrows, ncols)
96 96  
97 97 # Fill elements
98 98 for i in range(nrows):
... ... @@ -108,17 +108,17 @@ class Test(GPythonTestSuite):
108 108 # Return
109 109 return
110 110  
111   - # Test GSparseMatrix class
112   - def test_sparse_matrix(self):
  111 + # Test GMatrixSymmetric class
  112 + def test_matrix_symmetric(self):
113 113 """
114   - Test GSparseMatrix class.
  114 + Test GMatrixSymmetric class.
115 115 """
116 116 # Set matrix size
117   - nrows = 5
  117 + nrows = 3
118 118 ncols = 3
119 119  
120 120 # Allocate matrix
121   - m = GSparseMatrix(nrows, ncols)
  121 + m = GMatrixSymmetric(nrows, ncols)
122 122  
123 123 # Fill elements
124 124 for i in range(nrows):
... ... @@ -133,3 +133,4 @@ class Test(GPythonTestSuite):
133 133  
134 134 # Return
135 135 return
  136 +
... ...
test/test_GMatrixSparse.cpp
1 1 /***************************************************************************
2   - * test_GSparseMatrix.cpp - Test sparse matrix class *
  2 + * test_GMatrixSparse.cpp - Test sparse matrix class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2006-2012 by Juergen Knoedlseder *
  4 + * copyright (C) 2006-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -19,7 +19,7 @@
19 19 * *
20 20 ***************************************************************************/
21 21 /**
22   - * @file test_GSparseMatrix.cpp
  22 + * @file test_GMatrixSparse.cpp
23 23 * @brief Implementation of unit tests for sparse matrices
24 24 * @author Juergen Knoedlseder
25 25 */
... ... @@ -29,7 +29,7 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <cmath>
32   -#include "test_GSparseMatrix.hpp"
  32 +#include "test_GMatrixSparse.hpp"
33 33  
34 34 /* __ Globals ____________________________________________________________ */
35 35 double g_matrix[] = {1.0, 7.0, 3.0, 2.0, 4.0, 8.0, 5.0, 6.0, 9.0};
... ... @@ -44,10 +44,10 @@ int g_cols = 5;
44 44 /***************************************************************************
45 45 * @brief Set test matrix
46 46 ***************************************************************************/
47   -GSparseMatrix TestGSparseMatrix::set_matrix(void) const
  47 +GMatrixSparse TestGMatrixSparse::set_matrix(void) const
48 48 {
49 49 // Allocate matrix
50   - GSparseMatrix matrix(g_rows, g_cols);
  50 + GMatrixSparse matrix(g_rows, g_cols);
51 51  
52 52 // Set matrix values
53 53 for (int i = 0; i < g_elements; ++i) {
... ... @@ -63,10 +63,10 @@ GSparseMatrix TestGSparseMatrix::set_matrix(void) const
63 63 * @brief Set test matrix with zero lines
64 64 ***************************************************************************/
65 65 /*
66   -GSparseMatrix TestGSparseMatrix::set_matrix_zero(void) const
  66 +GMatrixSparse TestGMatrixSparse::set_matrix_zero(void) const
67 67 {
68 68 // Allocate matrix
69   - GSparseMatrix matrix(g_rows+1,g_cols+1);
  69 + GMatrixSparse matrix(g_rows+1,g_cols+1);
70 70  
71 71 // Set matrix values
72 72 int i = 0;
... ... @@ -89,7 +89,7 @@ GSparseMatrix TestGSparseMatrix::set_matrix_zero(void) const
89 89 /***************************************************************************
90 90 * @brief Set test vector
91 91 ***************************************************************************/
92   -GVector TestGSparseMatrix::set_vector(void) const
  92 +GVector TestGMatrixSparse::set_vector(void) const
93 93 {
94 94 // Allocate vector
95 95 GVector vector(g_cols);
... ... @@ -114,7 +114,7 @@ GVector TestGSparseMatrix::set_vector(void) const
114 114 * Checks if a matrix corresponds to the test matrix. Optionally, the test
115 115 * matrix can be scaled and an offset can be added.
116 116 ***************************************************************************/
117   -bool TestGSparseMatrix::check_matrix(const GSparseMatrix& matrix,
  117 +bool TestGMatrixSparse::check_matrix(const GMatrixSparse& matrix,
118 118 const double& scale,
119 119 const double& offset) const
120 120 {
... ... @@ -158,7 +158,7 @@ bool TestGSparseMatrix::check_matrix(const GSparseMatrix&amp; matrix,
158 158 * Checks if a matrix corresponds to the test matrix. Optionally, the test
159 159 * matrix can be scaled and an offset can be added.
160 160 ***************************************************************************/
161   -bool TestGSparseMatrix::check_matrix_trans(const GSparseMatrix& matrix,
  161 +bool TestGMatrixSparse::check_matrix_trans(const GMatrixSparse& matrix,
162 162 const double& scale,
163 163 const double& offset) const
164 164 {
... ... @@ -198,8 +198,8 @@ bool TestGSparseMatrix::check_matrix_trans(const GSparseMatrix&amp; matrix,
198 198 * @param[in] matrix Matrix.
199 199 * @param[in] ref Reference matrix.
200 200 ***************************************************************************/
201   -bool TestGSparseMatrix::check_matrix_lt(const GSparseMatrix& matrix,
202   - const GSparseMatrix& ref) const
  201 +bool TestGMatrixSparse::check_matrix_lt(const GMatrixSparse& matrix,
  202 + const GMatrixSparse& ref) const
203 203 {
204 204 // Initialise check with true
205 205 bool result = true;
... ... @@ -239,8 +239,8 @@ bool TestGSparseMatrix::check_matrix_lt(const GSparseMatrix&amp; matrix,
239 239 * @param[in] matrix Matrix.
240 240 * @param[in] ref Reference matrix.
241 241 ***************************************************************************/
242   -bool TestGSparseMatrix::check_matrix_ut(const GSparseMatrix& matrix,
243   - const GSparseMatrix& ref) const
  242 +bool TestGMatrixSparse::check_matrix_ut(const GMatrixSparse& matrix,
  243 + const GMatrixSparse& ref) const
244 244 {
245 245 // Initialise check with true
246 246 bool result = true;
... ... @@ -277,26 +277,26 @@ bool TestGSparseMatrix::check_matrix_ut(const GSparseMatrix&amp; matrix,
277 277 /***********************************************************************//**
278 278 * @brief Set parameters and tests
279 279 **************************************************************************/
280   -void TestGSparseMatrix::set(void)
  280 +void TestGMatrixSparse::set(void)
281 281 {
282 282 // Set test name
283   - name("GSparseMatrix");
  283 + name("GMatrixSparse");
284 284  
285 285 // Add tests
286   - append(static_cast<pfunction>(&TestGSparseMatrix::alloc_matrix), "Test matrix allocation");
287   - append(static_cast<pfunction>(&TestGSparseMatrix::assign_values), "Test value assignment");
288   - append(static_cast<pfunction>(&TestGSparseMatrix::copy_matrix), "Test matrix copying");
289   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_operations), "Test matrix operations");
290   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_arithmetics), "Test matrix arithmetics");
291   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_functions), "Test matrix functions");
292   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_compare), "Test matrix comparisons");
293   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_cholesky), "Test matrix Cholesky decomposition");
294   - append(static_cast<pfunction>(&TestGSparseMatrix::matrix_print), "Test matrix printing");
  286 + append(static_cast<pfunction>(&TestGMatrixSparse::alloc_matrix), "Test matrix allocation");
  287 + append(static_cast<pfunction>(&TestGMatrixSparse::assign_values), "Test value assignment");
  288 + append(static_cast<pfunction>(&TestGMatrixSparse::copy_matrix), "Test matrix copying");
  289 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_operations), "Test matrix operations");
  290 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_arithmetics), "Test matrix arithmetics");
  291 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_functions), "Test matrix functions");
  292 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_compare), "Test matrix comparisons");
  293 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_cholesky), "Test matrix Cholesky decomposition");
  294 + append(static_cast<pfunction>(&TestGMatrixSparse::matrix_print), "Test matrix printing");
295 295  
296 296 // Set members
297 297 m_test = set_matrix();
298 298 v_test = set_vector();
299   - m_bigger = GSparseMatrix(g_rows+1, g_cols+1);
  299 + m_bigger = GMatrixSparse(g_rows+1, g_cols+1);
300 300  
301 301 // Return
302 302 return;
... ... @@ -306,12 +306,12 @@ void TestGSparseMatrix::set(void)
306 306 /***********************************************************************//**
307 307 * @brief Test matrix allocation
308 308 ***************************************************************************/
309   -void TestGSparseMatrix::alloc_matrix(void)
  309 +void TestGMatrixSparse::alloc_matrix(void)
310 310 {
311 311 // Allocate zero matrix. The allocation should fail.
312 312 test_try("Allocate zero matrix");
313 313 try {
314   - GSparseMatrix test(0,0);
  314 + GMatrixSparse test(0,0);
315 315 test_try_failure("Expected GException::empty exception.");
316 316 }
317 317 catch (GException::empty &e) {
... ... @@ -323,7 +323,7 @@ void TestGSparseMatrix::alloc_matrix(void)
323 323  
324 324 // Setup a symmetric sparse matrix
325 325 int size = 30;
326   - GSparseMatrix symmetric(size,size);
  326 + GMatrixSparse symmetric(size,size);
327 327 for (int i = 0; i < size; i+=2) {
328 328 for (int j = 0; j < size; j+=2) {
329 329 symmetric(i,j) = 1.0+i+j;
... ... @@ -334,9 +334,9 @@ void TestGSparseMatrix::alloc_matrix(void)
334 334 test_try("Test symmetric GMatrix conversion");
335 335 try {
336 336 GMatrix cnv_matrix = GMatrix(symmetric);
337   - GSparseMatrix back_matrix = GSparseMatrix(cnv_matrix);
  337 + GMatrixSparse back_matrix = GMatrixSparse(cnv_matrix);
338 338 test_assert((symmetric == back_matrix),
339   - "Test symmetric GSparseMatrix - GMatrix conversion",
  339 + "Test symmetric GMatrixSparse - GMatrix conversion",
340 340 "Found:\n"+back_matrix.print()+"\nExpected:\n"+symmetric.print());
341 341 test_try_success();
342 342 }
... ... @@ -351,9 +351,9 @@ void TestGSparseMatrix::alloc_matrix(void)
351 351 test_try("Test GMatrix conversion");
352 352 try {
353 353 GMatrix cnv_matrix = GMatrix(m_test);
354   - GSparseMatrix back_matrix = GSparseMatrix(cnv_matrix);
  354 + GMatrixSparse back_matrix = GMatrixSparse(cnv_matrix);
355 355 test_assert((m_test == back_matrix),
356   - "Test GSparseMatrix - GMatrix conversion",
  356 + "Test GMatrixSparse - GMatrix conversion",
357 357 "Found:\n"+back_matrix.print()+"\nExpected:\n"+m_test.print());
358 358 test_try_success();
359 359 }
... ... @@ -361,13 +361,13 @@ void TestGSparseMatrix::alloc_matrix(void)
361 361 test_try_failure(e);
362 362 }
363 363  
364   - // Test GSparseMatrix <-> GSymMatrix conversion
365   - test_try("Test GSymMatrix conversion");
  364 + // Test GMatrixSparse <-> GMatrixSymmetric conversion
  365 + test_try("Test GMatrixSymmetric conversion");
366 366 try {
367   - GSymMatrix cnv_sym = GSymMatrix(symmetric);
368   - GSparseMatrix back_sym = GSparseMatrix(cnv_sym);
  367 + GMatrixSymmetric cnv_sym = GMatrixSymmetric(symmetric);
  368 + GMatrixSparse back_sym = GMatrixSparse(cnv_sym);
369 369 test_assert((symmetric == back_sym),
370   - "Test GSparseMatrix - GSymMatrix conversion",
  370 + "Test GMatrixSparse - GMatrixSymmetric conversion",
371 371 "Found:\n"+back_sym.print()+"\nExpected:\n"+symmetric.print());
372 372 test_try_success();
373 373 }
... ... @@ -375,10 +375,10 @@ void TestGSparseMatrix::alloc_matrix(void)
375 375 test_try_failure(e);
376 376 }
377 377  
378   - // Test invalid GSparseMatrix <-> GSymMatrix conversion
379   - test_try("Test invalid GSymMatrix conversion");
  378 + // Test invalid GMatrixSparse <-> GMatrixSymmetric conversion
  379 + test_try("Test invalid GMatrixSymmetric conversion");
380 380 try {
381   - GSymMatrix bad_sym = GSymMatrix(m_test);
  381 + GMatrixSymmetric bad_sym = GMatrixSymmetric(m_test);
382 382 test_try_failure("Expected GException::matrix_not_symmetric exception.");
383 383 }
384 384 catch (GException::matrix_not_symmetric &e) {
... ... @@ -396,10 +396,10 @@ void TestGSparseMatrix::alloc_matrix(void)
396 396 /***********************************************************************//**
397 397 * @brief Test value assignment
398 398 ***************************************************************************/
399   -void TestGSparseMatrix::assign_values(void)
  399 +void TestGMatrixSparse::assign_values(void)
400 400 {
401 401 // Setup 3x3 matrix
402   - GSparseMatrix test(3,3);
  402 + GMatrixSparse test(3,3);
403 403  
404 404 // Assignment individual values
405 405 for (int i = 0; i < 3; ++i) {
... ... @@ -433,12 +433,12 @@ void TestGSparseMatrix::assign_values(void)
433 433 #endif
434 434  
435 435 // Setup 10x10 matrix and keep for reference
436   - GSparseMatrix sparse(10,10);
  436 + GMatrixSparse sparse(10,10);
437 437 for (int i = 3; i < 5; ++i) {
438 438 sparse(i,i) = 5.0;
439 439 }
440   - GSparseMatrix initial = sparse;
441   - GSparseMatrix reference = sparse;
  440 + GMatrixSparse initial = sparse;
  441 + GMatrixSparse reference = sparse;
442 442  
443 443 // Insert column into 10 x 10 matrix using large matrix stack and the
444 444 // add_col(GVector) method
... ... @@ -636,10 +636,10 @@ void TestGSparseMatrix::assign_values(void)
636 636 /***********************************************************************//**
637 637 * @brief Test matrix copy
638 638 ***************************************************************************/
639   -void TestGSparseMatrix::copy_matrix(void)
  639 +void TestGMatrixSparse::copy_matrix(void)
640 640 {
641 641 // Copy matrix
642   - GSparseMatrix test = m_test;
  642 + GMatrixSparse test = m_test;
643 643  
644 644 // Test if original and compied matrices are correct
645 645 test_assert(check_matrix(m_test), "Test source matrix");
... ... @@ -656,7 +656,7 @@ void TestGSparseMatrix::copy_matrix(void)
656 656 *
657 657 * Tests matrix*vector and matrix*matrix multiplication operations.
658 658 ***************************************************************************/
659   -void TestGSparseMatrix::matrix_operations(void)
  659 +void TestGMatrixSparse::matrix_operations(void)
660 660 {
661 661 // Perform vector multiplication
662 662 GVector test1 = m_test * v_test;
... ... @@ -693,10 +693,10 @@ void TestGSparseMatrix::matrix_operations(void)
693 693 }
694 694  
695 695 // Test matrix multiplication
696   - GSparseMatrix test3 = m_test * transpose(m_test);
  696 + GMatrixSparse test3 = m_test * transpose(m_test);
697 697  
698 698 // Check if the result matrix is as expected
699   - GSparseMatrix ref3(g_rows, g_rows);
  699 + GMatrixSparse ref3(g_rows, g_rows);
700 700 for (int row = 0; row < g_rows; ++row) {
701 701 for (int col = 0; col < g_rows; ++col) {
702 702 double value = 0.0;
... ... @@ -735,7 +735,7 @@ void TestGSparseMatrix::matrix_operations(void)
735 735 // Test incompatible matrix multiplication
736 736 test_try("Test incompatible matrix multiplication");
737 737 try {
738   - GSparseMatrix test4 = m_bigger * m_test;
  738 + GMatrixSparse test4 = m_bigger * m_test;
739 739 test_try_failure("Expected GException::matrix_mismatch exception.");
740 740 }
741 741 catch (GException::matrix_mismatch &e) {
... ... @@ -748,7 +748,7 @@ void TestGSparseMatrix::matrix_operations(void)
748 748 // Test another incompatible matrix multiplication
749 749 test_try("Test incompatible matrix multiplication");
750 750 try {
751   - GSparseMatrix test5 = m_bigger * m_test;
  751 + GMatrixSparse test5 = m_bigger * m_test;
752 752 test_try_failure("Expected GException::matrix_mismatch exception.");
753 753 }
754 754 catch (GException::matrix_mismatch &e) {
... ... @@ -768,70 +768,70 @@ void TestGSparseMatrix::matrix_operations(void)
768 768 *
769 769 * Tests matrix arithmetics.
770 770 ***************************************************************************/
771   -void TestGSparseMatrix::matrix_arithmetics(void)
  771 +void TestGMatrixSparse::matrix_arithmetics(void)
772 772 {
773   - // -GSparseMatrix
774   - GSparseMatrix test = -m_test;
  773 + // -GMatrixSparse
  774 + GMatrixSparse test = -m_test;
775 775 test_assert(check_matrix(m_test), "Test source matrix");
776   - test_assert(check_matrix(test, -1.0, 0.0), "Test -GSparseMatrix",
  776 + test_assert(check_matrix(test, -1.0, 0.0), "Test -GMatrixSparse",
777 777 "Unexpected result matrix:\n"+test.print());
778 778  
779   - // GSparseMatrix += GSparseMatrix
  779 + // GMatrixSparse += GMatrixSparse
780 780 test = m_test;
781 781 test += m_test;
782 782 test_assert(check_matrix(m_test), "Test source matrix");
783   - test_assert(check_matrix(test, 2.0, 0.0), "Test GSparseMatrix += GSparseMatrix",
  783 + test_assert(check_matrix(test, 2.0, 0.0), "Test GMatrixSparse += GMatrixSparse",
784 784 "Unexpected result matrix:\n"+test.print());
785 785  
786   - // GSparseMatrix -= GSparseMatrix
  786 + // GMatrixSparse -= GMatrixSparse
787 787 test = m_test;
788 788 test -= m_test;
789 789 test_assert(check_matrix(m_test), "Test source matrix");
790   - test_assert(check_matrix(test, 0.0, 0.0), "Test GSparseMatrix -= GSparseMatrix",
  790 + test_assert(check_matrix(test, 0.0, 0.0), "Test GMatrixSparse -= GMatrixSparse",
791 791 "Unexpected result matrix:\n"+test.print());
792 792  
793   - // GSparseMatrix *= 3.0
  793 + // GMatrixSparse *= 3.0
794 794 test = m_test;
795 795 test *= 3.0;
796 796 test_assert(check_matrix(m_test), "Test source matrix");
797   - test_assert(check_matrix(test, 3.0, 0.0), "Test GSparseMatrix *= 3.0",
  797 + test_assert(check_matrix(test, 3.0, 0.0), "Test GMatrixSparse *= 3.0",
798 798 "Unexpected result matrix:\n"+test.print());
799 799  
800   - // GSparseMatrix /= 3.0
  800 + // GMatrixSparse /= 3.0
801 801 test = m_test;
802 802 test /= 3.0;
803 803 test_assert(check_matrix(m_test), "Test source matrix");
804   - test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GSparseMatrix /= 3.0",
  804 + test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSparse /= 3.0",
805 805 "Unexpected result matrix:\n"+test.print());
806 806  
807   - // GSparseMatrix + GSparseMatrix
  807 + // GMatrixSparse + GMatrixSparse
808 808 test = m_test + m_test;
809 809 test_assert(check_matrix(m_test), "Test source matrix");
810   - test_assert(check_matrix(test, 2.0, 0.0), "Test GSparseMatrix + GSparseMatrix",
  810 + test_assert(check_matrix(test, 2.0, 0.0), "Test GMatrixSparse + GMatrixSparse",
811 811 "Unexpected result matrix:\n"+test.print());
812 812  
813   - // GSparseMatrix - GSparseMatrix
  813 + // GMatrixSparse - GMatrixSparse
814 814 test = m_test - m_test;
815 815 test_assert(check_matrix(m_test), "Test source matrix");
816   - test_assert(check_matrix(test, 0.0, 0.0), "Test GSparseMatrix - GSparseMatrix",
  816 + test_assert(check_matrix(test, 0.0, 0.0), "Test GMatrixSparse - GMatrixSparse",
817 817 "Unexpected result matrix:\n"+test.print());
818 818  
819   - // GSparseMatrix * 3.0
  819 + // GMatrixSparse * 3.0
820 820 test = m_test * 3.0;
821 821 test_assert(check_matrix(m_test), "Test source matrix");
822   - test_assert(check_matrix(test, 3.0, 0.0), "Test GSparseMatrix * 3.0",
  822 + test_assert(check_matrix(test, 3.0, 0.0), "Test GMatrixSparse * 3.0",
823 823 "Unexpected result matrix:\n"+test.print());
824 824  
825   - // 3.0 * GSparseMatrix
  825 + // 3.0 * GMatrixSparse
826 826 test = 3.0 * m_test;
827 827 test_assert(check_matrix(m_test), "Test source matrix");
828   - test_assert(check_matrix(test, 3.0, 0.0), "Test 3.0 * GSparseMatrix",
  828 + test_assert(check_matrix(test, 3.0, 0.0), "Test 3.0 * GMatrixSparse",
829 829 "Unexpected result matrix:\n"+test.print());
830 830  
831   - // GSparseMatrix / 3.0
  831 + // GMatrixSparse / 3.0
832 832 test = m_test / 3.0;
833 833 test_assert(check_matrix(m_test), "Test source matrix");
834   - test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GSparseMatrix / 3.0",
  834 + test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSparse / 3.0",
835 835 "Unexpected result matrix:\n"+test.print());
836 836  
837 837 // Test invalid matrix addition
... ... @@ -858,7 +858,7 @@ void TestGSparseMatrix::matrix_arithmetics(void)
858 858 *
859 859 * Tests matrix functions.
860 860 ***************************************************************************/
861   -void TestGSparseMatrix::matrix_functions(void)
  861 +void TestGMatrixSparse::matrix_functions(void)
862 862 {
863 863 // Minimum
864 864 double min = m_test.min();
... ... @@ -890,10 +890,10 @@ void TestGSparseMatrix::matrix_functions(void)
890 890 test_value(sum, value, 1.0e-20, "Test sum function");
891 891  
892 892 // Transpose function
893   - GSparseMatrix test1 = transpose(m_test);
  893 + GMatrixSparse test1 = transpose(m_test);
894 894 test_assert(check_matrix(m_test), "Test source matrix");
895 895 test_assert(check_matrix_trans(test1, 1.0, 0.0),
896   - "Test transpose(GSparseMatrix) function",
  896 + "Test transpose(GMatrixSparse) function",
897 897 "Unexpected transposed matrix:\n"+test1.print());
898 898  
899 899 // Transpose method
... ... @@ -901,15 +901,15 @@ void TestGSparseMatrix::matrix_functions(void)
901 901 test1.transpose();
902 902 test_assert(check_matrix(m_test), "Test source matrix");
903 903 test_assert(check_matrix_trans(test1, 1.0, 0.0),
904   - "Test GSparseMatrix.transpose() method",
  904 + "Test GMatrixSparse.transpose() method",
905 905 "Unexpected transposed matrix:\n"+test1.print());
906 906  
907 907 // Convert to general matrix
908   - GSparseMatrix test2 = GSparseMatrix(m_test);
  908 + GMatrixSparse test2 = GMatrixSparse(m_test);
909 909 test_assert(check_matrix(m_test), "Test source matrix");
910 910 test_assert(check_matrix(test2, 1.0, 0.0),
911   - "Test GSparseMatrix(GSparseMatrix) constructor",
912   - "Unexpected GSparseMatrix:\n"+test2.print());
  911 + "Test GMatrixSparse(GMatrixSparse) constructor",
  912 + "Unexpected GMatrixSparse:\n"+test2.print());
913 913  
914 914 // Return
915 915 return;
... ... @@ -919,13 +919,13 @@ void TestGSparseMatrix::matrix_functions(void)
919 919 /***********************************************************************//**
920 920 * @brief Test matrix comparisons
921 921 ***************************************************************************/
922   -void TestGSparseMatrix::matrix_compare(void)
  922 +void TestGMatrixSparse::matrix_compare(void)
923 923 {
924 924 // Allocate an empty matrix
925   - GSparseMatrix empty(g_rows, g_cols);
  925 + GMatrixSparse empty(g_rows, g_cols);
926 926  
927 927 // Allocate a full matrix
928   - GSparseMatrix full(g_rows, g_cols);
  928 + GMatrixSparse full(g_rows, g_cols);
929 929 for (int i = 0; i < g_rows; ++i) {
930 930 for (int j = 0; j < g_rows; ++j) {
931 931 full(i,j) = 1.0 + i*1000.0 + j*10.0;
... ... @@ -960,10 +960,10 @@ void TestGSparseMatrix::matrix_compare(void)
960 960 /***********************************************************************//**
961 961 * @brief Test Cholesky decomposition
962 962 ***************************************************************************/
963   -void TestGSparseMatrix::matrix_cholesky(void)
  963 +void TestGMatrixSparse::matrix_cholesky(void)
964 964 {
965 965 // Setup matrix for Cholesky decomposition
966   - GSparseMatrix chol_test(5,5);
  966 + GMatrixSparse chol_test(5,5);
967 967 chol_test(0,0) = 1.0;
968 968 chol_test(0,1) = 0.2;
969 969 chol_test(0,2) = 0.2;
... ... @@ -993,7 +993,7 @@ void TestGSparseMatrix::matrix_cholesky(void)
993 993 }
994 994  
995 995 // Perform Cholesky decomposition
996   - GSparseMatrix cd = cholesky_decompose(chol_test);
  996 + GMatrixSparse cd = cholesky_decompose(chol_test);
997 997  
998 998 // Perform inplace Cholesky decomposition
999 999 cd = chol_test;
... ... @@ -1052,7 +1052,7 @@ void TestGSparseMatrix::matrix_cholesky(void)
1052 1052 test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method - 5");
1053 1053  
1054 1054 // Setup matrix for Cholesky decomposition with zero row/col
1055   - GSparseMatrix chol_test_zero(6,6);
  1055 + GMatrixSparse chol_test_zero(6,6);
1056 1056 chol_test_zero(0,0) = 1.0;
1057 1057 chol_test_zero(0,1) = 0.2;
1058 1058 chol_test_zero(0,2) = 0.2;
... ... @@ -1068,7 +1068,7 @@ void TestGSparseMatrix::matrix_cholesky(void)
1068 1068 chol_test_zero(5,5) = 1.0;
1069 1069  
1070 1070 // Test compressed Cholesky decomposition
1071   - GSparseMatrix cd_zero = chol_test_zero;
  1071 + GMatrixSparse cd_zero = chol_test_zero;
1072 1072 cd_zero.cholesky_decompose();
1073 1073  
1074 1074 // Test compressed Cholesky solver (first test)
... ... @@ -1124,7 +1124,7 @@ void TestGSparseMatrix::matrix_cholesky(void)
1124 1124 test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method - 5");
1125 1125  
1126 1126 // Setup matrix for Cholesky decomposition with zero row/col (unsymmetric case)
1127   - GSparseMatrix chol_test_zero2(6,5);
  1127 + GMatrixSparse chol_test_zero2(6,5);
1128 1128 chol_test_zero2(0,0) = 1.0;
1129 1129 chol_test_zero2(0,1) = 0.2;
1130 1130 chol_test_zero2(0,2) = 0.2;
... ... @@ -1140,7 +1140,7 @@ void TestGSparseMatrix::matrix_cholesky(void)
1140 1140 chol_test_zero2(5,4) = 1.0;
1141 1141  
1142 1142 // Test compressed Cholesky decomposition (unsymmetric case)
1143   - GSparseMatrix cd_zero2 = chol_test_zero2;
  1143 + GMatrixSparse cd_zero2 = chol_test_zero2;
1144 1144 cd_zero2.cholesky_decompose();
1145 1145  
1146 1146 // Test compressed Cholesky solver (unsymmetric case)
... ... @@ -1201,16 +1201,16 @@ void TestGSparseMatrix::matrix_cholesky(void)
1201 1201 "Test unsymmetric compressed cholesky_solver() method - 5");
1202 1202  
1203 1203 // Test Cholesky inverter (inplace)
1204   - GSparseMatrix unit(5,5);
  1204 + GMatrixSparse unit(5,5);
1205 1205 unit(0,0) = 1.0;
1206 1206 unit(1,1) = 1.0;
1207 1207 unit(2,2) = 1.0;
1208 1208 unit(3,3) = 1.0;
1209 1209 unit(4,4) = 1.0;
1210   - GSparseMatrix chol_test_inv = chol_test;
  1210 + GMatrixSparse chol_test_inv = chol_test;
1211 1211 chol_test_inv.cholesky_invert();
1212   - GSparseMatrix ci_product = chol_test * chol_test_inv;
1213   - GSparseMatrix ci_residuals = ci_product - unit;
  1212 + GMatrixSparse ci_product = chol_test * chol_test_inv;
  1213 + GMatrixSparse ci_residuals = ci_product - unit;
1214 1214 res = (abs(ci_residuals)).max();
1215 1215 test_value(res, 0.0, 1.0e-15, "Test inplace Cholesky inverter");
1216 1216  
... ... @@ -1222,16 +1222,16 @@ void TestGSparseMatrix::matrix_cholesky(void)
1222 1222 test_value(res, 0.0, 1.0e-15, "Test Cholesky inverter");
1223 1223  
1224 1224 // Test Cholesky inverter for compressed matrix
1225   - unit = GSparseMatrix(6,6);
  1225 + unit = GMatrixSparse(6,6);
1226 1226 unit(0,0) = 1.0;
1227 1227 unit(1,1) = 1.0;
1228 1228 unit(2,2) = 1.0;
1229 1229 unit(4,4) = 1.0;
1230 1230 unit(5,5) = 1.0;
1231   - GSparseMatrix chol_test_zero_inv = chol_test_zero;
  1231 + GMatrixSparse chol_test_zero_inv = chol_test_zero;
1232 1232 chol_test_zero_inv.cholesky_invert();
1233   - GSparseMatrix ciz_product = chol_test_zero * chol_test_zero_inv;
1234   - GSparseMatrix ciz_residuals = ciz_product - unit;
  1233 + GMatrixSparse ciz_product = chol_test_zero * chol_test_zero_inv;
  1234 + GMatrixSparse ciz_residuals = ciz_product - unit;
1235 1235 res = (abs(ciz_residuals)).max();
1236 1236 test_value(res, 0.0, 1.0e-15, "Test compressed matrix Cholesky inverter");
1237 1237  
... ... @@ -1243,11 +1243,11 @@ void TestGSparseMatrix::matrix_cholesky(void)
1243 1243 /***************************************************************************
1244 1244 * @brief Test matrix printing
1245 1245 ***************************************************************************/
1246   -void TestGSparseMatrix::matrix_print(void)
  1246 +void TestGMatrixSparse::matrix_print(void)
1247 1247 {
1248 1248 // Set reference
1249 1249 std::string reference;
1250   - reference.append("=== GSparseMatrix ===\n");
  1250 + reference.append("=== GMatrixSparse ===\n");
1251 1251 reference.append(" Number of rows ............: 4\n");
1252 1252 reference.append(" Number of columns .........: 5\n");
1253 1253 reference.append(" Number of nonzero elements : 9\n");
... ... @@ -1268,7 +1268,7 @@ void TestGSparseMatrix::matrix_print(void)
1268 1268 "Unexpected print() output:\n"+output+"\nExpected:\n"+reference);
1269 1269  
1270 1270 // Allocate big matrix
1271   - GSparseMatrix big(30, 40);
  1271 + GMatrixSparse big(30, 40);
1272 1272 for (int i = 0; i < 30; ++i) {
1273 1273 for (int j = 0; j < 40; ++j) {
1274 1274 big(i,j) = i+j;
... ... @@ -1277,7 +1277,7 @@ void TestGSparseMatrix::matrix_print(void)
1277 1277  
1278 1278 // Set reference for big matrix
1279 1279 std::string ref_big;
1280   - ref_big.append("=== GSparseMatrix ===\n");
  1280 + ref_big.append("=== GMatrixSparse ===\n");
1281 1281 ref_big.append(" Number of rows ............: 30\n");
1282 1282 ref_big.append(" Number of columns .........: 40\n");
1283 1283 ref_big.append(" Number of nonzero elements : 1199\n");
... ... @@ -1315,13 +1315,13 @@ void TestGSparseMatrix::matrix_print(void)
1315 1315 int main(void)
1316 1316 {
1317 1317 // Allocate test suit container
1318   - GTestSuites testsuites("GSparseMatrix class testing");
  1318 + GTestSuites testsuites("GMatrixSparse class testing");
1319 1319  
1320 1320 // Initially assume that we pass all tests
1321 1321 bool success = true;
1322 1322  
1323 1323 // Create a test suite
1324   - TestGSparseMatrix test;
  1324 + TestGMatrixSparse test;
1325 1325  
1326 1326 // Append test suite to the container
1327 1327 testsuites.append(test);
... ... @@ -1330,7 +1330,7 @@ int main(void)
1330 1330 success = testsuites.run();
1331 1331  
1332 1332 // Save test report
1333   - testsuites.save("reports/GSparseMatrix.xml");
  1333 + testsuites.save("reports/GMatrixSparse.xml");
1334 1334  
1335 1335 // Return success status
1336 1336 return (success ? 0 : 1);
... ...
test/test_GMatrixSparse.hpp
1 1 /***************************************************************************
2   - * test_GSparseMatrix.hpp - Test sparse matrix class *
  2 + * test_GMatrixSparse.hpp - Test sparse matrix class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -19,20 +19,20 @@
19 19 * *
20 20 ***************************************************************************/
21 21 /**
22   - * @file test_GSparseMatrix.hpp
  22 + * @file test_GMatrixSparse.hpp
23 23 * @brief Definition of unit tests for sparse matrices
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
27   -#ifndef TEST_GSPARSEMATRIX_HPP
28   -#define TEST_GSPARSEMATRIX_HPP
  27 +#ifndef TEST_GMATRIXSPARSE_HPP
  28 +#define TEST_GMATRIXSPARSE_HPP
29 29  
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include "GammaLib.hpp"
32 32  
33 33  
34 34 /***********************************************************************//**
35   - * @class TestGSparseMatrix
  35 + * @class TestGMatrixSparse
36 36 *
37 37 * @brief Test suite for sparse matrix class testing
38 38 *
... ... @@ -40,12 +40,12 @@
40 40 * that match logically are gathered in a number of class methods, and the
41 41 * class methods are executed when running the test.
42 42 ***************************************************************************/
43   -class TestGSparseMatrix : public GTestSuite {
  43 +class TestGMatrixSparse : public GTestSuite {
44 44  
45 45 public:
46 46 // Constructors and destructors
47   - TestGSparseMatrix(void) : GTestSuite() {}
48   - virtual ~TestGSparseMatrix(void) {}
  47 + TestGMatrixSparse(void) : GTestSuite() {}
  48 + virtual ~TestGMatrixSparse(void) {}
49 49  
50 50 // Methods
51 51 virtual void set(void);
... ... @@ -61,24 +61,24 @@ public:
61 61  
62 62 private:
63 63 // Private methods
64   - GSparseMatrix set_matrix(void) const;
65   - //GSparseMatrix set_matrix_zero(void) const;
  64 + GMatrixSparse set_matrix(void) const;
  65 + //GMatrixSparse set_matrix_zero(void) const;
66 66 GVector set_vector(void) const;
67   - bool check_matrix(const GSparseMatrix& matrix,
68   - const double& scale = 1.0,
69   - const double& offset = 0.0) const;
70   - bool check_matrix_trans(const GSparseMatrix& matrix,
71   - const double& scale,
72   - const double& offset) const;
73   - bool check_matrix_lt(const GSparseMatrix& matrix,
74   - const GSparseMatrix& ref) const;
75   - bool check_matrix_ut(const GSparseMatrix& matrix,
76   - const GSparseMatrix& ref) const;
  67 + bool check_matrix(const GMatrixSparse& matrix,
  68 + const double& scale = 1.0,
  69 + const double& offset = 0.0) const;
  70 + bool check_matrix_trans(const GMatrixSparse& matrix,
  71 + const double& scale,
  72 + const double& offset) const;
  73 + bool check_matrix_lt(const GMatrixSparse& matrix,
  74 + const GMatrixSparse& ref) const;
  75 + bool check_matrix_ut(const GMatrixSparse& matrix,
  76 + const GMatrixSparse& ref) const;
77 77  
78 78 // Private members;
79   - GSparseMatrix m_test; //!< Test matrix
80   - GSparseMatrix m_bigger; //!< Bigger test matrix (for collisions)
  79 + GMatrixSparse m_test; //!< Test matrix
  80 + GMatrixSparse m_bigger; //!< Bigger test matrix (for collisions)
81 81 GVector v_test; //!< Test vector
82 82 };
83 83  
84   -#endif /* TEST_GSPARSEMATRIX_HPP */
  84 +#endif /* TEST_GMATRIXSPARSE_HPP */
... ...
test/test_GMatrixSymmetric.cpp
1 1 /***************************************************************************
2   - * test_GSymMatrix.cpp - Test symmetric matrix class *
  2 + * test_GMatrixSymmetric.cpp - Test symmetric matrix class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2006-2012 by Juergen Knoedlseder *
  4 + * copyright (C) 2006-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -19,7 +19,7 @@
19 19 * *
20 20 ***************************************************************************/
21 21 /**
22   - * @file test_GSymMatrix.cpp
  22 + * @file test_GMatrixSymmetric.cpp
23 23 * @brief Implementation of unit tests for symmetric matrices
24 24 * @author Juergen Knoedlseder
25 25 */
... ... @@ -29,7 +29,7 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <cmath>
32   -#include "test_GSymMatrix.hpp"
  32 +#include "test_GMatrixSymmetric.hpp"
33 33  
34 34 /* __ Globals ____________________________________________________________ */
35 35 double g_matrix[] = {4.0, 1.0, 2.0, 1.0, 5.0, 3.0, 2.0, 3.0, 6.0};
... ... @@ -41,10 +41,10 @@ int g_cols = 3;
41 41 /***************************************************************************
42 42 * @brief Set test matrix
43 43 ***************************************************************************/
44   -GSymMatrix TestGSymMatrix::set_matrix(void) const
  44 +GMatrixSymmetric TestGMatrixSymmetric::set_matrix(void) const
45 45 {
46 46 // Allocate matrix
47   - GSymMatrix matrix(g_rows,g_cols);
  47 + GMatrixSymmetric matrix(g_rows,g_cols);
48 48  
49 49 // Set matrix values
50 50 for (int row = 0; row < g_rows; ++row) {
... ... @@ -61,10 +61,10 @@ GSymMatrix TestGSymMatrix::set_matrix(void) const
61 61 /***************************************************************************
62 62 * @brief Set test matrix with zero lines
63 63 ***************************************************************************/
64   -GSymMatrix TestGSymMatrix::set_matrix_zero(void) const
  64 +GMatrixSymmetric TestGMatrixSymmetric::set_matrix_zero(void) const
65 65 {
66 66 // Allocate matrix
67   - GSymMatrix matrix(g_rows+1,g_cols+1);
  67 + GMatrixSymmetric matrix(g_rows+1,g_cols+1);
68 68  
69 69 // Set matrix values
70 70 int i = 0;
... ... @@ -87,7 +87,7 @@ GSymMatrix TestGSymMatrix::set_matrix_zero(void) const
87 87 /***************************************************************************
88 88 * @brief Set test vector
89 89 ***************************************************************************/
90   -GVector TestGSymMatrix::set_vector(void) const
  90 +GVector TestGMatrixSymmetric::set_vector(void) const
91 91 {
92 92 // Allocate vector
93 93 GVector vector(g_cols);
... ... @@ -112,9 +112,9 @@ GVector TestGSymMatrix::set_vector(void) const
112 112 * Checks if a matrix corresponds to the test matrix. Optionally, the test
113 113 * matrix can be scaled and an offset can be added.
114 114 ***************************************************************************/
115   -bool TestGSymMatrix::check_matrix(const GSymMatrix& matrix,
116   - const double& scale,
117   - const double& offset) const
  115 +bool TestGMatrixSymmetric::check_matrix(const GMatrixSymmetric& matrix,
  116 + const double& scale,
  117 + const double& offset) const
118 118 {
119 119 // Initialise check with true
120 120 bool result = true;
... ... @@ -145,9 +145,9 @@ bool TestGSymMatrix::check_matrix(const GSymMatrix&amp; matrix,
145 145 * Checks if a matrix corresponds to the test matrix. Optionally, the test
146 146 * matrix can be scaled and an offset can be added.
147 147 ***************************************************************************/
148   -bool TestGSymMatrix::check_matrix(const GMatrix& matrix,
149   - const double& scale,
150   - const double& offset) const
  148 +bool TestGMatrixSymmetric::check_matrix(const GMatrix& matrix,
  149 + const double& scale,
  150 + const double& offset) const
151 151 {
152 152 // Initialise check with true
153 153 bool result = true;
... ... @@ -175,9 +175,9 @@ bool TestGSymMatrix::check_matrix(const GMatrix&amp; matrix,
175 175 * @param[in] scale scale factor (default: 1.0)
176 176 * @param[in] offset offset value (default: 0.0)
177 177 ***************************************************************************/
178   -bool TestGSymMatrix::check_matrix_lt(const GMatrix& matrix,
179   - const double& scale,
180   - const double& offset) const
  178 +bool TestGMatrixSymmetric::check_matrix_lt(const GMatrix& matrix,
  179 + const double& scale,
  180 + const double& offset) const
181 181 {
182 182 // Initialise check with true
183 183 bool result = true;
... ... @@ -206,9 +206,9 @@ bool TestGSymMatrix::check_matrix_lt(const GMatrix&amp; matrix,
206 206 * @param[in] scale scale factor (default: 1.0)
207 207 * @param[in] offset offset value (default: 0.0)
208 208 ***************************************************************************/
209   -bool TestGSymMatrix::check_matrix_ut(const GMatrix& matrix,
210   - const double& scale,
211   - const double& offset) const
  209 +bool TestGMatrixSymmetric::check_matrix_ut(const GMatrix& matrix,
  210 + const double& scale,
  211 + const double& offset) const
212 212 {
213 213 // Initialise check with true
214 214 bool result = true;
... ... @@ -233,26 +233,26 @@ bool TestGSymMatrix::check_matrix_ut(const GMatrix&amp; matrix,
233 233 /***********************************************************************//**
234 234 * @brief Set parameters and tests
235 235 **************************************************************************/
236   -void TestGSymMatrix::set(void)
  236 +void TestGMatrixSymmetric::set(void)
237 237 {
238 238 // Set test name
239   - name("GSymMatrix");
  239 + name("GMatrixSymmetric");
240 240  
241 241 // Add tests
242   - append(static_cast<pfunction>(&TestGSymMatrix::alloc_matrix), "Test matrix allocation");
243   - append(static_cast<pfunction>(&TestGSymMatrix::assign_values), "Test value assignment");
244   - append(static_cast<pfunction>(&TestGSymMatrix::copy_matrix), "Test matrix copying");
245   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_operations), "Test matrix operations");
246   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_arithmetics), "Test matrix arithmetics");
247   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_functions), "Test matrix functions");
248   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_compare), "Test matrix comparisons");
249   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_cholesky), "Test matrix Cholesky decomposition");
250   - append(static_cast<pfunction>(&TestGSymMatrix::matrix_print), "Test matrix printing");
  242 + append(static_cast<pfunction>(&TestGMatrixSymmetric::alloc_matrix), "Test matrix allocation");
  243 + append(static_cast<pfunction>(&TestGMatrixSymmetric::assign_values), "Test value assignment");
  244 + append(static_cast<pfunction>(&TestGMatrixSymmetric::copy_matrix), "Test matrix copying");
  245 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_operations), "Test matrix operations");
  246 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_arithmetics), "Test matrix arithmetics");
  247 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_functions), "Test matrix functions");
  248 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_compare), "Test matrix comparisons");
  249 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_cholesky), "Test matrix Cholesky decomposition");
  250 + append(static_cast<pfunction>(&TestGMatrixSymmetric::matrix_print), "Test matrix printing");
251 251  
252 252 // Set members
253 253 m_test = set_matrix();
254 254 v_test = set_vector();
255   - m_bigger = GSymMatrix(g_rows+1, g_cols+1);
  255 + m_bigger = GMatrixSymmetric(g_rows+1, g_cols+1);
256 256  
257 257 // Return
258 258 return;
... ... @@ -262,12 +262,12 @@ void TestGSymMatrix::set(void)
262 262 /***********************************************************************//**
263 263 * @brief Test matrix allocation
264 264 ***************************************************************************/
265   -void TestGSymMatrix::alloc_matrix(void)
  265 +void TestGMatrixSymmetric::alloc_matrix(void)
266 266 {
267 267 // Allocate zero matrix. The allocation should fail.
268 268 test_try("Allocate zero matrix");
269 269 try {
270   - GSymMatrix test(0,0);
  270 + GMatrixSymmetric test(0,0);
271 271 test_try_failure("Expected GException::empty exception.");
272 272 }
273 273 catch (GException::empty &e) {
... ... @@ -285,10 +285,10 @@ void TestGSymMatrix::alloc_matrix(void)
285 285 /***********************************************************************//**
286 286 * @brief Test value assignment
287 287 ***************************************************************************/
288   -void TestGSymMatrix::assign_values(void)
  288 +void TestGMatrixSymmetric::assign_values(void)
289 289 {
290 290 // Setup 3x3 matrix
291   - GSymMatrix test(3,3);
  291 + GMatrixSymmetric test(3,3);
292 292  
293 293 // Assignment individual values
294 294 for (int i = 0; i < 3; ++i) {
... ... @@ -329,10 +329,10 @@ void TestGSymMatrix::assign_values(void)
329 329 /***********************************************************************//**
330 330 * @brief Test matrix copy
331 331 ***************************************************************************/
332   -void TestGSymMatrix::copy_matrix(void)
  332 +void TestGMatrixSymmetric::copy_matrix(void)
333 333 {
334 334 // Copy matrix
335   - GSymMatrix test = m_test;
  335 + GMatrixSymmetric test = m_test;
336 336  
337 337 // Test if original and compied matrices are correct
338 338 test_assert(check_matrix(m_test), "Test source matrix");
... ... @@ -349,7 +349,7 @@ void TestGSymMatrix::copy_matrix(void)
349 349 *
350 350 * Tests matrix*vector and matrix*matrix multiplication operations.
351 351 ***************************************************************************/
352   -void TestGSymMatrix::matrix_operations(void)
  352 +void TestGMatrixSymmetric::matrix_operations(void)
353 353 {
354 354 // Perform vector multiplication
355 355 GVector test1 = m_test * v_test;
... ... @@ -388,10 +388,10 @@ void TestGSymMatrix::matrix_operations(void)
388 388 }
389 389  
390 390 // Test matrix multiplication
391   - GSymMatrix test3 = m_test * m_test;
  391 + GMatrixSymmetric test3 = m_test * m_test;
392 392  
393 393 // Check if the result matrix is as expected
394   - GSymMatrix ref3 = test3;
  394 + GMatrixSymmetric ref3 = test3;
395 395 result = true;
396 396 for (int row = 0; row < test3.rows(); ++row) {
397 397 for (int col = 0; col < test3.cols(); ++col) {
... ... @@ -417,7 +417,7 @@ void TestGSymMatrix::matrix_operations(void)
417 417 // Test incompatible matrix multiplication
418 418 test_try("Test incompatible matrix multiplication");
419 419 try {
420   - GSymMatrix test4 = m_test * m_bigger;
  420 + GMatrixSymmetric test4 = m_test * m_bigger;
421 421 test_try_failure("Expected GException::matrix_mismatch exception.");
422 422 }
423 423 catch (GException::matrix_mismatch &e) {
... ... @@ -430,7 +430,7 @@ void TestGSymMatrix::matrix_operations(void)
430 430 // Test another incompatible matrix multiplication
431 431 test_try("Test incompatible matrix multiplication");
432 432 try {
433   - GSymMatrix test5 = m_bigger * m_test;
  433 + GMatrixSymmetric test5 = m_bigger * m_test;
434 434 test_try_failure("Expected GException::matrix_mismatch exception.");
435 435 }
436 436 catch (GException::matrix_mismatch &e) {
... ... @@ -450,70 +450,70 @@ void TestGSymMatrix::matrix_operations(void)
450 450 *
451 451 * Tests matrix arithmetics.
452 452 ***************************************************************************/
453   -void TestGSymMatrix::matrix_arithmetics(void)
  453 +void TestGMatrixSymmetric::matrix_arithmetics(void)
454 454 {
455   - // -GSymMatrix
456   - GSymMatrix test = -m_test;
  455 + // -GMatrixSymmetric
  456 + GMatrixSymmetric test = -m_test;
457 457 test_assert(check_matrix(m_test), "Test source matrix");
458   - test_assert(check_matrix(test, -1.0, 0.0), "Test -GSymMatrix",
  458 + test_assert(check_matrix(test, -1.0, 0.0), "Test -GMatrixSymmetric",
459 459 test.print());
460 460  
461   - // GSymMatrix += GSymMatrix
  461 + // GMatrixSymmetric += GMatrixSymmetric
462 462 test = m_test;
463 463 test += m_test;
464 464 test_assert(check_matrix(m_test), "Test source matrix");
465   - test_assert(check_matrix(test, 2.0, 0.0), "Test GSymMatrix += GSymMatrix",
  465 + test_assert(check_matrix(test, 2.0, 0.0), "Test GMatrixSymmetric += GMatrixSymmetric",
466 466 test.print());
467 467  
468   - // GSymMatrix -= GSymMatrix
  468 + // GMatrixSymmetric -= GMatrixSymmetric
469 469 test = m_test;
470 470 test -= m_test;
471 471 test_assert(check_matrix(m_test), "Test source matrix");
472   - test_assert(check_matrix(test, 0.0, 0.0), "Test GSymMatrix -= GSymMatrix",
  472 + test_assert(check_matrix(test, 0.0, 0.0), "Test GMatrixSymmetric -= GMatrixSymmetric",
473 473 test.print());
474 474  
475   - // GSymMatrix *= 3.0
  475 + // GMatrixSymmetric *= 3.0
476 476 test = m_test;
477 477 test *= 3.0;
478 478 test_assert(check_matrix(m_test), "Test source matrix");
479   - test_assert(check_matrix(test, 3.0, 0.0), "Test GSymMatrix *= 3.0",
  479 + test_assert(check_matrix(test, 3.0, 0.0), "Test GMatrixSymmetric *= 3.0",
480 480 test.print());
481 481  
482   - // GSymMatrix /= 3.0
  482 + // GMatrixSymmetric /= 3.0
483 483 test = m_test;
484 484 test /= 3.0;
485 485 test_assert(check_matrix(m_test), "Test source matrix");
486   - test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GSymMatrix /= 3.0",
  486 + test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSymmetric /= 3.0",
487 487 test.print());
488 488  
489   - // GSymMatrix + GSymMatrix
  489 + // GMatrixSymmetric + GMatrixSymmetric
490 490 test = m_test + m_test;
491 491 test_assert(check_matrix(m_test), "Test source matrix");
492   - test_assert(check_matrix(test, 2.0, 0.0), "Test GSymMatrix + GSymMatrix",
  492 + test_assert(check_matrix(test, 2.0, 0.0), "Test GMatrixSymmetric + GMatrixSymmetric",
493 493 test.print());
494 494  
495   - // GSymMatrix - GSymMatrix
  495 + // GMatrixSymmetric - GMatrixSymmetric
496 496 test = m_test - m_test;
497 497 test_assert(check_matrix(m_test), "Test source matrix");
498   - test_assert(check_matrix(test, 0.0, 0.0), "Test GSymMatrix - GSymMatrix",
  498 + test_assert(check_matrix(test, 0.0, 0.0), "Test GMatrixSymmetric - GMatrixSymmetric",
499 499 test.print());
500 500  
501   - // GSymMatrix * 3.0
  501 + // GMatrixSymmetric * 3.0
502 502 test = m_test * 3.0;
503 503 test_assert(check_matrix(m_test), "Test source matrix");
504   - test_assert(check_matrix(test, 3.0, 0.0), "Test GSymMatrix * 3.0",
  504 + test_assert(check_matrix(test, 3.0, 0.0), "Test GMatrixSymmetric * 3.0",
505 505 test.print());
506 506  
507   - // 3.0 * GSymMatrix
  507 + // 3.0 * GMatrixSymmetric
508 508 test = 3.0 * m_test;
509 509 test_assert(check_matrix(m_test), "Test source matrix");
510   - test_assert(check_matrix(test, 3.0, 0.0), "Test 3.0 * GSymMatrix",
  510 + test_assert(check_matrix(test, 3.0, 0.0), "Test 3.0 * GMatrixSymmetric",
511 511 test.print());
512 512  
513   - // GSymMatrix / 3.0
  513 + // GMatrixSymmetric / 3.0
514 514 test = m_test / 3.0;
515 515 test_assert(check_matrix(m_test), "Test source matrix");
516   - test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GSymMatrix / 3.0",
  516 + test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSymmetric / 3.0",
517 517 test.print());
518 518  
519 519 // Test invalid matrix addition
... ... @@ -540,7 +540,7 @@ void TestGSymMatrix::matrix_arithmetics(void)
540 540 *
541 541 * Tests matrix functions.
542 542 ***************************************************************************/
543   -void TestGSymMatrix::matrix_functions(void)
  543 +void TestGMatrixSymmetric::matrix_functions(void)
544 544 {
545 545 // Minimum
546 546 double min = m_test.min();
... ... @@ -583,10 +583,10 @@ void TestGSymMatrix::matrix_functions(void)
583 583 test_value(sum, value, 1.0e-20, "Test sum function");
584 584  
585 585 // Transpose function
586   - GSymMatrix test1 = transpose(m_test);
  586 + GMatrixSymmetric test1 = transpose(m_test);
587 587 test_assert(check_matrix(m_test), "Test source matrix");
588 588 test_assert(check_matrix(test1, 1.0, 0.0),
589   - "Test transpose(GSymMatrix) function",
  589 + "Test transpose(GMatrixSymmetric) function",
590 590 "Unexpected transposed matrix:\n"+test1.print());
591 591  
592 592 // Transpose method
... ... @@ -594,28 +594,28 @@ void TestGSymMatrix::matrix_functions(void)
594 594 test1.transpose();
595 595 test_assert(check_matrix(m_test), "Test source matrix");
596 596 test_assert(check_matrix(test1, 1.0, 0.0),
597   - "Test GSymMatrix.transpose() method",
  597 + "Test GMatrixSymmetric.transpose() method",
598 598 "Unexpected transposed matrix:\n"+test1.print());
599 599  
600 600 // Convert to general matrix
601 601 GMatrix test2 = GMatrix(m_test);
602 602 test_assert(check_matrix(m_test), "Test source matrix");
603 603 test_assert(check_matrix(test2, 1.0, 0.0),
604   - "Test GMatrix(GSymMatrix) constructor",
  604 + "Test GMatrix(GMatrixSymmetric) constructor",
605 605 "Unexpected GMatrix:\n"+test2.print());
606 606  
607 607 // Extract lower triangle
608 608 test2 = m_test.extract_lower_triangle();
609 609 test_assert(check_matrix(m_test), "Test source matrix");
610 610 test_assert(check_matrix_lt(test2, 1.0, 0.0),
611   - "Test GSymMatrix.extract_lower_triangle() method",
  611 + "Test GMatrixSymmetric.extract_lower_triangle() method",
612 612 "Unexpected GMatrix:\n"+test2.print());
613 613  
614 614 // Extract upper triangle
615 615 test2 = m_test.extract_upper_triangle();
616 616 test_assert(check_matrix(m_test), "Test source matrix");
617 617 test_assert(check_matrix_ut(test2, 1.0, 0.0),
618   - "Test GSymMatrix.extract_upper_triangle() method",
  618 + "Test GMatrixSymmetric.extract_upper_triangle() method",
619 619 "Unexpected GMatrix:\n"+test2.print());
620 620  
621 621 // Return
... ... @@ -626,10 +626,10 @@ void TestGSymMatrix::matrix_functions(void)
626 626 /***********************************************************************//**
627 627 * @brief Test matrix comparisons
628 628 ***************************************************************************/
629   -void TestGSymMatrix::matrix_compare(void)
  629 +void TestGMatrixSymmetric::matrix_compare(void)
630 630 {
631 631 // Allocate an empty matrix
632   - GSymMatrix empty(g_rows,g_cols);
  632 + GMatrixSymmetric empty(g_rows,g_cols);
633 633  
634 634 // Test operators
635 635 test_assert((m_test == m_test), "Test == operator");
... ... @@ -647,10 +647,10 @@ void TestGSymMatrix::matrix_compare(void)
647 647 /***********************************************************************//**
648 648 * @brief Test Cholesky decomposition
649 649 ***************************************************************************/
650   -void TestGSymMatrix::matrix_cholesky(void)
  650 +void TestGMatrixSymmetric::matrix_cholesky(void)
651 651 {
652 652 // Test Cholesky decomposition
653   - GSymMatrix cd = cholesky_decompose(m_test);
  653 + GMatrixSymmetric cd = cholesky_decompose(m_test);
654 654 GMatrix cd_lower = cd.extract_lower_triangle();
655 655 GMatrix cd_upper = transpose(cd_lower);
656 656 GMatrix cd_product = cd_lower * cd_upper;
... ... @@ -659,8 +659,8 @@ void TestGSymMatrix::matrix_cholesky(void)
659 659 test_value(res, 0.0, 1.0e-15, "Test cholesky_decompose() method");
660 660  
661 661 // Test compressed Cholesky decomposition
662   - GSymMatrix test_zero = set_matrix_zero();
663   - GSymMatrix cd_zero = cholesky_decompose(test_zero);
  662 + GMatrixSymmetric test_zero = set_matrix_zero();
  663 + GMatrixSymmetric cd_zero = cholesky_decompose(test_zero);
664 664 GMatrix cd_zero_lower = cd_zero.extract_lower_triangle();
665 665 GMatrix cd_zero_upper = transpose(cd_zero_lower);
666 666 GMatrix cd_zero_product = cd_zero_lower * cd_zero_upper;
... ... @@ -669,7 +669,7 @@ void TestGSymMatrix::matrix_cholesky(void)
669 669 test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_decompose() method");
670 670  
671 671 // Test Cholesky inplace decomposition
672   - GSymMatrix test = m_test;
  672 + GMatrixSymmetric test = m_test;
673 673 test.cholesky_decompose();
674 674 GMatrix cd_lower2 = test.extract_lower_triangle();
675 675 test_assert((cd_lower2 == cd_lower), "Test inplace cholesky_decompose() method");
... ... @@ -751,9 +751,9 @@ void TestGSymMatrix::matrix_cholesky(void)
751 751 test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method");
752 752  
753 753 // Test Cholesky inverter
754   - GSymMatrix unit(g_rows,g_cols);
  754 + GMatrixSymmetric unit(g_rows,g_cols);
755 755 unit(0,0) = unit(1,1) = unit(2,2) = 1.0;
756   - GSymMatrix test_inv = m_test;
  756 + GMatrixSymmetric test_inv = m_test;
757 757 test_inv.cholesky_invert();
758 758 GMatrix ci_product = m_test * test_inv;
759 759 GMatrix ci_residuals = ci_product - unit;
... ... @@ -761,9 +761,9 @@ void TestGSymMatrix::matrix_cholesky(void)
761 761 test_value(res, 0.0, 1.0e-15, "Test cholesky_invert method");
762 762  
763 763 // Test Cholesky inverter for compressed matrix
764   - unit = GSymMatrix(4,4);
  764 + unit = GMatrixSymmetric(4,4);
765 765 unit(0,0) = unit(1,1) = unit(3,3) = 1.0;
766   - GSymMatrix test_zero_inv = test_zero;
  766 + GMatrixSymmetric test_zero_inv = test_zero;
767 767 test_zero_inv.cholesky_invert();
768 768 GMatrix ciz_product = test_zero * test_zero_inv;
769 769 GMatrix ciz_residuals = ciz_product - unit;
... ... @@ -778,11 +778,11 @@ void TestGSymMatrix::matrix_cholesky(void)
778 778 /***************************************************************************
779 779 * @brief Test matrix printing
780 780 ***************************************************************************/
781   -void TestGSymMatrix::matrix_print(void)
  781 +void TestGMatrixSymmetric::matrix_print(void)
782 782 {
783 783 // Set reference
784 784 std::string reference;
785   - reference.append("=== GSymMatrix ===\n");
  785 + reference.append("=== GMatrixSymmetric ===\n");
786 786 reference.append(" Number of rows ............: 3\n");
787 787 reference.append(" Number of columns .........: 3\n");
788 788 reference.append(" Number of elements ........: 6\n");
... ... @@ -807,13 +807,13 @@ void TestGSymMatrix::matrix_print(void)
807 807 int main(void)
808 808 {
809 809 // Allocate test suit container
810   - GTestSuites testsuites("GSymMatrix class testing");
  810 + GTestSuites testsuites("GMatrixSymmetric class testing");
811 811  
812 812 // Initially assume that we pass all tests
813 813 bool success = true;
814 814  
815 815 // Create a test suite
816   - TestGSymMatrix test;
  816 + TestGMatrixSymmetric test;
817 817  
818 818 // Append test suite to the container
819 819 testsuites.append(test);
... ... @@ -822,7 +822,7 @@ int main(void)
822 822 success = testsuites.run();
823 823  
824 824 // Save test report
825   - testsuites.save("reports/GSymMatrix.xml");
  825 + testsuites.save("reports/GMatrixSymmetric.xml");
826 826  
827 827 // Return success status
828 828 return (success ? 0 : 1);
... ...
test/test_GMatrixSymmetric.hpp
1 1 /***************************************************************************
2   - * test_GSymMatrix.hpp - Test symmetric matrix class *
  2 + * test_GMatrixSymmetric.hpp - Test symmetric matrix class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -19,20 +19,20 @@
19 19 * *
20 20 ***************************************************************************/
21 21 /**
22   - * @file test_GSymMatrix.hpp
  22 + * @file test_GMatrixSymmetric.hpp
23 23 * @brief Definition of unit tests for symmetric matrices
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
27   -#ifndef TEST_GSYMMATRIX_HPP
28   -#define TEST_GSYMMATRIX_HPP
  27 +#ifndef TEST_GMATRIXSYMMETRIC_HPP
  28 +#define TEST_GMATRIXSYMMETRIC_HPP
29 29  
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include "GammaLib.hpp"
32 32  
33 33  
34 34 /***********************************************************************//**
35   - * @class TestGSymMatrix
  35 + * @class TestGMatrixSymmetric
36 36 *
37 37 * @brief Test suite for symmetric matrix class testing
38 38 *
... ... @@ -40,12 +40,12 @@
40 40 * that match logically are gathered in a number of class methods, and the
41 41 * class methods are executed when running the test.
42 42 ***************************************************************************/
43   -class TestGSymMatrix : public GTestSuite {
  43 +class TestGMatrixSymmetric : public GTestSuite {
44 44  
45 45 public:
46 46 // Constructors and destructors
47   - TestGSymMatrix(void) : GTestSuite() {}
48   - virtual ~TestGSymMatrix(void) {}
  47 + TestGMatrixSymmetric(void) : GTestSuite() {}
  48 + virtual ~TestGMatrixSymmetric(void) {}
49 49  
50 50 // Methods
51 51 virtual void set(void);
... ... @@ -61,26 +61,26 @@ public:
61 61  
62 62 private:
63 63 // Private methods
64   - GSymMatrix set_matrix(void) const;
65   - GSymMatrix set_matrix_zero(void) const;
66   - GVector set_vector(void) const;
67   - bool check_matrix(const GSymMatrix& matrix,
68   - const double& scale = 1.0,
69   - const double& offset = 0.0) const;
70   - bool check_matrix(const GMatrix& matrix,
71   - const double& scale = 1.0,
72   - const double& offset = 0.0) const;
73   - bool check_matrix_lt(const GMatrix& matrix,
74   - const double& scale,
75   - const double& offset) const;
76   - bool check_matrix_ut(const GMatrix& matrix,
77   - const double& scale,
78   - const double& offset) const;
  64 + GMatrixSymmetric set_matrix(void) const;
  65 + GMatrixSymmetric set_matrix_zero(void) const;
  66 + GVector set_vector(void) const;
  67 + bool check_matrix(const GMatrixSymmetric& matrix,
  68 + const double& scale = 1.0,
  69 + const double& offset = 0.0) const;
  70 + bool check_matrix(const GMatrix& matrix,
  71 + const double& scale = 1.0,
  72 + const double& offset = 0.0) const;
  73 + bool check_matrix_lt(const GMatrix& matrix,
  74 + const double& scale,
  75 + const double& offset) const;
  76 + bool check_matrix_ut(const GMatrix& matrix,
  77 + const double& scale,
  78 + const double& offset) const;
79 79  
80 80 // Private members;
81   - GSymMatrix m_test; //!< Test matrix
82   - GSymMatrix m_bigger; //!< Bigger test matrix (for collisions)
83   - GVector v_test; //!< Test vector
  81 + GMatrixSymmetric m_test; //!< Test matrix
  82 + GMatrixSymmetric m_bigger; //!< Bigger test matrix (for collisions)
  83 + GVector v_test; //!< Test vector
84 84 };
85 85  
86   -#endif /* TEST_GSYMMATRIX_HPP */
  86 +#endif /* TEST_GMATRIXSYMMETRIC_HPP */
... ...