Skip to content

Commit b6d519a

Browse files
committed
Strengthen clang-format checks
1 parent c9dac34 commit b6d519a

74 files changed

Lines changed: 1021 additions & 813 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
Language: Cpp
2+
Standard: c++20
23
BasedOnStyle: Google
4+
UseTab: Never
5+
AllowShortFunctionsOnASingleLine: Empty
6+
IndentPPDirectives: AfterHash
7+
SortIncludes: true
8+
FixNamespaceComments: true
9+
InsertBraces: true
10+
QualifierAlignment: Left
11+
PointerAlignment: Right
12+
ReferenceAlignment: Right
13+
SortUsingDeclarations: LexicographicNumeric
14+
InsertNewlineAtEOF: true
15+
LambdaBodyIndentation: OuterScope
16+
MaxEmptyLinesToKeep: 1
17+
LineEnding: LF

app/Converters/reader_weights_sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ int main() {
2525
}
2626

2727
return 0;
28-
}
28+
}

app/Converters/reader_weights_sample_onnx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ int main() {
7474
}
7575

7676
return 0;
77-
}
77+
}

app/Graph/acc_check.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ int main(int argc, char* argv[]) {
9797
for (int i = 0; i < 28; ++i) {
9898
for (int j = 0; j < 28; ++j) {
9999
size_t a = ind;
100-
for (size_t n = 0; n < name; n++) a += counts[n] + 1;
100+
for (size_t n = 0; n < name; n++) {
101+
a += counts[n] + 1;
102+
}
101103
res[(a) * 28 * 28 + i * 28 + j] = channels[0].at<uchar>(j, i);
102104
}
103105
}
@@ -124,8 +126,12 @@ int main(int argc, char* argv[]) {
124126
for (size_t name = 0; name < 10; name++) {
125127
for (size_t ind = 0; ind < counts[name] + 1; ind++) {
126128
size_t a = ind;
127-
for (size_t n = 0; n < name; n++) a += counts[n] + 1;
128-
if (name == indices[a]) stat++;
129+
for (size_t n = 0; n < name; n++) {
130+
a += counts[n] + 1;
131+
}
132+
if (name == indices[a]) {
133+
stat++;
134+
}
129135
}
130136
}
131137
double percentage =
@@ -177,7 +183,9 @@ int main(int argc, char* argv[]) {
177183
folder_oss << std::setw(5) << std::setfill('0') << class_id;
178184
std::string class_folder_path = dataset_path + "/" + folder_oss.str();
179185

180-
if (!fs::exists(class_folder_path)) continue;
186+
if (!fs::exists(class_folder_path)) {
187+
continue;
188+
}
181189

182190
for (const auto& entry : fs::directory_iterator(class_folder_path)) {
183191
if (entry.path().extension() == ".png" ||
@@ -280,4 +288,4 @@ int main(int argc, char* argv[]) {
280288
<< final_accuracy_top5 << "%" << '\n';
281289

282290
return 0;
283-
}
291+
}

app/Graph/build.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
2525
std::string json_file = MODEL_PATH_H5;
2626
it_lab_ai::json model_data = it_lab_ai::read_json(json_file);
2727

28-
if (comments) std::cout << "Loaded model data from JSON." << '\n';
28+
if (comments) {
29+
std::cout << "Loaded model data from JSON." << '\n';
30+
}
2931

3032
for (const auto& layer_data : model_data) {
3133
std::string layer_type = layer_data["type"];
@@ -70,7 +72,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
7072
options, 1, pads, 1, tmp_values, tmp_bias, 1, true);
7173
layers.push_back(conv_layer);
7274
layerpostop.push_back(false);
73-
if (comments) std::cout << "ConvLayer added to layers." << '\n';
75+
if (comments) {
76+
std::cout << "ConvLayer added to layers." << '\n';
77+
}
7478
}
7579
if (layer_type.find("relu") != std::string::npos) {
7680
auto ew_layer = LayerFactory::createEwLayer("relu", options);
@@ -85,7 +89,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
8589
auto fc_layer = std::make_shared<it_lab_ai::FCLayer>(tensor, tmp_bias);
8690
layers.push_back(fc_layer);
8791
layerpostop.push_back(false);
88-
if (comments) std::cout << "DenseLayer added to layers." << '\n';
92+
if (comments) {
93+
std::cout << "DenseLayer added to layers." << '\n';
94+
}
8995
}
9096

9197
if (layer_type.find("Pool") != std::string::npos) {
@@ -105,15 +111,19 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
105111

106112
layers.push_back(pool_layer);
107113
layerpostop.push_back(false);
108-
if (comments) std::cout << "PoolingLayer added to layers." << '\n';
114+
if (comments) {
115+
std::cout << "PoolingLayer added to layers." << '\n';
116+
}
109117
}
110118

111119
if (layer_type.find("Flatten") != std::string::npos) {
112120
auto flatten_layer = std::make_shared<it_lab_ai::FlattenLayer>(
113121
std::vector<size_t>({0, 3, 2, 1}));
114122
layers.push_back(flatten_layer);
115123
layerpostop.push_back(false);
116-
if (comments) std::cout << "FlattenLayer added to layers." << '\n';
124+
if (comments) {
125+
std::cout << "FlattenLayer added to layers." << '\n';
126+
}
117127
}
118128

119129
if (layer_type.find("Dropout") != std::string::npos) {
@@ -128,14 +138,20 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
128138
}
129139
}
130140
}
131-
if (comments) std::cout << "number of layers - " << layers.size() + 1 << '\n';
141+
if (comments) {
142+
std::cout << "number of layers - " << layers.size() + 1 << '\n';
143+
}
132144
auto a1 = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
133145
it_lab_ai::kNchw);
134146

