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

stillwater-sc / universal / 21370064209

26 Jan 2026 06:55PM UTC coverage: 84.067%. First build
21370064209

Pull #499

github

Ravenwater
Add comprehensive quire regression tests

- Create static/quire/ test directory with api/ and arithmetic/ subdirectories
- Add api.cpp demonstrating quire construction, assignment, accumulation,
  fused dot product (FDP), and conversion back to posit
- Add arithmetic.cpp with comprehensive tests for:
  - Assignment from zero, integers, floats, doubles, and posit values
  - Addition and subtraction operations with various sign combinations
  - Conversion tests including powers of 2 and round-trip verification
  - Exception tests for operand_too_large_for_quire and operand_too_small_for_quire
  - Fused dot product (FDP) tests using quire_mul for unrounded accumulation
- Tests cover posit<8,0>, posit<16,1>, and posit<32,2> configurations
- Use powers of 2 as test values to ensure exact representation across
  all posit configurations

Improves code coverage for:
- include/sw/universal/number/posit/quire.hpp
- include/sw/universal/number/quire/exceptions.hpp

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pull Request #499: V3.93: UBSan fixes, image demo, and coverage workflow

130 of 156 new or added lines in 6 files covered. (83.33%)

33024 of 39283 relevant lines covered (84.07%)

6722728.46 hits per line

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

35.94
/linalg/data/test_matrices.cpp
1
// test_matrices.cpp: convert test matrix include files to data files
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
#include <universal/utility/directives.hpp>
8
#include <cmath>
9
#include <iostream>
10
#include <iomanip>
11
#include <fstream>
12

13
// Serialization - test_matrix.hpp reads matrices from .dat files
14
#include <blas/serialization/datafile.hpp>
15
#include <blas/serialization/test_matrix.hpp>
16

17
#include <universal/verification/test_suite.hpp>
18
#include <blas/matrices/testsuite.hpp>
19

20
namespace sw { namespace blas {
21
        using namespace sw::numeric::containers;
22

23
        static void WriteMatrixDataFile(const std::string& filename, const matrix<double>& A) {
×
24
                std::ofstream fo;
×
25
                fo.open(filename);
×
26
                fo << A;
×
27
                fo.close();
×
28
        }
×
29

30
        static void GenerateMatrixDataFiles(const std::vector<std::string>& testMatrixNames) {
×
31
                for (auto matrixName : testMatrixNames) {
×
32
                        WriteMatrixDataFile(matrixName + std::string(".dat"), getTestMatrix(matrixName));
×
33
                }
×
34
        }
×
35

36
} }
37

38
// This is a program that we ran once to get the test matrices converted to data files
39
// 
40
// We have no code in the regression side of the test so CI is a NOP
41

42

43
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
44
#define MANUAL_TESTING 0
45
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
46
// It is the responsibility of the regression test to organize the tests in a quartile progression.
47
//#undef REGRESSION_LEVEL_OVERRIDE
48
#ifndef REGRESSION_LEVEL_OVERRIDE
49
#undef REGRESSION_LEVEL_1
50
#undef REGRESSION_LEVEL_2
51
#undef REGRESSION_LEVEL_3
52
#undef REGRESSION_LEVEL_4
53
#define REGRESSION_LEVEL_1 1
54
#define REGRESSION_LEVEL_2 1
55
#define REGRESSION_LEVEL_3 1
56
#define REGRESSION_LEVEL_4 1
57
#endif
58

