Skip to content

Commit 610a643

Browse files
committed
Reformat source
1 parent b79ae28 commit 610a643

8 files changed

Lines changed: 85 additions & 77 deletions

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ $(BUILD_COV)/CMakeCache.txt:
4242
-DCMAKE_EXE_LINKER_FLAGS="--coverage"
4343

4444
check: $(BUILD)/CMakeCache.txt
45-
# Commented out, clang-tide reports too much nonsense
45+
# Commented out, clang-tidy reports too much (sometimes dangerous) nonsense
4646
# @echo "--- clang-tidy ---"
4747
# @find src test demo -name '*.cc' | xargs clang-tidy -p $(BUILD)
4848
@echo "--- clang-format ---"
4949
@clang-format --dry-run --Werror $(SRCS) && echo "format OK"
5050

51+
format_source:
52+
@echo "--- clang-format ---"
53+
@clang-format $(SRCS) -i --verbose
54+
5155
clean:
5256
rm -rf $(BUILD) $(BUILD_COV) $(COV_OUT)

demo/utils.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
#include <cstdio>
55
#include <sstream>
66

7-
#define PRINT(x) \
8-
do { std::ostringstream _s; _s << (x); printf(#x ": %s\n", _s.str().c_str()); } while(0)
7+
#define PRINT(x) \
8+
do { \
9+
std::ostringstream _s; \
10+
_s << (x); \
11+
printf(#x ": %s\n", _s.str().c_str()); \
12+
} while(0)
913
#define PRINT_SEP \
1014
printf("======================================================================\n")
11-
#define PRINT_TITLE(x) \
12-
do { PRINT_SEP; printf(" %s\n", (x)); PRINT_SEP; } while(0)
15+
#define PRINT_TITLE(x) \
16+
do { \
17+
PRINT_SEP; \
18+
printf(" %s\n", (x)); \
19+
PRINT_SEP; \
20+
} while(0)
1321

1422
#endif // DVRLIB_UTILS_H

demo/vdi2048.cc

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <iostream>
2-
#include <vector>
32

43
#include "gsl_wrapper.h"
54
#include "recon.h"
@@ -25,18 +24,18 @@ void example_VDI2048_1(bool increase_var = false, bool keep_free = true) {
2524
system.add_var("m_D", 2.092, 0.272);
2625

2726
if(keep_free) {
28-
system.add_var("m_FD1", 0, -1);
29-
system.add_var("m_FD2", 0, -1);
30-
system.add_var("m_FD3", 0, -1);
31-
system.add_var("m_HDAnz", 0, -1);
27+
system.add_var("m_FD1", 0, -1);
28+
system.add_var("m_FD2", 0, -1);
29+
system.add_var("m_FD3", 0, -1);
30+
system.add_var("m_HDAnz", 0, -1);
3231
}
3332

3433
system.add_covariance_coeff("m_FDKeI", "m_FDKeII", 0.2);
3534
system.add_covariance_coeff("m_SpI", "m_SpII", 0.4);
3635

3736
if(increase_var) {
38-
system.change_var("m_FDKeI", 46.241, 2.500);
39-
system.change_var("m_FDKeII", 45.668, 2.500);
37+
system.change_var("m_FDKeI", 46.241, 2.500);
38+
system.change_var("m_FDKeII", 45.668, 2.500);
4039
}
4140

4241
// get and print the covariance matrix
@@ -54,25 +53,25 @@ void example_VDI2048_1(bool increase_var = false, bool keep_free = true) {
5453
// M_FD2 - M_FD3 = 0
5554
// M_HDAnz - M_HDNK = 0
5655
auto F_with_free = []() -> matrix {
57-
double Fc[][15] = {
58-
{1, 1, 0, 0, -0.2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0},
59-
{0, 0, 1, 1, -0.6, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0},
60-
{0, 0, 0, 0, 0.4, 1, 1, 1, 1, 0, 0, 0, 0, -1, 0},
61-
{0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, -1},
62-
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0},
63-
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0},
64-
{0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1},
65-
};
66-
return matrix(7, 15, Fc);
56+
double Fc[][15] = {
57+
{1, 1, 0, 0, -0.2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0},
58+
{0, 0, 1, 1, -0.6, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0},
59+
{0, 0, 0, 0, 0.4, 1, 1, 1, 1, 0, 0, 0, 0, -1, 0},
60+
{0, 0, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, -1},
61+
{0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0},
62+
{0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0},
63+
{0, 0, 0, 0, 0.0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1},
64+
};
65+
return matrix(7, 15, Fc);
6766
};
6867

6968
auto F_without_free = []() -> matrix {
70-
double Fc[][11] = {
71-
{1, 1, -1, -1, 0.4, 0, 0, 0, 0, 0, 0},
72-
{0, 0, 1, 1, -1, -1, -1, -1, -1, 0, 0},
73-
{0, 0, 0, 0, 0, 0, 1, 1, 1, -1, 0},
74-
};
75-
return matrix(3, 11, Fc);
69+
double Fc[][11] = {
70+
{1, 1, -1, -1, 0.4, 0, 0, 0, 0, 0, 0},
71+
{0, 0, 1, 1, -1, -1, -1, -1, -1, 0, 0},
72+
{0, 0, 0, 0, 0, 0, 1, 1, 1, -1, 0},
73+
};
74+
return matrix(3, 11, Fc);
7675
};
7776

7877
matrix F = keep_free ? F_with_free() : F_without_free();
@@ -137,9 +136,8 @@ void example_VDI2048_1(bool increase_var = false, bool keep_free = true) {
137136
PRINT_TITLE("Updated variables and confidences");
138137
auto updated_sys = system.updated(x_new, confint_new);
139138
updated_sys.print_vars();
140-
141139
}
142140

143141
void example_VDI2048() {
144142
example_VDI2048_1(true, true);
145-
}
143+
}

src/dvr_assert.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ namespace dvrlib {
99
struct assertion_error : public std::logic_error {
1010
assertion_error(const char* cond, const char* file, int line)
1111
: std::logic_error(std::string("assertion failed: ") + cond +
12-
" (" + file + ":" + std::to_string(line) + ")") {}
12+
" (" + file + ":" + std::to_string(line) + ")") {
13+
}
1314
};
1415

1516
} // namespace dvrlib
1617

17-
#define dvr_assert(cond) \
18-
do { \
19-
if (!(cond)) \
18+
#define dvr_assert(cond) \
19+
do { \
20+
if(!(cond)) \
2021
throw dvrlib::assertion_error(#cond, __FILE__, __LINE__); \
21-
} while (0)
22+
} while(0)
2223

2324
#endif // DVRLIB_DVR_ASSERT_H

src/recon_system.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void recon_system::change_var(const char* name, double val, double confint) {
4040

4141
int recon_system::get_number_measured() const {
4242
int count = 0;
43-
for(const auto & var : vars) {
43+
for(const auto& var : vars) {
4444
if(var.confint >= 0)
4545
count++;
4646
}
@@ -58,7 +58,7 @@ matrix recon_system::get_covariance_matrix() const {
5858
S_x.set(i, i, confint2var(vars[i].confint));
5959
}
6060

61-
for(const auto & extra_cov : extra_covs) {
61+
for(const auto& extra_cov : extra_covs) {
6262
int i = find_var(extra_cov.var1);
6363
int j = find_var(extra_cov.var2);
6464
dvr_assert(i >= 0);
@@ -100,7 +100,7 @@ recon_system recon_system::updated(const vector& values,
100100

101101
void recon_system::print_vars() const {
102102
printf("%-12s%10s%10s\n", "name", "value", "confint");
103-
for(const auto & var : vars) {
103+
for(const auto& var : vars) {
104104
printf("%-12s%10.3f", var.name.c_str(), var.value);
105105
if(var.confint < 0)
106106
printf(" (free)");

test/custom_reporter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ class SummaryListener : public Catch::EventListenerBase {
99
void testCaseEnded(Catch::TestCaseStats const& stats) override {
1010
auto passed = stats.totals.assertions.passed;
1111
auto failed = stats.totals.assertions.failed;
12-
auto total = passed + failed;
12+
auto total = passed + failed;
1313

14-
if (failed == 0) {
14+
if(failed == 0) {
1515
Catch::cout() << "\033[32m ✓ " << stats.testInfo->name
16-
<< ": " << total << " assertion"
17-
<< (total != 1 ? "s" : "") << " passed\033[0m\n";
16+
<< ": " << total << " assertion"
17+
<< (total != 1 ? "s" : "") << " passed\033[0m\n";
1818
} else {
1919
Catch::cout() << "\033[31m ✗ " << stats.testInfo->name
20-
<< ": " << passed << "/" << total
21-
<< " passed, " << failed << " FAILED\033[0m\n";
20+
<< ": " << passed << "/" << total
21+
<< " passed, " << failed << " FAILED\033[0m\n";
2222
}
2323
}
2424
};

test/gsl_wrapper_tests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TEST_CASE("vector") {
1010
REQUIRE(v.get(1) == 4.0);
1111
REQUIRE(v.get(2) == 4.0);
1212

13-
for (int i = 0; i < 3; i++) {
13+
for(int i = 0; i < 3; i++) {
1414
v.set(i, 1.23 + i);
1515
}
1616
REQUIRE(v.get(0) == 1.23);

test/vdi2048_test.cc

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ using namespace dvrlib;
88
static void setup_system(recon_system& sys) {
99
sys.add_var("m_FDKeI", 46.241, 0.800);
1010
sys.add_var("m_FDKeII", 45.668, 0.790);
11-
sys.add_var("m_SpI", 44.575, 0.535);
11+
sys.add_var("m_SpI", 44.575, 0.535);
1212
sys.add_var("m_SpII", 44.319, 0.532);
13-
sys.add_var("m_V", 0.525, 0.105);
14-
sys.add_var("m_HK", 69.978, 0.854);
15-
sys.add_var("m_A7", 10.364, 0.168);
16-
sys.add_var("m_A6", 3.744, 0.058);
17-
sys.add_var("m_A5", 4.391, 0.058);
13+
sys.add_var("m_V", 0.525, 0.105);
14+
sys.add_var("m_HK", 69.978, 0.854);
15+
sys.add_var("m_A7", 10.364, 0.168);
16+
sys.add_var("m_A6", 3.744, 0.058);
17+
sys.add_var("m_A5", 4.391, 0.058);
1818
sys.add_var("m_HDNK", 18.498, 0.205);
19-
sys.add_var("m_D", 2.092, 0.272);
20-
sys.add_var("m_FD1", 0, -1);
21-
sys.add_var("m_FD2", 0, -1);
22-
sys.add_var("m_FD3", 0, -1);
19+
sys.add_var("m_D", 2.092, 0.272);
20+
sys.add_var("m_FD1", 0, -1);
21+
sys.add_var("m_FD2", 0, -1);
22+
sys.add_var("m_FD3", 0, -1);
2323
sys.add_var("m_HDAnz", 0, -1);
2424
sys.add_covariance_coeff("m_FDKeI", "m_FDKeII", 0.2);
2525
sys.add_covariance_coeff("m_SpI", "m_SpII", 0.4);
@@ -42,8 +42,8 @@ TEST_CASE("VDI2048 regression") {
4242
recon_system sys;
4343
setup_system(sys);
4444
matrix S_x = sys.get_covariance_matrix();
45-
matrix F = make_constraints_matrix();
46-
vector x = sys.get_values();
45+
matrix F = make_constraints_matrix();
46+
vector x = sys.get_values();
4747

4848
vector v(x.size());
4949
lin_recon(F * x, S_x, F, v);
@@ -52,7 +52,7 @@ TEST_CASE("VDI2048 regression") {
5252
lin_cov_update(S_x, F, S_v);
5353

5454
matrix S_x_new = S_x - S_v;
55-
vector x_new = x + v;
55+
vector x_new = x + v;
5656
vector confint_new(S_x.size1());
5757
extract_confidence(S_x_new, confint_new);
5858

@@ -61,34 +61,32 @@ TEST_CASE("VDI2048 regression") {
6161
SECTION("corrections v") {
6262
double expected[] = {
6363
-1.27651079357085, -1.25002785826582,
64-
0.350904047191697, 0.348096449940544,
65-
0.00134787242233519, 0.575060829315,
66-
0.0117829833264503, 0.00140440603423252,
67-
0.00140440603423252, 0.0155917953949165,
68-
0, 89.2771917736789, 89.2771917736789,
69-
89.2771917736788, 18.5135917953949
70-
};
71-
for (int i = 0; i < v.size(); i++)
64+
0.350904047191697, 0.348096449940544,
65+
0.00134787242233519, 0.575060829315,
66+
0.0117829833264503, 0.00140440603423252,
67+
0.00140440603423252, 0.0155917953949165,
68+
0, 89.2771917736789, 89.2771917736789,
69+
89.2771917736788, 18.5135917953949};
70+
for(int i = 0; i < v.size(); i++)
7271
CHECK(v.get(i) == Catch::Approx(expected[i]).epsilon(tol));
7372
}
7473

7574
SECTION("constraints satisfied after correction") {
7675
vector residual = F * (x + v);
77-
for (int i = 0; i < residual.size(); i++)
76+
for(int i = 0; i < residual.size(); i++)
7877
CHECK(residual.get(i) == Catch::Approx(0.0).margin(1e-10));
7978
}
8079

8180
SECTION("updated values x_new") {
8281
double expected[] = {
8382
44.9644892064291, 44.4179721417342,
8483
44.9259040471917, 44.6670964499405,
85-
0.526347872422335, 70.553060829315,
86-
10.3757829833265, 3.74540440603423,
87-
4.39240440603423, 18.5135917953949,
88-
2.092, 89.2771917736789, 89.2771917736789,
89-
89.2771917736788, 18.5135917953949
90-
};
91-
for (int i = 0; i < x_new.size(); i++)
84+
0.526347872422335, 70.553060829315,
85+
10.3757829833265, 3.74540440603423,
86+
4.39240440603423, 18.5135917953949,
87+
2.092, 89.2771917736789, 89.2771917736789,
88+
89.2771917736788, 18.5135917953949};
89+
for(int i = 0; i < x_new.size(); i++)
9290
CHECK(x_new.get(i) == Catch::Approx(expected[i]).epsilon(tol));
9391
}
9492

@@ -99,9 +97,8 @@ TEST_CASE("VDI2048 regression") {
9997
0.104623410451298, 0.559872848891984,
10098
0.133003389109488, 0.056695251568643,
10199
0.056695251568643, 0.137102511396334,
102-
0.272
103-
};
104-
for (int i = 0; i < confint_new.size(); i++)
100+
0.272};
101+
for(int i = 0; i < confint_new.size(); i++)
105102
CHECK(confint_new.get(i) == Catch::Approx(expected[i]).epsilon(tol));
106103
}
107104
}

0 commit comments

Comments
 (0)