Skip to content

Commit 924924b

Browse files
committed
Explicitly put size_t in std since newer gcc/clang require that
1 parent dfefde9 commit 924924b

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

src/wasm-ops/batch-normalization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void batch_normalization_f32_imp(float *X, float *Y, int32_t batch_size,
2222
int32_t num_channels, int32_t channel_size,
2323
float *scale, float *bias, float *mean,
2424
float *variance, float epsilon) {
25-
for (size_t nc = 0; nc < batch_size * num_channels; ++nc) {
26-
for (size_t i = 0; i < channel_size; ++i) {
25+
for (std::size_t nc = 0; nc < batch_size * num_channels; ++nc) {
26+
for (std::size_t i = 0; i < channel_size; ++i) {
2727
Y[nc * channel_size + i] =
2828
scale[nc % num_channels] *
2929
((X[nc * channel_size + i] - mean[nc % num_channels]) /

src/wasm-ops/binary-op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void binary_imp(void *data, const T *input_1, const T *input_2, T *output) {
7474
std::vector<int32_t> broadcasted_indices(output_strides.size());
7575

7676
// core functionality (with broadcasting)
77-
for (size_t i = 0; i < output_length; ++i) {
77+
for (std::size_t i = 0; i < output_length; ++i) {
7878
ShapeUtils::offset_to_indices(output_strides, i, broadcasted_indices);
7979
BroadcastUtils::broadcasted_to_original_indices(broadcasted_indices,
8080
dims1_vector, indices_1);

src/wasm-ops/clip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void clip_f32(void *);
1414
template <typename T>
1515
void clip_imp(const T *input, T *output, const int32_t length, const float min,
1616
const float max) {
17-
for (size_t i = 0; i < length; ++i) {
17+
for (std::size_t i = 0; i < length; ++i) {
1818
const auto &val = input[i];
1919
output[i] = (val < min) ? min : (val > max) ? max : val;
2020
}

src/wasm-ops/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ static_assert(sizeof(int) == sizeof(int32_t),
1010
"'int' and 'int32_t' should be the same type");
1111

1212
#define PARAM_VALUE(data, offset, type) \
13-
(*((type *)((((uint8_t *)(data)) + ((size_t)(offset))))))
13+
(*((type *)((((uint8_t *)(data)) + ((std::size_t)(offset))))))
1414
#define PARAM_PTR(data, offset, type) \
1515
((type *)((offset == 0) ? nullptr \
16-
: (((uint8_t *)(data)) + ((size_t)(offset)))))
16+
: (((uint8_t *)(data)) + ((std::size_t)(offset)))))
1717

1818
#define PARAM_BOOL(data, offset) (!!PARAM_VALUE(data, offset, uint8_t))
1919
#define PARAM_INT32(data, offset) PARAM_VALUE(data, offset, int32_t)

src/wasm-ops/instance-normalization.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ void instance_normalization_f32_imp(float *X, float *Y, int32_t batch_size,
2323
float temp;
2424
float mean;
2525
float variance;
26-
size_t physicalOffset;
27-
size_t iterEnd;
28-
size_t currentChannel;
26+
std::size_t physicalOffset;
27+
std::size_t iterEnd;
28+
std::size_t currentChannel;
2929

30-
for (size_t nc = 0; nc < batch_size * num_channels; nc++) {
30+
for (std::size_t nc = 0; nc < batch_size * num_channels; nc++) {
3131
physicalOffset = nc * channel_size;
3232
iterEnd = physicalOffset + channel_size;
3333
currentChannel = nc % num_channels;
3434

3535
// compute mean for this channel
3636
temp = 0;
37-
for (size_t i = physicalOffset; i < iterEnd; ++i) {
37+
for (std::size_t i = physicalOffset; i < iterEnd; ++i) {
3838
temp += X[i];
3939
}
4040
mean = temp / channel_size;
4141

4242
// compute variance for this channel
4343
temp = 0;
44-
for (size_t i = physicalOffset; i < iterEnd; ++i) {
44+
for (std::size_t i = physicalOffset; i < iterEnd; ++i) {
4545
temp += pow(X[i] - mean, 2);
4646
}
4747
variance = temp / channel_size;
4848

4949
// compute normalized value for data in this channel
50-
for (size_t i = physicalOffset; i < iterEnd; ++i) {
50+
for (std::size_t i = physicalOffset; i < iterEnd; ++i) {
5151
Y[i] =
5252
scale[currentChannel] * ((X[i] - mean) / sqrt(variance + epsilon)) +
5353
bias[currentChannel];

src/wasm-ops/softmax.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ void softmax_f32(void *data) {
1616

1717
// Core operator implementation
1818
void softmax_f32_imp(float *X, float *Y, int32_t N, int32_t D) {
19-
for (size_t i = 0; i < N; i++) {
19+
for (std::size_t i = 0; i < N; i++) {
2020
// find row offset
2121
int offset = i * D;
2222

2323
// find max of each logical row
2424
float max = std::numeric_limits<float>::lowest();
25-
for (size_t j = 0; j < D; j++) {
25+
for (std::size_t j = 0; j < D; j++) {
2626
if (X[offset + j] > max)
2727
max = X[offset + j];
2828
}
2929

3030
// find normalization scale per row
3131
float scale = 0;
32-
for (size_t j = 0; j < D; j++) {
32+
for (std::size_t j = 0; j < D; j++) {
3333
Y[offset + j] = exp(X[offset + j] - max);
3434
scale += Y[offset + j];
3535
}
3636

3737
// perform the softmax normalization
38-
for (size_t j = 0; j < D; j++) {
38+
for (std::size_t j = 0; j < D; j++) {
3939
// If scale is 0, then all elements in that row are 0, so no normalization
4040
// operation required
4141
if (scale != 0)

src/wasm-ops/sum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void sum_f32(void *data) {
1515

1616
// Core operator implementation
1717
void sum_f32_imp(int num_tensors, int size, float *Y, float *X) {
18-
for (size_t i = 0; i < num_tensors; ++i) {
19-
for (size_t j = 0; j < size; ++j)
18+
for (std::size_t i = 0; i < num_tensors; ++i) {
19+
for (std::size_t j = 0; j < size; ++j)
2020
Y[j] += X[i * size + j];
2121
}
2222
}

src/wasm-ops/utils/broadcast_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void BroadcastUtils::broadcasted_to_original_indices(
2424
return;
2525
}
2626
auto offset = broadcasted_indices.size() - dims.size();
27-
for (size_t i = 0; i < rank; ++i) {
27+
for (std::size_t i = 0; i < rank; ++i) {
2828
original_indices[i] = broadcasted_indices[offset + i] % dims[i];
2929
}
3030
}

src/wasm-ops/utils/shape_utils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#include "shape_utils.h"
55
#include <math.h>
66

7-
size_t ShapeUtils::size_from_dims(const std::vector<int32_t> &dims) {
7+
std::size_t ShapeUtils::size_from_dims(const std::vector<int32_t> &dims) {
88
auto rank = dims.size();
99
if (rank == 0) {
1010
return 1;
1111
}
1212
if (rank == 1) {
1313
return dims[0];
1414
}
15-
size_t size = 1;
15+
std::size_t size = 1;
1616
for (auto &e : dims) {
1717
size *= e;
1818
}
@@ -45,18 +45,18 @@ void ShapeUtils::compute_strides(const std::vector<int32_t> &dims,
4545
}
4646
}
4747

48-
size_t ShapeUtils::indices_to_offset(const std::vector<int32_t> &strides,
48+
std::size_t ShapeUtils::indices_to_offset(const std::vector<int32_t> &strides,
4949
const std::vector<int32_t> &indices) {
50-
size_t offset = 0;
51-
for (size_t i = 0; i < indices.size(); ++i) {
50+
std::size_t offset = 0;
51+
for (std::size_t i = 0; i < indices.size(); ++i) {
5252
offset += strides[i] * indices[i];
5353
}
5454
return offset;
5555
}
5656

5757
std::vector<int32_t>
5858
ShapeUtils::offset_to_indices(const std::vector<int32_t> &strides,
59-
size_t offset) {
59+
std::size_t offset) {
6060
auto rank = strides.size();
6161
if (rank == 0) {
6262
return std::vector<int32_t>();
@@ -70,7 +70,7 @@ ShapeUtils::offset_to_indices(const std::vector<int32_t> &strides,
7070
}
7171

7272
void ShapeUtils::offset_to_indices(const std::vector<int32_t> &strides,
73-
size_t offset,
73+
std::size_t offset,
7474
std::vector<int32_t> &indices) {
7575
auto rank = strides.size();
7676
if (rank == 0) {
@@ -80,7 +80,7 @@ void ShapeUtils::offset_to_indices(const std::vector<int32_t> &strides,
8080
indices[0] = offset * strides[0];
8181
return;
8282
}
83-
for (size_t i = 0; i < indices.size() - 1; ++i) {
83+
for (std::size_t i = 0; i < indices.size() - 1; ++i) {
8484
indices[i] = floor(offset / strides[i]);
8585
offset -= indices[i] * strides[i];
8686
}

src/wasm-ops/utils/shape_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
#include <stdint.h>
88

99
namespace ShapeUtils {
10-
size_t size_from_dims(const std::vector<int32_t> &dims);
10+
std::size_t size_from_dims(const std::vector<int32_t> &dims);
1111
std::vector<int32_t> compute_strides(const std::vector<int32_t> &dims);
1212
// Fills in values in the strides vector. Assumes it is of the required size.
1313
void compute_strides(const std::vector<int32_t> &dims,
1414
std::vector<int32_t> &strides);
15-
size_t indices_to_offset(const std::vector<int32_t> &strides,
15+
std::size_t indices_to_offset(const std::vector<int32_t> &strides,
1616
const std::vector<int32_t> &indices);
1717
std::vector<int32_t> offset_to_indices(const std::vector<int32_t> &strides,
18-
size_t offset);
18+
std::size_t offset);
1919
// Fills in values in the indices vector. Assumes it is of the required size.
20-
void offset_to_indices(const std::vector<int32_t> &strides, size_t offset,
20+
void offset_to_indices(const std::vector<int32_t> &strides, std::size_t offset,
2121
std::vector<int32_t> &indices);
2222
}; // namespace ShapeUtils

0 commit comments

Comments
 (0)