135-
if (comments) std::cout << "InputLayer created." << '\n';
147+
if (comments) {
148+
std::cout << "InputLayer created." << '\n';
149+
}
136150

137151
graph.setInput(a1, input);
138-
if (comments) std::cout << "Input set in graph." << '\n';
152+
if (comments) {
153+
std::cout << "Input set in graph." << '\n';
154+
}
139155

140156
graph.makeConnection(a1, layers[0]);
141157
if (comments) {
@@ -199,13 +215,12 @@ void build_graph(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
199215
try {
200216
std::sort(connection_list.begin(), connection_list.end(),
201217
[&](const auto& a, const auto& b) {
202-
if (!name_to_layer.contains(a.first) ||
203-
!name_to_layer.contains(b.first)) {
204-
return false;
205-
}
206-
return name_to_layer[a.first]->getID() <
207-
name_to_layer[b.first]->getID();
208-
});
218+
if (!name_to_layer.contains(a.first) ||
219+
!name_to_layer.contains(b.first)) {
220+
return false;
221+
}
222+
return name_to_layer[a.first]->getID() < name_to_layer[b.first]->getID();
223+
});
209224

210225
} catch (const std::exception& e) {
211226
std::cerr << "ERROR during sorting: " << e.what() << '\n';
@@ -298,7 +313,9 @@ ParseResult parse_json_model(RuntimeOptions options,
298313
}
299314
}
300315

301-
if (comments) std::cout << "Loaded model data from JSON." << '\n';
316+
if (comments) {
317+
std::cout << "Loaded model data from JSON." << '\n';
318+
}
302319

303320
auto input_layer = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
304321
it_lab_ai::kNchw);
@@ -311,7 +328,9 @@ ParseResult parse_json_model(RuntimeOptions options,
311328
try {
312329
std::string layer_type = layer_data["type"];
313330

314-
if (layer_type == "InputLayer") continue;
331+
if (layer_type == "InputLayer") {
332+
continue;
333+
}
315334
std::string layer_name = layer_data["name"];
316335
int layer_index = layer_data["index"];
317336
if (comments) {
@@ -705,7 +724,9 @@ ParseResult parse_json_model(RuntimeOptions options,
705724
std::cout << "TransposeLayer added with perm: [";
706725
for (size_t i = 0; i < perm.size(); ++i) {
707726
std::cout << perm[i];
708-
if (i < perm.size() - 1) std::cout << ", ";
727+
if (i < perm.size() - 1) {
728+
std::cout << ", ";
729+
}
709730
}
710731
std::cout << "]" << '\n';
711732
}

app/Graph/graph_build.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ int main(int argc, char* argv[]) {
181181
}
182182
}
183183
return 0;
184-
}
184+
}