59
int main()
1✔
60
try {
61
        using namespace sw::universal;
62
        using namespace sw::blas;
63

64
        std::string test_suite  = "test matrices serialization";
2✔
65
        std::string test_tag    = "test_matrices";
1✔
66
        bool reportTestCases    = true;
1✔
67
        int nrOfFailedTestCases = 0;
1✔
68

69
        ReportTestSuiteHeader(test_suite, reportTestCases);
1✔
70

71
#if MANUAL_TESTING
72

73
        // set up the set of test matrices
74
        std::vector<std::string> allTestMatrices = {
75
                "lambers_well",  //   2 x   2 well-conditioned matrix, K = 10.0
76
                "lambers_ill",   //   2 x   2 ill-conditioned matrix, K = 1.869050824603144e+08
77
                "h3",            //   3 x   3 test matrix, K = 1.8478e+11
78
                "int3",          //   3 x   3 integer test matrix (low condition number), K = 43.6115
79
                "faires74x3",    //   3 x   3 Burden Faires Ill-conditioned, K = 15999
80
                "q3",            //   3 x   3 Variable test matrix (edit entries), K = 1.2857e+06
81
                "q4",            //   4 x   4 test matrix, K = 2.35
82
                "q5",            //   5 x   5 test matrix, K = 1.1e+04
83
                "lu4",           //   4 x   4 test matrix, K = 11.6810
84
                "s4",            //   4 x   4 test matrix, K = 4.19
85
                "rand4",         //   4 x   4 random (low condition), K = 27.81
86
                "cage3",         //   5 x   5 Directed Weighted Graph, K = 1.884547e+01
87
                "b1_ss",         //   7 x   7 Chemical Process Simulation Problem, K = 1.973732e+02
88

89
                "west0132",      // 132 x 132 Chem. Simulation Process, K = 4.2e+11 
90
                "west0167",      // 167 x 167 Chemical Simulation Process, K = 2.827e+07
91
                "steam1",        // 240 x 240 Computational Fluid Dynamics, K = 2.827501e+07
92
                "steam3",        //  83 x  83 Computational Fluid Dynamics, K = 5.51e+10
93
                "fs_183_1",      // 183 x 183 2D/3D Problem Sequence, K = 1.5129e+13
94
                "fs_183_3",      // 183 x 183 2D/3D Problem Sequence, K = 1.5129e+13
95
                "bwm200",        // 200 x 200 Chemical simulation, K = 2.412527e+03
96
                "gre_343",       // 343 x 343 Directed Weighted Graph, K = 1.119763e+02
97
                "pores_1",       //  30 x  30 Computational Fluid Dynamics, K = 1.812616e+06
98
                "Stranke94",     //  10 x  10 Undirected Weighted Graph, K = 5.173300e+01
99
                "Trefethen_20",  //  20 x  20 Combinatorial Problem, K = 6.308860e+01
100
                "bcsstk01",      //  48 x  48 Structural Engineering, K = 8.8234e+05
101
                "bcsstk03",      // 112 x 112 Structural Engineering, K = 6.791333e+06
102
                "bcsstk04",      // 132 x 132 Structural Engineering, K = 2.292466e+06
103
                "bcsstk05",      // 153 x 153 Structural Engineering, K = 1.428114e+04
104
                "bcsstk22",      // 138 x 138 Structural Engineering, K = 1.107165e+05
105
                "lund_a",        // 147 x 147 Structural Engineering, K = 2.796948e+06
106
                "nos1",          // 237 x 237 Structural Engineering K = 1.991546e+07
107
                "arc130",        // 130 x 130    K = 6.0542e+10
108
                "saylr1",        // 238 x 238 Computational Fluid Dynamics, K = 7.780581e+08
109
                "tumorAntiAngiogenesis_2" // , K 1.9893e+10
110
        };
111
        GenerateMatrixDataFiles(allTestMatrices);
112

113
        ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
114
        return EXIT_SUCCESS;
115
#else
116
        // Test the serialization/test_matrix.hpp functionality
117
        // Note: sw::blas::getTestMatrix() reads from .dat files (different from global getTestMatrix())
118
#if REGRESSION_LEVEL_1
119
        {
120
                // Test dataDirectory()
121
                std::string dataDir = sw::blas::dataDirectory();
1✔
122
                if (dataDir.empty()) {
1✔
NEW
123
                        ++nrOfFailedTestCases;
×
NEW
124
                        if (reportTestCases) std::cout << "FAIL: dataDirectory() returned empty\n";
×
125
                } else {
126
                        if (reportTestCases) std::cout << "PASS: dataDirectory() = " << dataDir << "\n";
1✔
127
                }
128

129
                // Test TestMatrixList is populated
130
                if (sw::blas::TestMatrixList.empty()) {
1✔
NEW
131
                        ++nrOfFailedTestCases;
×
NEW
132
                        if (reportTestCases) std::cout << "FAIL: TestMatrixList is empty\n";
×
133
                } else {
134
                        if (reportTestCases) std::cout << "PASS: TestMatrixList has " << sw::blas::TestMatrixList.size() << " matrices\n";
1✔
135
                }
136

137
                // Test ConditionNumber map is populated
138
                if (sw::blas::ConditionNumber.empty()) {
1✔
NEW
139
                        ++nrOfFailedTestCases;
×
NEW
140
                        if (reportTestCases) std::cout << "FAIL: ConditionNumber map is empty\n";
×
141
                } else {
142
                        if (reportTestCases) std::cout << "PASS: ConditionNumber map has " << sw::blas::ConditionNumber.size() << " entries\n";
1✔
143
                }
144

145
                // Test kappa() for known matrices (from serialization module)
146
                double k = sw::blas::kappa("lambers_well");
1✔
147
                if (std::abs(k - 10.0) < 0.001) {
1✔
148
                        if (reportTestCases) std::cout << "PASS: kappa(lambers_well) = " << k << "\n";
1✔
149
                } else {
NEW
150
                        ++nrOfFailedTestCases;
×
NEW
151
                        if (reportTestCases) std::cout << "FAIL: kappa(lambers_well) = " << k << " (expected 10.0)\n";
×
152
                }
153

154
                // Test kappa() for unknown matrix (should return 0.0 and print error)
155
                double unknownK = sw::blas::kappa("nonexistent_matrix");
1✔
156
                if (unknownK == 0.0) {
1✔
157
                        if (reportTestCases) std::cout << "PASS: kappa(unknown) = 0.0 (expected)\n";
1✔
158
                } else {
NEW
159
                        ++nrOfFailedTestCases;
×
NEW
160
                        if (reportTestCases) std::cout << "FAIL: kappa(unknown) = " << unknownK << " (expected 0.0)\n";
×
161
                }
162
        }
1✔
163
#endif
164

165
#if REGRESSION_LEVEL_2
166
        {
167
                using namespace sw::numeric::containers;
168

169
                // Test loading a small matrix from file using sw::blas::getTestMatrix
170
                matrix<double> A = sw::blas::getTestMatrix("lambers_well");
171
                if (num_rows(A) == 2 && num_cols(A) == 2) {
172
                        if (reportTestCases) std::cout << "PASS: getTestMatrix(lambers_well) = 2x2\n";
173
                } else {
174
                        ++nrOfFailedTestCases;
175
                        if (reportTestCases) std::cout << "FAIL: getTestMatrix(lambers_well) = " << num_rows(A) << "x" << num_cols(A) << "\n";
176
                }
177

178
                // Test loading another matrix
179
                matrix<double> B = sw::blas::getTestMatrix("lu4");
180
                if (num_rows(B) == 4 && num_cols(B) == 4) {
181
                        if (reportTestCases) std::cout << "PASS: getTestMatrix(lu4) = 4x4\n";
182
                } else {
183
                        ++nrOfFailedTestCases;
184
                        if (reportTestCases) std::cout << "FAIL: getTestMatrix(lu4) = " << num_rows(B) << "x" << num_cols(B) << "\n";
185
                }
186

187
                // Test loading non-existent matrix (should return empty matrix)
188
                matrix<double> C = sw::blas::getTestMatrix("nonexistent_matrix");
189
                if (num_rows(C) == 0 && num_cols(C) == 0) {
190
                        if (reportTestCases) std::cout << "PASS: getTestMatrix(unknown) = 0x0 (expected)\n";
191
                } else {
192
                        ++nrOfFailedTestCases;
193
                        if (reportTestCases) std::cout << "FAIL: getTestMatrix(unknown) = " << num_rows(C) << "x" << num_cols(C) << "\n";
194
                }
195
        }
196
#endif
197

198
#if REGRESSION_LEVEL_3
199
        {
200
                using namespace sw::numeric::containers;
201

202
                // Test loading all matrices in TestMatrixList
203
                int loadedCount = 0;
204
                for (const auto& matrixName : sw::blas::TestMatrixList) {
205
                        matrix<double> M = sw::blas::getTestMatrix(matrixName);
206
                        if (num_rows(M) > 0 && num_cols(M) > 0) {
207
                                ++loadedCount;
208
                        } else {
209
                                ++nrOfFailedTestCases;
210
                                if (reportTestCases) std::cout << "FAIL: getTestMatrix(" << matrixName << ") load failed\n";
211
                        }
212
                }
213
                if (reportTestCases) std::cout << "Loaded " << loadedCount << "/" << sw::blas::TestMatrixList.size() << " matrices\n";
214
        }
215
#endif
216

217
#if REGRESSION_LEVEL_4
218
        {
219
                // Verify condition numbers are available for all matrices in TestMatrixList
220
                int kappaCount = 0;
221
                for (const auto& matrixName : sw::blas::TestMatrixList) {
222
                        double k = sw::blas::kappa(matrixName);
223
                        if (k > 0.0) {
224
                                ++kappaCount;
225
                        } else {
226
                                ++nrOfFailedTestCases;
227
                                if (reportTestCases) std::cout << "FAIL: kappa(" << matrixName << ") not found\n";
228
                        }
229
                }
230
                if (reportTestCases) std::cout << "Found kappa for " << kappaCount << "/" << sw::blas::TestMatrixList.size() << " matrices\n";
231
        }
232
#endif
233

234
        ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
1✔
235
        return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
1✔
236
#endif
237
}
1✔
238
catch (char const* msg) {
×
239
        std::cerr << msg << std::endl;
×
240
        return EXIT_FAILURE;
×
241
}
×
242
catch (const sw::universal::universal_arithmetic_exception& err) {
×
243
        std::cerr << "Uncaught universal arithmetic exception: " << err.what() << std::endl;
×
244
        return EXIT_FAILURE;
×
245
}
×
246
catch (const sw::universal::universal_internal_exception& err) {
×
247
        std::cerr << "Uncaught universal internal exception: " << err.what() << std::endl;
×
248
        return EXIT_FAILURE;
×
249
}
×
250
catch (const std::runtime_error& err) {
×
251
        std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
×
252
        return EXIT_FAILURE;
×
253
}
×
254
catch (...) {
×
255
        std::cerr << "Caught unknown exception" << std::endl;
×
256
        return EXIT_FAILURE;
×
257
}
×
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