• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stillwater-sc / universal / 21373544687

26 Jan 2026 08:52PM UTC coverage: 83.993%. First build
21373544687

Pull #499

github

web-flow
Merge 9fc4c0125 into f1f1d0fc7
Pull Request #499: V3.93: UBSan fixes, image demo, and coverage workflow

588 of 852 new or added lines in 9 files covered. (69.01%)

33473 of 39852 relevant lines covered (83.99%)

6555315.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.09
/linalg/blas/static_matrices.cpp
1
// static_matrices.cpp: enumerate ALL test matrices and report condition numbers
2
//
3
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
4
// SPDX-License-Identifier: MIT
5
//
6
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
7
//
8
// This test exercises ALL matrix header files in blas/matrices/ by including them
9
// directly and exercising each matrix's data. This ensures full code coverage of
10
// the matrices directory.
11

12
#include <universal/utility/directives.hpp>
13
#include <blas/blas.hpp>
14

15
// Include ALL matrix header files for complete coverage
16
// Small matrices (fast compilation)
17
#include <blas/matrices/lambers_well.hpp>   //   2 x   2 well-conditioned
18
#include <blas/matrices/lambers_ill.hpp>    //   2 x   2 ill-conditioned
19
#include <blas/matrices/h3.hpp>             //   3 x   3 test matrix
20
#include <blas/matrices/q3.hpp>             //   3 x   3 test matrix
21
#include <blas/matrices/int3.hpp>           //   3 x   3 integer test matrix
22
#include <blas/matrices/faires74x3.hpp>     //   3 x   3 Burden Faires ill-conditioned
23
#include <blas/matrices/q4.hpp>             //   4 x   4 test matrix
24
#include <blas/matrices/q5.hpp>             //   5 x   5 test matrix
25
#include <blas/matrices/lu4.hpp>            //   4 x   4 test matrix
26
#include <blas/matrices/s4.hpp>             //   4 x   4 test matrix
27
#include <blas/matrices/rand4.hpp>          //   4 x   4 random matrix
28
#include <blas/matrices/rand8.hpp>          //   8 x   8 random matrix
29
#include <blas/matrices/rump6x6ill.hpp>     //   6 x   6 Rump ill-conditioned
30
#include <blas/matrices/b1_ss.hpp>          //   7 x   7 Chemical Process Simulation
31
#include <blas/matrices/cage3.hpp>          //   5 x   5 Directed Weighted Graph
32
#include <blas/matrices/Stranke94.hpp>      //  10 x  10 Undirected Weighted Graph
33
#include <blas/matrices/Trefethen_20.hpp>   //  20 x  20 Combinatorial Problem
34
#include <blas/matrices/wilk21.hpp>         //  21 x  21 Wilkinson test matrix
35
#include <blas/matrices/pores_1.hpp>        //  30 x  30 Computational Fluid Dynamics
36

37
// Medium matrices
38
#include <blas/matrices/bcsstk01.hpp>       //  48 x  48 Structural Engineering
39
#include <blas/matrices/steam3.hpp>         //  83 x  83 Computational Fluid Dynamics
40
#include <blas/matrices/bcsstk03.hpp>       // 112 x 112 Structural Engineering
41
#include <blas/matrices/arc130.hpp>         // 130 x 130
42
#include <blas/matrices/west0132.hpp>       // 132 x 132 Chemical Simulation
43
#include <blas/matrices/bcsstk04.hpp>       // 132 x 132 Structural Engineering
44
#include <blas/matrices/bcsstk22.hpp>       // 138 x 138 Structural Engineering
45
#include <blas/matrices/lund_a.hpp>         // 147 x 147 Structural Engineering
46
#include <blas/matrices/bcsstk05.hpp>       // 153 x 153 Structural Engineering
47
#include <blas/matrices/west0167.hpp>       // 167 x 167 Chemical Simulation
48
#include <blas/matrices/fs_183_1.hpp>       // 183 x 183 2D/3D Problem
49
#include <blas/matrices/fs_183_3.hpp>       // 183 x 183 2D/3D Problem
50
#include <blas/matrices/bwm200.hpp>         // 200 x 200 Chemical Simulation
51
#include <blas/matrices/nos1.hpp>           // 237 x 237 Structural Engineering
52
#include <blas/matrices/saylr1.hpp>         // 238 x 238 Computational Fluid Dynamics
53
#include <blas/matrices/steam1.hpp>         // 240 x 240 Computational Fluid Dynamics
54
#include <blas/matrices/gre_343.hpp>        // 343 x 343 Directed Weighted Graph
55
#include <blas/matrices/tumorAntiAngiogenesis_2.hpp>  // tumor model
56

57
// Also include testsuite.hpp for getTestMatrix() and kappa() functions
58
#include <blas/matrices/testsuite.hpp>
59

60
#include <iostream>
61
#include <iomanip>
62
#include <string>
63

