Skip to content

Commit 4de835a

Browse files
committed
Address 'bugprone-*' clang-tidy remarks
1 parent b002e57 commit 4de835a

16 files changed

Lines changed: 162 additions & 102 deletions

.clang-tidy

Lines changed: 95 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,97 @@
1-
Checks: >
2-
modernize-*,
3-
performance-*,
4-
portability-*,
5-
readability-*,
6-
-google-readability-braces-around-statements,
7-
-google-readability-namespace-comments,
8-
-google-runtime-references,
9-
-misc-non-private-member-variables-in-classes,
10-
-misc-const-correctness,
11-
-misc-include-cleaner,
12-
-modernize-return-braced-init-list,
13-
-modernize-use-trailing-return-type,
14-
-modernize-concat-nested-namespaces,
15-
-modernize-use-nodiscard,
16-
-modernize-avoid-c-arrays,
17-
-modernize-pass-by-value,
18-
-performance-move-const-arg,
19-
-performance-avoid-endl,
20-
-readability-braces-around-statements,
21-
-readability-identifier-length,
22-
-readability-magic-numbers,
23-
-readability-named-parameter,
24-
-readability-redundant-declaration,
25-
-readability-function-cognitive-complexity,
26-
-bugprone-narrowing-conversions,
27-
-bugprone-easily-swappable-parameters,
28-
-bugprone-implicit-widening-of-multiplication-result,
29-
-bugprone-unchecked-optional-access,
1+
Checks : > google - *, modernize - *, performance - *, portability - *,
2+
readability - *, -google - readability - braces - around - statements,
3+
-google - readability - namespace - comments,
4+
-google - runtime - references,
5+
-misc - non - private - member - variables - in - classes,
6+
-misc - const - correctness, -misc - include - cleaner,
7+
-modernize - return -braced - init - list,
8+
-modernize - use - trailing - return -type,
9+
-modernize - concat - nested - namespaces, -modernize - use - nodiscard,
10+
-modernize - avoid - c - arrays, -modernize - pass - by - value,
11+
-performance - move - const - arg, -performance - avoid - endl,
12+
-readability - braces - around - statements,
13+
-readability - identifier - length, -readability - magic - numbers,
14+
-readability - named - parameter, -readability - redundant - declaration,
15+
-readability - function - cognitive - complexity,
16+
-bugprone - narrowing - conversions,
17+
-bugprone - easily - swappable - parameters,
18+
-bugprone - implicit - widening - of - multiplication - result,
19+
-bugprone - unchecked - optional - access,
3020
31-
WarningsAsErrors: "*"
21+
WarningsAsErrors : "*"
3222
33-
CheckOptions:
34-
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
35-
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
36-
- { key: readability-identifier-naming.StructCase, value: CamelCase }
37-
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
38-
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
39-
- { key: readability-identifier-naming.VariableCase, value: lower_case }
40-
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
41-
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
42-
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
43-
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
44-
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
45-
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
46-
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
47-
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
48-
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
49-
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
50-
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
51-
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
52-
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
53-
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
54-
- { key: readability-implicit-bool-conversion.AllowIntegerConditions, value: 1 }
55-
- { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1 }
56-
- { key: readability-function-cognitive-complexity.IgnoreMacros, value: 1 }
23+
CheckOptions
24+
: -{
25+
key : readability - identifier - naming.NamespaceCase,
26+
value : lower_case
27+
} -
28+
{key : readability - identifier - naming.ClassCase, value : CamelCase} -
29+
{key : readability - identifier - naming.StructCase, value : CamelCase} -
30+
{
31+
key : readability - identifier - naming.TemplateParameterCase,
32+
value : CamelCase
33+
} -
34+
{key : readability - identifier - naming.FunctionCase, value : aNy_CasE} -
35+
{
36+
key : readability - identifier - naming.VariableCase,
37+
value : lower_case
38+
} -
39+
{
40+
key : readability - identifier - naming.ClassMemberCase,
41+
value : lower_case
42+
} -
43+
{key : readability - identifier - naming.ClassMemberSuffix, value : _} -
44+
{key : readability - identifier - naming.PrivateMemberSuffix, value : _} -
45+
{
46+
key : readability - identifier - naming.ProtectedMemberSuffix,
47+
value : _
48+
} -
49+
{
50+
key : readability - identifier - naming.EnumConstantCase,
51+
value : CamelCase
52+
} -
53+
{key : readability - identifier - naming.EnumConstantPrefix, value : k} -
54+
{
55+
key : readability - identifier - naming.ConstexprVariableCase,
56+
value : CamelCase
57+
} -
58+
{
59+
key : readability - identifier - naming.ConstexprVariablePrefix,
60+
value : k
61+
} -
62+
{
63+
key : readability - identifier - naming.GlobalConstantCase,
64+
value : CamelCase
65+
} -
66+
{
67+
key : readability - identifier - naming.GlobalConstantPrefix,
68+
value : k
69+
} -
70+
{
71+
key : readability - identifier - naming.MemberConstantCase,
72+
value : CamelCase
73+
} -
74+
{
75+
key : readability - identifier - naming.MemberConstantPrefix,
76+
value : k
77+
} -
78+
{
79+
key : readability - identifier - naming.StaticConstantCase,
80+
value : CamelCase
81+
} -
82+
{
83+
key : readability - identifier - naming.StaticConstantPrefix,
84+
value : k
85+
} -
86+
{
87+
key : readability - implicit - bool - conversion.AllowIntegerConditions,
88+
value : 1
89+
} -
90+
{
91+
key : readability - implicit - bool - conversion.AllowPointerConditions,
92+
value : 1
93+
} -
94+
{
95+
key : readability - function - cognitive - complexity.IgnoreMacros,
96+
value : 1
97+
}

app/Converters/reader_weights_sample_onnx.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ int main() {
3030
if (value.is_array()) {
3131
std::cout << "[";
3232
for (const auto& v : value) {
33-
if (v.is_number())
33+
if (v.is_number()) {
3434
std::cout << v.get<float>() << " ";
35-
else if (v.is_string())
35+
} else if (v.is_string()) {
3636
std::cout << v.get<std::string>() << " ";
37+
}
3738
}
3839
std::cout << "]";
3940
} else if (value.is_number()) {

app/Graph/build.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
3636

3737
for (const auto& layer_data : model_data) {
3838
std::string layer_type = layer_data["type"];
39-
if (comments)
39+
if (comments) {
4040
std::cout << "Processing layer of type: " << layer_type << std::endl;
41+
}
4142

4243
it_lab_ai::Tensor tensor =
4344
it_lab_ai::create_tensor_from_json(layer_data, it_lab_ai::Type::kFloat);
@@ -84,8 +85,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
8485
layer_ptrs.push_back(ew_layer.get());
8586
layers.push_back(std::move(ew_layer));
8687
layerpostop.push_back(true);
87-
if (comments)
88+
if (comments) {
8889
std::cout << "Element wise (relu) added to layers" << std::endl;
90+
}
8991
}
9092
if (layer_type.find("Dense") != std::string::npos) {
9193
it_lab_ai::Tensor tmp_bias = it_lab_ai::make_tensor(tensor.get_bias());
@@ -104,9 +106,10 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
104106
} else {
105107
pooltype = "average";
106108
}
107-
if (comments)
109+
if (comments) {
108110
std::cout << "PoolingLayer shape: " << shape[0] << "x" << shape[1]
109111
<< std::endl;
112+
}
110113
auto pool_layer =
111114
std::make_unique<it_lab_ai::PoolingLayer>(shape, pooltype, kDefault);
112115
layer_ptrs.push_back(pool_layer.get());
@@ -129,15 +132,17 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
129132
layer_ptrs.push_back(dropout_layer.get());
130133
layers.push_back(std::move(dropout_layer));
131134
layerpostop.push_back(false);
132-
if (comments)
135+
if (comments) {
133136
std::cout
134137
<< "DropOutLayer added to layers with probability 0.4 (turned "
135138
"off for inference)."
136139
<< std::endl;
140+
}
137141
}
138142
}
139-
if (comments)
143+
if (comments) {
140144
std::cout << "number of layers - " << layers.size() + 1 << std::endl;
145+
}
141146
auto a1 = std::make_unique<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
142147
it_lab_ai::kNchw);
143148
Layer* a1_ptr = a1.get();
@@ -148,17 +153,19 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
148153
if (comments) std::cout << "Input set in graph." << std::endl;
149154

150155
graph.makeConnection(a1_ptr, layer_ptrs[0]);
151-
if (comments)
156+
if (comments) {
152157
std::cout << "Connection made between InputLayer and first layer."
153158
<< std::endl;
159+
}
154160

155161
for (size_t i = 0; i < layers.size() - 1; ++i) {
156162
if (layerpostop[i]) {
157163
layer_ptrs[i - 1]->postops.layers.push_back(layer_ptrs[i]);
158164
layer_ptrs[i - 1]->postops.count++;
159165
graph.makeConnection(layer_ptrs[i - 1], layer_ptrs[i + 1]);
160-
} else if (!layerpostop[i + 1])
166+
} else if (!layerpostop[i + 1]) {
161167
graph.makeConnection(layer_ptrs[i], layer_ptrs[i + 1]);
168+
}
162169
}
163170

