Skip to content

Commit 1130a73

Browse files
committed
c/ Use %zu consistently for printing size_t.
1 parent 092dd66 commit 1130a73

4 files changed

Lines changed: 51 additions & 50 deletions

File tree

c/hv_contrib.c

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ hvc_1point_diffs_nondom(double * restrict hvc, double * restrict points,
134134
#undef swap_points
135135
}
136136

137-
/* O(n log n) dimension-sweep algorithm.
137+
/**
138+
O(n log n) dimension-sweep algorithm.
138139
139140
hvc[] must be already allocated with size n. Points that are duplicated
140141
have zero exclusive contribution. Thus, the sum of contributions may
@@ -147,34 +148,35 @@ hvc2d(double * restrict hvc, const double * restrict data, size_t n,
147148
const double * restrict ref)
148149
{
149150
ASSUME(n > 0);
150-
const double **p = generate_sorted_doublep_2d_filter_by_ref(data, &n, ref[0]);
151+
const double ** p = generate_sorted_doublep_2d_filter_by_ref(data, &n, ref[0]);
151152
if (unlikely(n == 0)) return 0;
152153
if (unlikely(!p)) return -1;
153154

154155
size_t j = 0;
155156
// Find first point below the reference point.
156-
while (j < n && p[j][1] >= ref[1])
157+
while (p[j][1] >= ref[1]) {
157158
j++;
158-
if (unlikely(j == n)) {
159-
free(p);
160-
return 0;
159+
if (unlikely(j == n)) {
160+
free(p);
161+
return 0;
162+
}
161163
}
162-
double height = ref[1] - p[j][1];
163-
double hyperv = (ref[0] - p[j][0]) * height;
164164
const double * prev = p[j];
165+
double height = ref[1] - prev[1];
166+
double hyperv = (ref[0] - prev[0]) * height;
165167
j++;
166168
while (j < n) {
167-
DEBUG2_PRINT("[%lld]=(%g, %g) -> [%lld]=(%g,%g) (height=%g)\n",
168-
(long long)(prev - data) / 2, prev[0], prev[1],
169-
(long long)(p[j] - data) / 2, p[j][0], p[j][1], height);
169+
DEBUG2_PRINT("[%zu]=(%g, %g) -> [%zu]=(%g,%g) (height=%g)\n",
170+
((size_t)(prev - data)) / 2, prev[0], prev[1],
171+
((size_t)(p[j] - data)) / 2, p[j][0], p[j][1], height);
170172
// likely() because most points will be non-dominated.
171173
if (likely(prev[1] > p[j][1])) {
172174
assert(prev[0] < p[j][0]);
173175
/* Compute the contribution of prev. We have to accumulate because
174176
we may have computed partial contributions. */
175177
hvc[(prev - data) / 2] += (p[j][0] - prev[0]) * height;
176-
DEBUG2_PRINT("hvc[%lld] += %g * %g = %g\n",
177-
(long long) (prev - data) / 2,
178+
DEBUG2_PRINT("hvc[%zu] += %g * %g = %g\n",
179+
((size_t)(prev - data)) / 2,
178180
p[j][0] - prev[0], height,
179181
(p[j][0] - prev[0]) * height);
180182
height = prev[1] - p[j][1];
@@ -183,20 +185,20 @@ hvc2d(double * restrict hvc, const double * restrict data, size_t n,
183185
prev = p[j];
184186
j++;
185187
} else if (prev[0] < p[j][0]) {
186-
// prev[1] <= p[j][1], thus pj contributes partially to hvc[prev].
188+
// prev[1] <= p[j][1], thus p[j] contributes partially to hvc[prev].
187189
double new_h = p[j][1] - prev[1];
188190
if (new_h < height) {
189191
hvc[(prev - data) / 2] += (p[j][0] - prev[0]) * (height - new_h);
190-
DEBUG2_PRINT("hvc[%lld] += %g * %g = %g\n",
191-
(long long) (prev - data) / 2,
192+
DEBUG2_PRINT("hvc[%zu] += %g * %g = %g\n",
193+
((size_t)(prev - data)) / 2,
192194
p[j][0] - prev[0], height - new_h,
193195
(p[j][0] - prev[0]) * (height - new_h));
194196
height = new_h;
195197
}
196198
j++;
197199
} else if (prev[1] == p[j][1]) { // && prev[0] == p[j][0]
198200
// Duplicates contribute zero.
199-
DEBUG2_PRINT("hvc[%lld] = %g\n", (long long)(prev - data) / 2,
201+
DEBUG2_PRINT("hvc[%zu] = %g\n", ((size_t)(prev - data)) / 2,
200202
hvc[(prev - data) / 2]);
201203
assert(hvc[(prev - data) / 2] == 0);
202204
/* We set height=0 here so that we set hvc[prev] = 0 when we find the
@@ -221,7 +223,7 @@ hvc2d(double * restrict hvc, const double * restrict data, size_t n,
221223
}
222224

223225
hvc[(prev - data) / 2] += (ref[0] - prev[0]) * height;
224-
DEBUG2_PRINT("hvc[%lld] = %g * %g = %g\n", (long long)(prev - data) / 2,
226+
DEBUG2_PRINT("hvc[%zu] = %g * %g = %g\n", ((size_t)(prev - data)) / 2,
225227
ref[0] - prev[0], height, (ref[0] - prev[0]) * height);
226228
free(p);
227229
return hyperv;
@@ -232,33 +234,34 @@ hvc2d_nondom(double * restrict hvc, const double * restrict data, size_t n,
232234
const double * restrict ref)
233235
{
234236
ASSUME(n > 0);
235-
const double **p = generate_sorted_doublep_2d_filter_by_ref(data, &n, ref[0]);
237+
const double ** p = generate_sorted_doublep_2d_filter_by_ref(data, &n, ref[0]);
236238
if (unlikely(n == 0)) return 0;
237239
if (unlikely(!p)) return -1;
238240

239241
size_t j = 0;
240242
// Find first point below the reference point.
241-
while (j < n && p[j][1] >= ref[1])
243+
while (p[j][1] >= ref[1]) {
242244
j++;
243-
if (unlikely(j == n)) {
244-
free(p);
245-
return 0;
245+
if (unlikely(j == n)) {
246+
free(p);
247+
return 0;
248+
}
246249
}
247-
double height = ref[1] - p[j][1];
248-
double hyperv = (ref[0] - p[j][0]) * height;
249250
const double * prev = p[j];
251+
double height = ref[1] - prev[1];
252+
double hyperv = (ref[0] - prev[0]) * height;
250253
j++;
251254
while (j < n) {
252-
DEBUG2_PRINT("[%lld]=(%g, %g) -> [%lld]=(%g,%g) (height=%g)\n",
253-
(long long)(prev - data) / 2, prev[0], prev[1],
254-
(long long)(p[j] - data) / 2, p[j][0], p[j][1], height);
255+
DEBUG2_PRINT("[%zu]=(%g, %g) -> [%zu]=(%g,%g) (height=%g)\n",
256+
((size_t)(prev - data)) / 2, prev[0], prev[1],
257+
((size_t)(p[j] - data)) / 2, p[j][0], p[j][1], height);
255258
// likely() because most points will be non-dominated.
256259
if (likely(prev[1] > p[j][1])) {
257260
assert(prev[0] < p[j][0]);
258-
/* Compute the contribution of prev. */
261+
// Compute the contribution of prev.
259262
hvc[(prev - data) / 2] = (p[j][0] - prev[0]) * height;
260-
DEBUG2_PRINT("hvc[%lld] = %g * %g = %g\n",
261-
(long long) (prev - data) / 2,
263+
DEBUG2_PRINT("hvc[%zu] = %g * %g = %g\n",
264+
((size_t)(prev - data)) / 2,
262265
p[j][0] - prev[0], height,
263266
(p[j][0] - prev[0]) * height);
264267
height = prev[1] - p[j][1];
@@ -269,16 +272,16 @@ hvc2d_nondom(double * restrict hvc, const double * restrict data, size_t n,
269272
} else if (prev[0] == p[j][0]) { // && prev[1] <= p[j][1]
270273
if (prev[1] == p[j][1]) {
271274
// Duplicates contribute zero.
272-
DEBUG2_PRINT("hvc[%lld] = %g\n", (long long)(prev - data) / 2,
275+
DEBUG2_PRINT("hvc[%zu] = %g\n", ((size_t)(prev - data)) / 2,
273276
hvc[(prev - data) / 2]);
274277
assert(hvc[(prev - data) / 2] == 0);
275-
/* We set this here so that we set hvc[prev] = 0 when we find the next
276-
non-duplicate. */
278+
/* We set this here so that we set hvc[prev] = 0 when we find
279+
the next non-duplicate. */
277280
height = 0;
278281
prev = p[j];
279282
}
280-
/* All points with same 0-coordinate are weakly dominated by
281-
prev, so they can be ignored. */
283+
/* All points with same 0-coordinate are weakly dominated by prev,
284+
so they can be ignored. */
282285
do {
283286
j++;
284287
} while (j < n && prev[0] == p[j][0]);
@@ -291,7 +294,7 @@ hvc2d_nondom(double * restrict hvc, const double * restrict data, size_t n,
291294
}
292295

293296
hvc[(prev - data) / 2] = (ref[0] - prev[0]) * height;
294-
DEBUG2_PRINT("hvc[%lld] = %g * %g = %g\n", (long long)(prev - data) / 2,
297+
DEBUG2_PRINT("hvc[%zu] = %g * %g = %g\n", ((size_t)(prev - data)) / 2,
295298
ref[0] - prev[0], height, (ref[0] - prev[0]) * height);
296299
free(p);
297300
return hyperv;

c/hvapprox.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ construct_polar_a(dimension_t dim, uint_fast32_t nsamples)
225225
61, 67, 67 };
226226

227227
const dimension_t p = primes[dim];
228-
DEBUG2_PRINT("construct_polar_a: prime: %u\n", (unsigned int)p);
228+
DEBUG2_PRINT("construct_polar_a: prime: %d\n", p);
229229

230230
uint_fast32_t * a = malloc(dim * sizeof(*a));
231231
a[0] = 1;
232-
DEBUG2_PRINT("construct_polar_a: a[%u] = %lu",
233-
(unsigned int) dim, (unsigned long) a[0]);
232+
DEBUG2_PRINT("construct_polar_a: a[%d] = %lu", dim, (unsigned long) a[0]);
234233
for (dimension_t k = 1; k < dim; k++) {
235234
long double temp = 2 * fabsl(cosl(2 * M_PIl * k / p));
236235
temp = fractl(temp);

c/nondominated.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define NONDOMINATED_H
33

44
#include "config.h"
5-
65
#include <string.h> // memcpy
76
#include <math.h> // INFINITY
87
#include "sort.h"
@@ -23,7 +22,8 @@ typedef struct avl_node_t {
2322
enum objs_agree_t { AGREE_MINIMISE = -1, AGREE_NONE = 0, AGREE_MAXIMISE = 1 };
2423

2524
static inline void
26-
printf_point(const char * prefix, const double * p, dimension_t dim, const char * suffix)
25+
printf_point(const char * prefix, const double * p, dimension_t dim,
26+
const char * suffix)
2727
{
2828
fprintf(stderr, "%s%g", prefix, p[0]);
2929
for (dimension_t d = 1; d < dim; d++)
@@ -46,7 +46,7 @@ printf_rows(const char * prefix,
4646
if (size > 0) {
4747
fprintf(stderr, "%s", prefix);
4848
printf_point(" = [ ", rows[0], dim, " ], ");
49-
// We cannot use %zu for size_t because of MingW compiler used by CRAN.
49+
// The 32-bit MinGW toolchain from Rtools 4.0 does not support %zu.
5050
fprintf(stderr, "%s = %lu\n", size_lab, (unsigned long) size);
5151
print_rows(rows, size, dim);
5252
} else {

c/whv.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ rect_weighted_hv2d(double *data, int n, double * rectangles,
7777
int rectangles_nrow, const double * reference)
7878
{
7979
#define debug_print_point(k, p, r, rect) \
80-
DEBUG2_PRINT("%d: p[%lu] = (%16.15g, %16.15g)" \
81-
"\trectangle[%lu] = (%16.15g, %16.15g, %16.15g, %16.15g)\n", \
82-
__LINE__, (unsigned long) k, p[0], p[1], (unsigned long) r, rect[0], rect[1], rect[2], rect[3])
80+
DEBUG2_PRINT("%d: p[%zu] = (%16.15g, %16.15g)" \
81+
"\trectangle[%zu] = (%16.15g, %16.15g, %16.15g, %16.15g)\n", \
82+
__LINE__, (size_t) k, p[0], p[1], (size_t) r, rect[0], rect[1], rect[2], rect[3])
8383

8484
#define debug_print_rect(r, rect) \
85-
DEBUG2_PRINT("%d: rectangle[%lu] = (%16.15g, %16.15g, %16.15g, %16.15g, %16.15g)\n", \
86-
__LINE__, (unsigned long) r, rect[0], rect[1], rect[2], rect[3], rect[4])
85+
DEBUG2_PRINT("%d: rectangle[%zu] = (%16.15g, %16.15g, %16.15g, %16.15g, %16.15g)\n", \
86+
__LINE__, (size_t) r, rect[0], rect[1], rect[2], rect[3], rect[4])
8787

8888
// rectangles: Two points per row + color
8989
// FIXME: Should we really allow color == 0
@@ -106,8 +106,7 @@ rect_weighted_hv2d(double *data, int n, double * rectangles,
106106
debug_print_point(pk, p, r, rect); \
107107
} while(0)
108108

109-
// We cannot use %zu for size_t because of MingW compiler used by CRAN.
110-
DEBUG2_PRINT("n = %lu\trectangles = %lu\n", (unsigned long)n, (unsigned long)rectangles_nrow);
109+
DEBUG2_PRINT("n = %zu\trectangles = %zu\n", (size_t)n, (size_t)rectangles_nrow);
111110
if (rectangles_nrow <= 0 || n <= 0) return 0;
112111

113112
int old_rectangles_nrow = rectangles_nrow;

0 commit comments

Comments
 (0)