64
// Helper to test a matrix and report results
65
template<typename Matrix>
66
bool testMatrix(const std::string& name, const Matrix& A, double expectedKappa, int& nrTests, int& nrPass) {
37✔
67
    ++nrTests;
37✔
68

69
    size_t rows = num_rows(A);
37✔
70
    size_t cols = num_cols(A);
37✔
71

72
    bool isSquare = (rows == cols);
37✔
73
    bool isValid = (rows > 0 && cols > 0);
37✔
74
    bool pass = isSquare && isValid;
37✔
75

76
    if (pass) ++nrPass;
37✔
77

78
    // Categorize by condition number
79
    std::string category;
37✔
80
    if (expectedKappa < 100) {
37✔
81
        category = "well-cond";
10✔
82
    } else if (expectedKappa < 1e6) {
27✔
83
        category = "moderate";
9✔
84
    } else if (expectedKappa < 1e10) {
18✔
85
        category = "ill-cond";
10✔
86
    } else {
87
        category = "severe";
8✔
88
    }
89

90
    std::cout << std::left << std::setw(24) << name
37✔
91
              << std::right << std::setw(6) << rows
37✔
92
              << std::setw(6) << cols
37✔
93
              << std::scientific << std::setprecision(2)
37✔
94
              << std::setw(14) << expectedKappa
37✔
95
              << std::fixed
37✔
96
              << std::setw(12) << category
97
              << (pass ? "" : " FAIL")
98
              << "\n";
37✔
99

100
    return pass;
37✔
101
}
37✔
102

