Skip to content

Commit 33cc3a7

Browse files
committed
Fix typecast in loops
1 parent 093520a commit 33cc3a7

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

cpp/src/neighbors/refine/refine_host.hpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ template<>
8181
inline float euclidean_distance_squared<distance_comp_l2, float, float>(
8282
float const* a, float const* b, size_t n) {
8383

84-
int n_rounded = n - (n % 4);
84+
size_t n_rounded = n - (n % 4);
8585

8686
float32x4_t vreg_dsum = vdupq_n_f32(0.f);
87-
for (int i = 0; i < n_rounded; i += 4) {
87+
for (size_t i = 0; i < n_rounded; i += 4) {
8888
float32x4_t vreg_a = vld1q_f32(&a[i]);
8989
float32x4_t vreg_b = vld1q_f32(&b[i]);
9090
float32x4_t vreg_d = vsubq_f32(vreg_a, vreg_b);
9191
vreg_dsum = vfmaq_f32(vreg_dsum, vreg_d, vreg_d);
9292
}
9393

9494
float dsum = vaddvq_f32(vreg_dsum);
95-
for (int i = n_rounded; i < n; ++i) {
95+
for (size_t i = n_rounded; i < n; ++i) {
9696
float d = a[i] - b[i];
9797
dsum += d * d;
9898
}
@@ -104,7 +104,7 @@ template<>
104104
inline float euclidean_distance_squared<distance_comp_l2, float, ::std::int8_t>(
105105
::std::int8_t const* a, ::std::int8_t const* b, size_t n) {
106106

107-
int n_rounded = n - (n % 16);
107+
size_t n_rounded = n - (n % 16);
108108
float dsum = 0.f;
109109

110110
if (n_rounded > 0) {
@@ -113,7 +113,7 @@ inline float euclidean_distance_squared<distance_comp_l2, float, ::std::int8_t>(
113113
float32x4_t vreg_dsum_fp32_2 = vreg_dsum_fp32_0;
114114
float32x4_t vreg_dsum_fp32_3 = vreg_dsum_fp32_0;
115115

116-
for (int i = 0; i < n_rounded; i += 16) {
116+
for (size_t i = 0; i < n_rounded; i += 16) {
117117
int8x16_t vreg_a = vld1q_s8(&a[i]);
118118
int16x8_t vreg_a_s16_0 = vmovl_s8(vget_low_s8(vreg_a));
119119
int16x8_t vreg_a_s16_1 = vmovl_s8(vget_high_s8(vreg_a));
@@ -143,7 +143,7 @@ inline float euclidean_distance_squared<distance_comp_l2, float, ::std::int8_t>(
143143
dsum = vaddvq_f32(vreg_dsum_fp32_0); // faddp
144144
}
145145

146-
for (int i = n_rounded; i < n; ++i) {
146+
for (size_t i = n_rounded; i < n; ++i) {
147147
float d = a[i] - b[i];
148148
dsum += d * d; // [nvc++] faddp, [clang] fadda, [gcc] vecsum+fadda
149149
}
@@ -155,7 +155,7 @@ template<>
155155
inline float euclidean_distance_squared<distance_comp_l2, float, ::std::uint8_t>(
156156
::std::uint8_t const* a, ::std::uint8_t const* b, size_t n) {
157157

158-
int n_rounded = n - (n % 16);
158+
size_t n_rounded = n - (n % 16);
159159
float dsum = 0.f;
160160

161161
if (n_rounded > 0) {
@@ -164,7 +164,7 @@ inline float euclidean_distance_squared<distance_comp_l2, float, ::std::uint8_t>
164164
float32x4_t vreg_dsum_fp32_2 = vreg_dsum_fp32_0;
165165
float32x4_t vreg_dsum_fp32_3 = vreg_dsum_fp32_0;
166166

167-
for (int i = 0; i < n_rounded; i += 16) {
167+
for (size_t i = 0; i < n_rounded; i += 16) {
168168
uint8x16_t vreg_a = vld1q_u8(&a[i]);
169169
uint16x8_t vreg_a_u16_0 = vmovl_u8(vget_low_u8(vreg_a));
170170
uint16x8_t vreg_a_u16_1 = vmovl_u8(vget_high_u8(vreg_a));
@@ -199,7 +199,7 @@ inline float euclidean_distance_squared<distance_comp_l2, float, ::std::uint8_t>
199199
dsum = vaddvq_f32(vreg_dsum_fp32_0); // faddp
200200
}
201201

202-
for (int i = n_rounded; i < n; ++i) {
202+
for (size_t i = n_rounded; i < n; ++i) {
203203
float d = a[i] - b[i];
204204
dsum += d * d; // [nvc++] faddp, [clang] fadda, [gcc] vecsum+fadda
205205
}
@@ -211,18 +211,18 @@ template<>
211211
inline float euclidean_distance_squared<distance_comp_inner, float, float>(
212212
float const* a, float const* b, size_t n) {
213213

214-
int n_rounded = n - (n % 4);
214+
size_t n_rounded = n - (n % 4);
215215

216216
float32x4_t vreg_dsum = vdupq_n_f32(0.f);
217-
for (int i = 0; i < n_rounded; i += 4) {
217+
for (size_t i = 0; i < n_rounded; i += 4) {
218218
float32x4_t vreg_a = vld1q_f32(&a[i]);
219219
float32x4_t vreg_b = vld1q_f32(&b[i]);
220220
vreg_a = vnegq_f32(vreg_a);
221221
vreg_dsum = vfmaq_f32(vreg_dsum, vreg_a, vreg_b);
222222
}
223223

224224
float dsum = vaddvq_f32(vreg_dsum);
225-
for (int i = n_rounded; i < n; ++i) {
225+
for (size_t i = n_rounded; i < n; ++i) {
226226
dsum += -a[i] * b[i];
227227
}
228228

@@ -233,7 +233,7 @@ template<>
233233
inline float euclidean_distance_squared<distance_comp_inner, float, ::std::int8_t>(
234234
::std::int8_t const* a, ::std::int8_t const* b, size_t n) {
235235

236-
int n_rounded = n - (n % 16);
236+
size_t n_rounded = n - (n % 16);
237237
float dsum = 0.f;
238238

239239
if (n_rounded > 0) {
@@ -242,7 +242,7 @@ inline float euclidean_distance_squared<distance_comp_inner, float, ::std::int8_
242242
float32x4_t vreg_dsum_fp32_2 = vreg_dsum_fp32_0;
243243
float32x4_t vreg_dsum_fp32_3 = vreg_dsum_fp32_0;
244244

245-
for (int i = 0; i < n_rounded; i += 16) {
245+
for (size_t i = 0; i < n_rounded; i += 16) {
246246
int8x16_t vreg_a = vld1q_s8(&a[i]);
247247
int16x8_t vreg_a_s16_0 = vmovl_s8(vget_low_s8(vreg_a));
248248
int16x8_t vreg_a_s16_1 = vmovl_s8(vget_high_s8(vreg_a));
@@ -272,7 +272,7 @@ inline float euclidean_distance_squared<distance_comp_inner, float, ::std::int8_
272272
dsum = vaddvq_f32(vreg_dsum_fp32_0); // faddp
273273
}
274274

275-
for (int i = n_rounded; i < n; ++i) {
275+
for (size_t i = n_rounded; i < n; ++i) {
276276
dsum += -a[i] * b[i];
277277
}
278278

@@ -281,7 +281,7 @@ inline float euclidean_distance_squared<distance_comp_inner, float, ::std::int8_
281281

282282
template<>
283283
inline float euclidean_distance_squared<distance_comp_inner, float, ::std::uint8_t>(::std::uint8_t const* a, ::std::uint8_t const* b, size_t n) {
284-
int n_rounded = n - (n % 16);
284+
size_t n_rounded = n - (n % 16);
285285
float dsum = 0.f;
286286

287287
if (n_rounded > 0) {
@@ -290,7 +290,7 @@ inline float euclidean_distance_squared<distance_comp_inner, float, ::std::uint8
290290
float32x4_t vreg_dsum_fp32_2 = vreg_dsum_fp32_0;
291291
float32x4_t vreg_dsum_fp32_3 = vreg_dsum_fp32_0;
292292

293-
for (int i = 0; i < n_rounded; i += 16) {
293+
for (size_t i = 0; i < n_rounded; i += 16) {
294294
uint8x16_t vreg_a = vld1q_u8(&a[i]);
295295
uint16x8_t vreg_a_u16_0 = vmovl_u8(vget_low_u8(vreg_a));
296296
uint16x8_t vreg_a_u16_1 = vmovl_u8(vget_high_u8(vreg_a));
@@ -320,7 +320,7 @@ inline float euclidean_distance_squared<distance_comp_inner, float, ::std::uint8
320320
dsum = vaddvq_f32(vreg_dsum_fp32_0); // faddp
321321
}
322322

323-
for (int i = n_rounded; i < n; ++i) {
323+
for (size_t i = n_rounded; i < n; ++i) {
324324
dsum += -a[i] * b[i];
325325
}
326326

0 commit comments

Comments
 (0)