Skip to content

Commit 9dad430

Browse files
committed
Address 'bugprone-*' clang-tidy remarks
1 parent b002e57 commit 9dad430

16 files changed

Lines changed: 68 additions & 48 deletions

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Checks: >
2+
bugprone-*,
23
modernize-*,
34
performance-*,
45
portability-*,

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 {

include/layers/PoolingLayer.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ enum PoolingType : uint8_t { kAverage, kMax };
1818

1919
class PoolingLayer : public Layer {
2020
public:
21-
PoolingLayer(const Shape& pooling_shape, const Shape& strides = {2, 2},
22-
const Shape& pads = {0, 0, 0, 0},
23-
const Shape& dilations = {1, 1}, bool ceil_mode = false,
24-
std::string pooling_type = "average",
25-
ImplType implType = kDefault)
21+
explicit PoolingLayer(const Shape& pooling_shape,
22+
const Shape& strides = {2, 2},
23+
const Shape& pads = {0, 0, 0, 0},
24+
const Shape& dilations = {1, 1}, bool ceil_mode = false,
25+
std::string pooling_type = "average",
26+
ImplType implType = kDefault)
2627
: Layer(kPooling),
2728
poolingShape_(pooling_shape),
2829
strides_(strides),
@@ -31,8 +32,9 @@ class PoolingLayer : public Layer {
3132
ceil_mode_(ceil_mode),
3233
poolingType_(std::move(pooling_type)),
3334
implType_(implType) {}
34-
PoolingLayer(const Shape& pooling_shape, std::string pooling_type = "average",
35-
ImplType implType = kDefault)
35+
explicit PoolingLayer(const Shape& pooling_shape,
36+
std::string pooling_type = "average",
37+
ImplType implType = kDefault)
3638
: Layer(kPooling),
3739
poolingShape_(pooling_shape),
3840
strides_({2, 2}),
@@ -250,9 +252,10 @@ std::vector<ValueType> PoolingLayerImpl<ValueType>::run(
250252
if (batch_dim >= 0) input_coords[batch_dim] = n;
251253
if (channel_dim >= 0) input_coords[channel_dim] = c;
252254
input_coords[this->inputShape_.dims() - spatial_dims] = pos_h;
253-
if (spatial_dims > 1)
255+
if (spatial_dims > 1) {
254256
input_coords[this->inputShape_.dims() - spatial_dims + 1] =
255257
pos_w;
258+
}
256259

257260
size_t input_index = this->inputShape_.get_index(input_coords);
258261
pooling_buf.push_back(input[input_index]);
@@ -264,8 +267,9 @@ std::vector<ValueType> PoolingLayerImpl<ValueType>::run(
264267
if (batch_dim >= 0) output_coords[batch_dim] = n;
265268
if (channel_dim >= 0) output_coords[channel_dim] = c;
266269
output_coords[this->outputShape_.dims() - spatial_dims] = h;
267-
if (spatial_dims > 1)
270+
if (spatial_dims > 1) {
268271
output_coords[this->outputShape_.dims() - spatial_dims + 1] = w;
272+
}
269273

270274
size_t output_index = this->outputShape_.get_index(output_coords);
271275

@@ -377,9 +381,10 @@ std::vector<ValueType> PoolingLayerImplTBB<ValueType>::run(
377381
if (channel_dim >= 0) input_coords[channel_dim] = c;
378382
input_coords[this->inputShape_.dims() -
379383
spatial_dims] = pos_h;
380-
if (spatial_dims > 1)
384+
if (spatial_dims > 1) {
381385
input_coords[this->inputShape_.dims() -
382386
spatial_dims + 1] = pos_w;
387+
}
383388

384389
size_t input_index =
385390
this->inputShape_.get_index(input_coords);
@@ -394,9 +399,10 @@ std::vector<ValueType> PoolingLayerImplTBB<ValueType>::run(
394399
if (channel_dim >= 0) output_coords[channel_dim] = c;
395400
output_coords[this->outputShape_.dims() - spatial_dims] =
396401
h;
397-
if (spatial_dims > 1)
402+
if (spatial_dims > 1) {
398403
output_coords[this->outputShape_.dims() - spatial_dims +
399404
1] = w;
405+
}
400406

401407
size_t output_index =
402408
this->outputShape_.get_index(output_coords);

0 commit comments

Comments
 (0)