164171
graph.setOutput(layer_ptrs.back(), output);
@@ -460,11 +467,12 @@ ParseResult parse_json_model(const std::string& json_path, bool comments) {
460467
} else if (layer_type.find("Dropout") != std::string::npos) {
461468
auto dropout_layer = std::make_unique<it_lab_ai::DropOutLayer>(0.0);
462469
layer = std::move(dropout_layer);
463-
if (comments)
470+
if (comments) {
464471
std::cout
465472
<< "DropOutLayer added to layers with probability 0.4 (turned "
466473
"off for inference)."
467474
<< std::endl;
475+
}
468476
} else if (layer_type == "GlobalAveragePool") {
469477
auto pool_layer = std::make_unique<it_lab_ai::PoolingLayer>(
470478
it_lab_ai::Shape({0, 0}), "average", kDefault);
@@ -668,15 +676,15 @@ ParseResult parse_json_model(const std::string& json_path, bool comments) {
668676
}
669677
} else {
670678
it_lab_ai::BinaryOpLayer::Operation op;
671-
if (layer_type == "Add")
679+
if (layer_type == "Add") {
672680
op = it_lab_ai::BinaryOpLayer::Operation::kAdd;
673-
else if (layer_type == "Sub")
681+
} else if (layer_type == "Sub") {
674682
op = it_lab_ai::BinaryOpLayer::Operation::kSub;
675-
else if (layer_type == "Mul")
683+
} else if (layer_type == "Mul") {
676684
op = it_lab_ai::BinaryOpLayer::Operation::kMul;
677-
else if (layer_type == "Div")
685+
} else if (layer_type == "Div") {
678686
op = it_lab_ai::BinaryOpLayer::Operation::kDiv;
679-
else {
687+
} else {
680688
op = it_lab_ai::BinaryOpLayer::Operation::kAdd;
681689
}
682690

include/layers/DropOutLayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DropOutLayer : public Layer {
1111
bool training_mode_;
1212

1313
public:
14-
DropOutLayer(double drop_rate = 0.0, bool training_mode = false)
14+
explicit DropOutLayer(double drop_rate = 0.0, bool training_mode = false)
1515
: Layer(kDropout) {
1616
drop_rate_ = drop_rate;
1717
training_mode_ = training_mode;

include/layers/EWLayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ T relu(const T& value) {
2020
class EWLayer : public Layer {
2121
public:
2222
EWLayer() : Layer(kElementWise), func_("none"), alpha_(0.0F), beta_(0.0F) {}
23-
EWLayer(std::string function, float alpha = 0.0F, float beta = 0.0F)
23+
explicit EWLayer(std::string function, float alpha = 0.0F, float beta = 0.0F)
2424
: Layer(kElementWise),
2525
func_(std::move(function)),
2626
alpha_(alpha),

include/layers/FCLayer.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ template <typename ValueType>
116116
FCLayerImpl<ValueType>::FCLayerImpl(const std::vector<ValueType>& input_weights,
117117
const Shape& input_weights_shape,
118118
const std::vector<ValueType>& input_bias)
119-
: LayerImpl<ValueType>(1, 1), weights_(input_weights), bias_(input_bias) {
119+
: LayerImpl<ValueType>(Shape({input_weights_shape[0]}),
120+
Shape({input_weights_shape[1]})),
121+
weights_(input_weights),
122+
bias_(input_bias) {
120123
if (input_weights.empty()) {
121124
throw std::invalid_argument("Empty weights for FCLayer");
122125
}

include/layers/FlattenLayer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class FlattenLayer : public Layer {
1515

1616
public:
1717
FlattenLayer() : Layer(kFlatten), order_({0, 1, 2, 3}), axis_(0) {}
18-
FlattenLayer(int axis) : Layer(kFlatten), order_({}), axis_(axis) {}
19-
FlattenLayer(const std::vector<size_t>& order)
18+
explicit FlattenLayer(int axis) : Layer(kFlatten), order_({}), axis_(axis) {}
19+
explicit FlattenLayer(const std::vector<size_t>& order)
2020
: Layer(kFlatten), order_(order), axis_(0) {}
2121
void run(const std::vector<Tensor>& input,
2222
std::vector<Tensor>& output) override;

include/layers/Layer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct PostOperations {
4444
class Layer {
4545
public:
4646
Layer() = default;
47-
Layer(LayerType type) : type_(type) {}
47+
explicit Layer(LayerType type) : type_(type) {}
4848
virtual ~Layer() = default;
4949
PostOperations postops;
5050
int getID() const { return id_; }

include/layers/OutputLayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace it_lab_ai {
1212
class OutputLayer : public Layer {
1313
public:
1414
OutputLayer() : Layer(kOutput) {}
15-
OutputLayer(const std::vector<std::string>& labels)
15+
explicit OutputLayer(const std::vector<std::string>& labels)
1616
: Layer(kOutput), labels_(labels) {}
1717
void run(const std::vector<Tensor>& input,
1818
std::vector<Tensor>& output) override {

0 commit comments

Comments
 (0)