Commit a7cdb4ead38a6394d64f274c1ddebd553ab00baa
1 parent
b4ded5bf
Add some debug code.
Some debug code was added to track down some problems in the GSparseMatrix class. The next step will be the modification to use the test suite.
Showing
1 changed file
with
73 additions
and
4 deletions
test/test_GSparseMatrix.cpp
| ... | ... | @@ -887,8 +887,26 @@ void test_arithmetics(const GSparseMatrix& m_test) |
| 887 | 887 | if (result != compare) { |
| 888 | 888 | cout << endl << "TEST ERROR: Corrupt GSparseMatrix.add_col(compressed array)." << endl; |
| 889 | 889 | cout << "m_test " << m_test << endl; |
| 890 | + for (int i = 0; i < g_rows; ++i) { | |
| 891 | + for (int j = 0; j < g_cols; ++j) { | |
| 892 | + std::cout << " " << m_test(i,j); | |
| 893 | + } | |
| 894 | + std::cout << std::endl; | |
| 895 | + } | |
| 890 | 896 | cout << "result " << result << endl; |
| 897 | + for (int i = 0; i < g_rows; ++i) { | |
| 898 | + for (int j = 0; j < g_cols; ++j) { | |
| 899 | + std::cout << " " << result(i,j); | |
| 900 | + } | |
| 901 | + std::cout << std::endl; | |
| 902 | + } | |
| 891 | 903 | cout << "compare " << compare << endl; |
| 904 | + for (int i = 0; i < g_rows; ++i) { | |
| 905 | + for (int j = 0; j < g_cols; ++j) { | |
| 906 | + std::cout << " " << compare(i,j); | |
| 907 | + } | |
| 908 | + std::cout << std::endl; | |
| 909 | + } | |
| 892 | 910 | throw; |
| 893 | 911 | } |
| 894 | 912 | cout << "."; |
| ... | ... | @@ -1039,7 +1057,7 @@ void test_conversion(void) |
| 1039 | 1057 | std::cout << "."; |
| 1040 | 1058 | // |
| 1041 | 1059 | // Convert GSymMatrix back to GSparseMatrix matrix |
| 1042 | - GSparseMatrix back_convert = sparse_matrix(converted); | |
| 1060 | + GSparseMatrix back_convert = GSparseMatrix(converted); | |
| 1043 | 1061 | std::cout << "."; |
| 1044 | 1062 | // |
| 1045 | 1063 | // Compare back converted matrix to original one. They should be identical |
| ... | ... | @@ -1115,7 +1133,7 @@ void test_conversion(void) |
| 1115 | 1133 | // |
| 1116 | 1134 | // Try converting now into GSymMatrix object (this should fail) |
| 1117 | 1135 | try { |
| 1118 | - converted = sym_matrix(sparse); | |
| 1136 | + converted = GSymMatrix(sparse); | |
| 1119 | 1137 | cout << endl << "TEST ERROR: Sparse->Sym conversion should have failed." << endl; |
| 1120 | 1138 | throw; |
| 1121 | 1139 | } |
| ... | ... | @@ -1128,11 +1146,11 @@ void test_conversion(void) |
| 1128 | 1146 | } |
| 1129 | 1147 | // |
| 1130 | 1148 | // Convert matrix into GMatrix object |
| 1131 | - GMatrix full = matrix(sparse); | |
| 1149 | + GMatrix full = GMatrix(sparse); | |
| 1132 | 1150 | cout << "."; |
| 1133 | 1151 | // |
| 1134 | 1152 | // Convert full matrix back to GSparseMatrix |
| 1135 | - back_convert = sparse_matrix(full); | |
| 1153 | + back_convert = GSparseMatrix(full); | |
| 1136 | 1154 | cout << "."; |
| 1137 | 1155 | // |
| 1138 | 1156 | // Compare back converted matrix to original one. They should be identical |
| ... | ... | @@ -1731,6 +1749,14 @@ void test_heavy(int block = 512) |
| 1731 | 1749 | // Check that both are identical |
| 1732 | 1750 | if (large != stack) { |
| 1733 | 1751 | cout << endl << "TEST ERROR: Stack-based insertion corrupted." << endl; |
| 1752 | + for (int i = 0; i < number; ++i) { | |
| 1753 | + for (int j = 0; j < number; ++j) { | |
| 1754 | + if (large(i,j) != stack(i,j)) { | |
| 1755 | + std::cout << "(" << i << "," << j << "): "; | |
| 1756 | + std::cout << large(i,j) << " is not stack " << stack(i,j) << std::endl; | |
| 1757 | + } | |
| 1758 | + } | |
| 1759 | + } | |
| 1734 | 1760 | throw; |
| 1735 | 1761 | } |
| 1736 | 1762 | // |
| ... | ... | @@ -1781,6 +1807,48 @@ void test_heavy(int block = 512) |
| 1781 | 1807 | } |
| 1782 | 1808 | |
| 1783 | 1809 | |
| 1810 | +void test_stack(int block = 512) | |
| 1811 | +{ | |
| 1812 | + // Set parameters | |
| 1813 | + int nrows = 10; | |
| 1814 | + int ncols = 10; | |
| 1815 | + | |
| 1816 | + // Initialise column vector | |
| 1817 | + GVector column(nrows); | |
| 1818 | + for (int i = 0; i < nrows; i+=2) { | |
| 1819 | + column[i] = 5.0; | |
| 1820 | + } | |
| 1821 | + | |
| 1822 | + // Initialise reference matrix | |
| 1823 | + GSparseMatrix ref(nrows, ncols); | |
| 1824 | + for (int i = 0; i < ncols; i+=2) { | |
| 1825 | + ref.add_col(column, i); | |
| 1826 | + } | |
| 1827 | + | |
| 1828 | + // Initialise stack matrix | |
| 1829 | + GSparseMatrix stack(nrows, ncols); | |
| 1830 | + stack.stack_init(10000, 4); | |
| 1831 | + for (int i = 0; i < ncols; i+=2) { | |
| 1832 | + stack.add_col(column, i); | |
| 1833 | + } | |
| 1834 | + stack.stack_destroy(); | |
| 1835 | + | |
| 1836 | + // Compare | |
| 1837 | + if (ref != stack) { | |
| 1838 | + std::cout << endl << "TEST ERROR: Stack-based insertion corrupted." << std::endl; | |
| 1839 | + for (int i = 0; i < nrows; ++i) { | |
| 1840 | + for (int j = 0; j < ncols; ++j) { | |
| 1841 | + if (ref(i,j) != stack(i,j)) { | |
| 1842 | + std::cout << "(" << i << "," << j << "): "; | |
| 1843 | + std::cout << "ref=" << ref(i,j) << " stack=" << stack(i,j) << std::endl; | |
| 1844 | + } | |
| 1845 | + } | |
| 1846 | + } | |
| 1847 | + throw; | |
| 1848 | + } | |
| 1849 | +} | |
| 1850 | + | |
| 1851 | + | |
| 1784 | 1852 | /*************************************************************************** |
| 1785 | 1853 | * Main test function * |
| 1786 | 1854 | ***************************************************************************/ |
| ... | ... | @@ -1811,6 +1879,7 @@ int main(void) |
| 1811 | 1879 | test_conversion(); |
| 1812 | 1880 | test_cholesky(); |
| 1813 | 1881 | test_heavy(); |
| 1882 | + //test_stack(); | |
| 1814 | 1883 | |
| 1815 | 1884 | // Return |
| 1816 | 1885 | return 0; | ... | ... |