103
int main(int argc, char* argv[])
1✔
104
try {
105
    using namespace sw::numeric::containers;
106

107
    int nrTests = 0;
1✔
108
    int nrPass = 0;
1✔
109

110
    std::cout << "Complete Static Test Matrices: Condition Number Report\n";
1✔
111
    std::cout << "=======================================================\n\n";
1✔
112

113
    std::cout << std::left << std::setw(24) << "Matrix"
1✔
114
              << std::right << std::setw(6) << "Rows"
1✔
115
              << std::setw(6) << "Cols"
116
              << std::setw(14) << "Kappa"
117
              << std::setw(12) << "Category"
118
              << "\n";
1✔
119
    std::cout << std::string(62, '-') << "\n";
2✔
120

121
    // Test ALL matrices - small matrices first
122
    testMatrix("lambers_well", lambers_well, 10.0, nrTests, nrPass);
2✔
123
    testMatrix("lambers_ill", lambers_ill, 1.869e+08, nrTests, nrPass);
2✔
124
    testMatrix("h3", h3, 1.8478e+11, nrTests, nrPass);
2✔
125
    testMatrix("q3", q3, 1.2857e+06, nrTests, nrPass);
2✔
126
    testMatrix("int3", int3, 43.6115, nrTests, nrPass);
2✔
127
    testMatrix("faires74x3", faires74x3, 15999, nrTests, nrPass);
2✔
128
    testMatrix("q4", q4, 2.35, nrTests, nrPass);
2✔
129
    testMatrix("q5", q5, 1.1e+04, nrTests, nrPass);
2✔
130
    testMatrix("lu4", lu4, 11.6810, nrTests, nrPass);
2✔
131
    testMatrix("s4", s4, 4.19, nrTests, nrPass);
2✔
132
    testMatrix("rand4", rand4, 27.81, nrTests, nrPass);
2✔
133
    testMatrix("rand8", rand8, 100.0, nrTests, nrPass);  // estimated
2✔
134
    testMatrix("rump6x6ill", rump6x6ill, 1e+16, nrTests, nrPass);  // severely ill-conditioned
2✔
135
    testMatrix("b1_ss", b1_ss, 1.973732e+02, nrTests, nrPass);
2✔
136
    testMatrix("cage3", cage3, 1.884547e+01, nrTests, nrPass);
2✔
137
    testMatrix("Stranke94", Stranke94, 5.173300e+01, nrTests, nrPass);
2✔
138
    testMatrix("Trefethen_20", Trefethen_20, 6.308860e+01, nrTests, nrPass);
2✔
139
    testMatrix("wilk21", wilk21, 42.0, nrTests, nrPass);
2✔
140
    testMatrix("pores_1", pores_1, 1.812616e+06, nrTests, nrPass);
2✔
141

142
    // Medium matrices
143
    testMatrix("bcsstk01", bcsstk01, 8.8234e+05, nrTests, nrPass);
2✔
144
    testMatrix("steam3", steam3, 5.51e+10, nrTests, nrPass);
2✔
145
    testMatrix("bcsstk03", bcsstk03, 6.791333e+06, nrTests, nrPass);
2✔
146
    testMatrix("arc130", arc130, 6.0542e+10, nrTests, nrPass);
2✔
147
    testMatrix("west0132", west0132, 4.2e+11, nrTests, nrPass);
2✔
148
    testMatrix("bcsstk04", bcsstk04, 2.292466e+06, nrTests, nrPass);
2✔
149
    testMatrix("bcsstk22", bcsstk22, 1.107165e+05, nrTests, nrPass);
2✔
150
    testMatrix("lund_a", lund_a, 2.796948e+06, nrTests, nrPass);
2✔
151
    testMatrix("bcsstk05", bcsstk05, 1.428114e+04, nrTests, nrPass);
2✔
152
    testMatrix("west0167", west0167, 2.827e+07, nrTests, nrPass);
2✔
153
    testMatrix("fs_183_1", fs_183_1, 1.5129e+13, nrTests, nrPass);
2✔
154
    testMatrix("fs_183_3", fs_183_3, 1.5129e+13, nrTests, nrPass);
2✔
155
    testMatrix("bwm200", bwm200, 2.412527e+03, nrTests, nrPass);
2✔
156
    testMatrix("nos1", nos1, 1.991546e+07, nrTests, nrPass);
2✔
157
    testMatrix("saylr1", saylr1, 7.780581e+08, nrTests, nrPass);
2✔
158
    testMatrix("steam1", steam1, 2.827501e+07, nrTests, nrPass);
2✔
159
    testMatrix("gre_343", gre_343, 1.119763e+02, nrTests, nrPass);
2✔
160
    testMatrix("tumorAntiAngiogenesis_2", tumorAntiAngiogenesis_2, 1.9893e+10, nrTests, nrPass);
2✔
161

162
    std::cout << std::string(62, '-') << "\n";
1✔
163
    std::cout << "\nMatrix validation: " << nrPass << " of " << nrTests << " passed\n\n";
1✔
164

165
    // Test testsuite.hpp API functions
166
    std::cout << "Testing testsuite.hpp API functions:\n";
1✔
167
    std::cout << std::string(40, '-') << "\n";
1✔
168

169
    // Test getTestMatrix() with valid name
170
    ++nrTests;
1✔
171
    matrix<double> test_lu4 = getTestMatrix("lu4");
1✔
172
    if (num_rows(test_lu4) == 4 && num_cols(test_lu4) == 4) {
1✔
173
        std::cout << "  getTestMatrix(\"lu4\"): PASS (4x4)\n";
1✔
174
        ++nrPass;
1✔
175
    } else {
NEW
176
        std::cout << "  getTestMatrix(\"lu4\"): FAIL\n";
×
177
    }
178

179
    // Test getTestMatrix() with invalid name (should return lu4)
180
    ++nrTests;
1✔
181
    matrix<double> fallback = getTestMatrix("nonexistent_matrix");
1✔
182
    if (num_rows(fallback) == num_rows(test_lu4) && num_cols(fallback) == num_cols(test_lu4)) {
1✔
183
        std::cout << "  getTestMatrix(invalid): PASS (returns lu4 fallback)\n";
1✔
184
        ++nrPass;
1✔
185
    } else {
NEW
186
        std::cout << "  getTestMatrix(invalid): FAIL\n";
×
187
    }
188

189
    // Test kappa() with valid name
190
    ++nrTests;
1✔
191
    double k = kappa("lambers_well");
1✔
192
    if (std::abs(k - 10.0) < 0.001) {
1✔
193
        std::cout << "  kappa(\"lambers_well\"): PASS (" << k << ")\n";
1✔
194
        ++nrPass;
1✔
195
    } else {
NEW
196
        std::cout << "  kappa(\"lambers_well\"): FAIL (got " << k << ")\n";
×
197
    }
198

199
    // Test kappa() with invalid name (should return lu4's kappa)
200
    ++nrTests;
1✔
201
    double fallbackKappa = kappa("nonexistent_matrix");
1✔
202
    if (std::abs(fallbackKappa - 11.6810) < 0.001) {
1✔
203
        std::cout << "  kappa(invalid): PASS (returns lu4 kappa = " << fallbackKappa << ")\n";
1✔
204
        ++nrPass;
1✔
205
    } else {
NEW
206
        std::cout << "  kappa(invalid): FAIL (got " << fallbackKappa << ")\n";
×
207
    }
208

209
    std::cout << std::string(40, '-') << "\n";
1✔
210
    std::cout << "\nTotal: " << nrPass << " of " << nrTests << " tests passed\n";
1✔
211

212
    return (nrPass == nrTests) ? EXIT_SUCCESS : EXIT_FAILURE;
1✔
213
}
1✔
NEW
214
catch (char const* msg) {
×
NEW
215
    std::cerr << "Caught exception: " << msg << std::endl;
×
NEW
216
    return EXIT_FAILURE;
×
NEW
217
}
×
NEW
218
catch (const std::runtime_error& err) {
×
NEW
219
    std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
×
NEW
220
    return EXIT_FAILURE;
×
NEW
221
}
×
NEW
222
catch (...) {
×
NEW
223
    std::cerr << "Caught unknown exception" << std::endl;
×
NEW
224
    return EXIT_FAILURE;
×
NEW
225
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc