Skip to content

Commit ef88c46

Browse files
committed
fix static analizys
1 parent 6639384 commit ef88c46

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/layers/MatmulLayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void MatmulLayer::matmul_nd_nd(const Tensor& a, const Tensor& b,
243243
std::vector<size_t> out_batch_strides(max_batch_dims, out_matrix_size);
244244

245245
for (int i = static_cast<int>(max_batch_dims) - 2; i >= 0; --i) {
246-
size_t idx = static_cast<size_t>(i);
246+
auto idx = static_cast<size_t>(i);
247247
a_batch_strides[idx] = a_batch_strides[idx + 1] * batch_shape_a[idx + 1];
248248
b_batch_strides[idx] = b_batch_strides[idx + 1] * batch_shape_b[idx + 1];
249249
}
@@ -259,7 +259,7 @@ void MatmulLayer::matmul_nd_nd(const Tensor& a, const Tensor& b,
259259
}
260260

261261
for (int i = static_cast<int>(max_batch_dims) - 2; i >= 0; --i) {
262-
size_t idx = static_cast<size_t>(i);
262+
auto idx = static_cast<size_t>(i);
263263
out_batch_strides[idx] =
264264
out_batch_strides[idx + 1] * output_batch_shape[idx + 1];
265265
}
@@ -286,7 +286,7 @@ void MatmulLayer::matmul_nd_nd(const Tensor& a, const Tensor& b,
286286
size_t temp_batch = batch;
287287

288288
for (int i = static_cast<int>(max_batch_dims) - 1; i >= 0; --i) {
289-
size_t idx = static_cast<size_t>(i);
289+
auto idx = static_cast<size_t>(i);
290290
size_t dim_size = output_batch_shape[idx];
291291
size_t batch_idx = temp_batch % dim_size;
292292
temp_batch /= dim_size;

src/layers/ReshapeLayer.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@ void ReshapeLayer::run(const std::vector<Tensor>& input,
2222
}
2323
}
2424

25-
std::vector<int64_t> original_requested_shape = target_shape;
2625
auto final_shape =
2726
calculate_output_shape(data_tensor.get_shape(), target_shape);
2827

2928
switch (data_tensor.get_type()) {
3029
case Type::kFloat:
31-
reshape_impl<float>(data_tensor, output[0], original_requested_shape,
32-
final_shape);
30+
reshape_impl<float>(data_tensor, output[0], target_shape, final_shape);
3331
break;
3432
case Type::kInt:
35-
reshape_impl<int>(data_tensor, output[0], original_requested_shape,
36-
final_shape);
33+
reshape_impl<int>(data_tensor, output[0], target_shape, final_shape);
3734
break;
3835
default:
3936
throw std::runtime_error("Unsupported tensor data type for Reshape");
@@ -96,17 +93,17 @@ std::vector<int64_t> ReshapeLayer::calculate_output_shape(
9693
}
9794

9895
template <typename T>
99-
void ReshapeLayer::reshape_impl(
100-
const Tensor& input, Tensor& output,
101-
const std::vector<int64_t>& original_requested_shape,
102-
const std::vector<int64_t>& final_shape) const {
96+
void ReshapeLayer::reshape_impl(const Tensor& input, Tensor& output,
97+
const std::vector<int64_t>& target_shape,
98+
const std::vector<int64_t>& final_shape) const {
10399
const auto* input_data = input.as<T>();
104100
const Shape& input_shape = input.get_shape();
105101

106-
if (input_shape[0] > 1 && original_requested_shape[0] == 1) {
107-
apply_per_batch_reshape<T>(input, output, original_requested_shape);
102+
if (input_shape[0] > 1 && target_shape[0] == 1) {
103+
apply_per_batch_reshape<T>(input, output, target_shape);
108104
} else {
109105
std::vector<size_t> shape_size_t;
106+
shape_size_t.reserve(final_shape.size());
110107
for (int64_t dim : final_shape) {
111108
shape_size_t.push_back(static_cast<size_t>(dim));
112109
}
@@ -117,12 +114,12 @@ void ReshapeLayer::reshape_impl(
117114
template <typename T>
118115
void ReshapeLayer::apply_per_batch_reshape(
119116
const Tensor& input, Tensor& output,
120-
const std::vector<int64_t>& original_requested_shape) const {
117+
const std::vector<int64_t>& target_shape) const {
121118
const auto* input_data = input.as<T>();
122119
const Shape& input_shape = input.get_shape();
123120
size_t batch_size = input_shape[0];
124121
size_t elements_per_batch = input_shape.count() / batch_size;
125-
std::vector<int64_t> per_batch_target = original_requested_shape;
122+
std::vector<int64_t> per_batch_target = target_shape;
126123
per_batch_target[0] = 1;
127124

128125
Shape single_batch_input_shape = input_shape;
@@ -132,6 +129,7 @@ void ReshapeLayer::apply_per_batch_reshape(
132129
calculate_output_shape(single_batch_input_shape, per_batch_target);
133130

134131
std::vector<size_t> final_output_shape_size_t;
132+
final_output_shape_size_t.reserve(single_batch_output_shape.size());
135133
final_output_shape_size_t.push_back(batch_size);
136134
for (size_t i = 1; i < single_batch_output_shape.size(); ++i) {
137135
final_output_shape_size_t.push_back(

0 commit comments

Comments
 (0)