include/graph/graph.hpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ class Graph {
9393
#endif
9494

9595
public:
96-
Graph() { arrayV_.push_back(0); }
96+
Graph() {
97+
arrayV_.push_back(0);
98+
}
9799

98100
Graph(int vertices, std::vector<std::vector<std::pair<int, int>>> split)
99101
: BiggestSize_(vertices), split_distribution_(std::move(split)) {
@@ -150,7 +152,9 @@ class Graph {
150152
arrayE_.begin() + arrayV_[layerID + 1]);
151153
}
152154

153-
[[nodiscard]] int getLayersCount() const { return V_; }
155+
[[nodiscard]] int getLayersCount() const {
156+
return V_;
157+
}
154158

155159
[[nodiscard]] std::shared_ptr<Layer> getLayerFromID(size_t layerID) const {
156160
if (layerID >= layers_.size()) {
@@ -188,7 +192,9 @@ class Graph {
188192
}
189193

190194
void addSingleLayer(const std::shared_ptr<Layer>& layer) {
191-
if (!layer) return;
195+
if (!layer) {
196+
return;
197+
}
192198

193199
int id = layer->getID();
194200
bool layer_exists = (id >= 0 && id < V_ && layers_[id] == layer);
@@ -314,7 +320,9 @@ class Graph {
314320

315321
bool areLayerNext(const std::shared_ptr<Layer>& layPrev,
316322
const std::shared_ptr<Layer>& layNext) {
317-
if (!layPrev || !layNext) return false;
323+
if (!layPrev || !layNext) {
324+
return false;
325+
}
318326

319327
if (layPrev->getID() >= V_ || layPrev->getID() < 0) {
320328
throw std::invalid_argument("No such layer in graph");
@@ -433,8 +441,12 @@ class Graph {
433441
stats.min_time = elapsed_ms;
434442
stats.max_time = elapsed_ms;
435443
} else {
436-
if (elapsed_ms < stats.min_time) stats.min_time = elapsed_ms;
437-
if (elapsed_ms > stats.max_time) stats.max_time = elapsed_ms;
444+
if (elapsed_ms < stats.min_time) {
445+
stats.min_time = elapsed_ms;
446+
}
447+
if (elapsed_ms > stats.max_time) {
448+
stats.max_time = elapsed_ms;
449+
}
438450
}
439451
#endif
440452
}
@@ -449,7 +461,9 @@ class Graph {
449461
}
450462

451463
#ifdef ENABLE_STATISTIC_TENSORS
452-
std::vector<Tensor> getTensors() { return tensors_; }
464+
std::vector<Tensor> getTensors() {
465+
return tensors_;
466+
}
453467
#endif
454468
#ifdef ENABLE_STATISTIC_TIME
455469
std::vector<std::string> getTimeInfo() {
@@ -461,10 +475,14 @@ class Graph {
461475
}
462476
return res;
463477
}
464-
std::vector<int> getTime() { return time_; }
478+
std::vector<int> getTime() {
479+
return time_;
480+
}
465481
#endif
466482
#ifdef ENABLE_STATISTIC_WEIGHTS
467-
std::vector<Tensor> getWEIGHTS() { return weights_; }
483+
std::vector<Tensor> getWEIGHTS() {
484+
return weights_;
485+
}
468486
#endif
469487

470488
[[nodiscard]] std::vector<std::pair<int, int>> getInOutDegrees() const {
@@ -495,7 +513,9 @@ class Graph {
495513
}
496514

497515
private:
498-
void markExecutionPlanDirty() { execution_plan_dirty_ = true; }
516+
void markExecutionPlanDirty() {
517+
execution_plan_dirty_ = true;
518+
}
499519

500520
void ensureExecutionPlan() const {
501521
if (execution_plan_dirty_) {
@@ -559,7 +579,9 @@ class Graph {
559579
std::vector<int> traversal_in_degree = in_degree;
560580

561581
std::function<void(int)> dfs = [&](int vertex) {
562-
if (visited[static_cast<size_t>(vertex)]) return;
582+
if (visited[static_cast<size_t>(vertex)]) {
583+
return;
584+
}
563585

564586
visited[static_cast<size_t>(vertex)] = true;
565587
traversal_order_.push_back(vertex);

include/layers/BatchNormalizationLayer.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ class BatchNormalizationLayer : public Layer {
2525
std::vector<Tensor>& output) override;
2626

2727
#ifdef ENABLE_STATISTIC_WEIGHTS
28-
Tensor get_weights() override { return Tensor(); }
28+
Tensor get_weights() override {
29+
return Tensor();
30+
}
2931
#endif
3032

31-
void set_epsilon(float epsilon) { epsilon_ = epsilon; }
32-
void set_momentum(float momentum) { momentum_ = momentum; }
33-
void set_training_mode(bool training_mode) { training_mode_ = training_mode; }
33+
void set_epsilon(float epsilon) {
34+
epsilon_ = epsilon;
35+
}
36+
void set_momentum(float momentum) {
37+
momentum_ = momentum;
38+
}
39+
void set_training_mode(bool training_mode) {
40+
training_mode_ = training_mode;
41+
}
3442

3543
private:
3644
Tensor scale_;
@@ -47,4 +55,4 @@ class BatchNormalizationLayer : public Layer {
4755
void validate_parameters(size_t num_channels) const;
4856
};
4957

50-
} // namespace it_lab_ai
58+
} // namespace it_lab_ai

include/layers/BinaryOpLayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ class BinaryOpLayer : public Layer {
5555
class BinaryOpLayerImpl;
5656
};
5757

58-
} // namespace it_lab_ai
58+
} // namespace it_lab_ai

include/layers/ConcatLayer.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ class ConcatLayer : public Layer {
1515

1616
void run(const std::vector<Tensor>& input,
1717
std::vector<Tensor>& output) override;
18-
void setInputOrder(const std::vector<int>& order) { input_order_ = order; }
18+
void setInputOrder(const std::vector<int>& order) {
19+
input_order_ = order;
20+
}
1921

2022
#ifdef ENABLE_STATISTIC_WEIGHTS
21-
Tensor get_weights() override { return Tensor(); }
23+
Tensor get_weights() override {
24+
return Tensor();
25+
}
2226
#endif
2327

2428
private:
@@ -81,4 +85,4 @@ class ConcatLayer : public Layer {
8185
}
8286
};
8387

84-
} // namespace it_lab_ai
88+
} // namespace it_lab_ai

0 commit comments

Comments
 (0)