Skip to content

Commit 13dabde

Browse files
committed
Switch argument order of IGD(), IGD_plus(), avg_Hausdorff_dist(), epsilon_additive(), epsilon_mult() to pass first the number of rows then the number of columns.
1 parent aa0cfcd commit 13dabde

7 files changed

Lines changed: 126 additions & 136 deletions

File tree

c/NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
* `pareto_rank()` is now O(k * n log n) in 3D, which is faster than the naive O(n^3).
66
* HV3D+ is slightly faster with repeated coordinates (#41).
7-
* Switch argument order of `fpli_hv()`, `hv_contributions()`
7+
* Switch argument order of `fpli_hv()`, `hv_contributions()`, `IGD()`,
8+
`IGD_plus()`, `avg_Hausdorff_dist()`, `epsilon_additive()`, `epsilon_mult()`
89
to pass first the number of rows then the number of columns.
910

1011
## 0.17.0

c/epsilon.h

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ epsilon_mult_agree_none(const signed char * restrict minmax, dimension_t dim,
109109
_attr_optimize_finite_math
110110
static inline double
111111
epsilon_mult_agree_min(dimension_t dim,
112-
const double * restrict points_a, size_t size_a,
113-
const double * restrict points_b, size_t size_b)
112+
const double * restrict points_a, size_t size_a,
113+
const double * restrict points_b, size_t size_b)
114114
{
115115
return epsilon_helper_(/* do_mult=*/true, AGREE_MINIMISE, /*minmax=*/NULL, dim, points_a, size_a, points_b, size_b);
116116
}
117117

118118
_attr_optimize_finite_math
119119
static inline double
120120
epsilon_mult_agree_max(dimension_t dim,
121-
const double * restrict points_a, size_t size_a,
122-
const double * restrict points_b, size_t size_b)
121+
const double * restrict points_a, size_t size_a,
122+
const double * restrict points_b, size_t size_b)
123123
{
124124
return epsilon_helper_(/* do_mult=*/true, AGREE_MAXIMISE, /*minmax=*/NULL, dim, points_a, size_a, points_b, size_b);
125125
}
@@ -137,17 +137,17 @@ epsilon_addi_agree_none(const signed char * restrict minmax, dimension_t dim,
137137
_attr_optimize_finite_math
138138
static inline double
139139
epsilon_addi_agree_min(dimension_t dim,
140-
const double * restrict points_a, size_t size_a,
141-
const double * restrict points_b, size_t size_b)
140+
const double * restrict points_a, size_t size_a,
141+
const double * restrict points_b, size_t size_b)
142142
{
143143
return epsilon_helper_(/* do_mult=*/false, AGREE_MINIMISE, /*minmax=*/NULL, dim, points_a, size_a, points_b, size_b);
144144
}
145145

146146
_attr_optimize_finite_math
147147
static inline double
148148
epsilon_addi_agree_max(dimension_t dim,
149-
const double * restrict points_a, size_t size_a,
150-
const double * restrict points_b, size_t size_b)
149+
const double * restrict points_a, size_t size_a,
150+
const double * restrict points_b, size_t size_b)
151151
{
152152
return epsilon_helper_(/* do_mult=*/false, AGREE_MAXIMISE, /*minmax=*/NULL, dim, points_a, size_a, points_b, size_b);
153153
}
@@ -194,41 +194,35 @@ epsilon_additive_minmax(const signed char * restrict minmax, dimension_t dim,
194194
}
195195

196196
_attr_maybe_unused static double
197-
epsilon_additive(const double * restrict data, int nobj, int npoints,
198-
const double * restrict ref, int ref_size,
197+
epsilon_additive(const double * restrict data, size_t n, dimension_t dim,
198+
const double * restrict ref, size_t ref_size,
199199
const bool * restrict maximise)
200200
{
201-
ASSUME(nobj >= 2);
202-
ASSUME(npoints >= 0);
203-
ASSUME(ref_size >= 0);
204-
dimension_t dim = (dimension_t) nobj;
201+
ASSUME(dim >= 2);
205202
const signed char * minmax = minmax_from_bool(maximise, dim);
206-
double value = epsilon_additive_minmax(minmax, dim, data, npoints, ref, ref_size);
203+
double value = epsilon_additive_minmax(minmax, dim, data, n, ref, ref_size);
207204
free ((void *)minmax);
208205
return value;
209206
}
210207

211208
_attr_maybe_unused static double
212-
epsilon_mult(const double * restrict data, int nobj, int npoints,
213-
const double * restrict ref, int ref_size,
209+
epsilon_mult(const double * restrict data, size_t n, dimension_t dim,
210+
const double * restrict ref, size_t ref_size,
214211
const bool * restrict maximise)
215212
{
216-
ASSUME(nobj >= 2);
217-
ASSUME(npoints >= 0);
218-
ASSUME(ref_size >= 0);
219-
dimension_t dim = (dimension_t) nobj;
213+
ASSUME(dim >= 2);
220214
const signed char * minmax = minmax_from_bool(maximise, dim);
221-
double value = epsilon_mult_minmax(minmax, dim, data, npoints, ref, ref_size);
215+
double value = epsilon_mult_minmax(minmax, dim, data, n, ref, ref_size);
222216
free ((void *)minmax);
223217
return value;
224218
}
225219

226220
/* FIXME: this can be done much faster. For example, the diff needs to
227221
be calculated just once and stored on a temporary array diff[]. */
228222
static inline int
229-
epsilon_additive_ind (dimension_t dim, const signed char * restrict minmax,
230-
const double * restrict points_a, size_t size_a,
231-
const double * restrict points_b, size_t size_b)
223+
epsilon_additive_ind(dimension_t dim, const signed char * restrict minmax,
224+
const double * restrict points_a, size_t size_a,
225+
const double * restrict points_b, size_t size_b)
232226
{
233227
double eps_ab = epsilon_additive_minmax(
234228
minmax, dim, points_a, size_a, points_b, size_b);

c/igd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ do_file (const char *filename, double *reference, size_t reference_size,
168168

169169
for (int n = 0, cumsize = 0; n < nruns; cumsize = cumsizes[n], n++) {
170170
_attr_maybe_unused double time_elapsed = 0;
171-
int size_a = cumsizes[n] - cumsize;
171+
size_t size_a = cumsizes[n] - cumsize;
172172
const double *points_a = &data[nobj * cumsize];
173173
//Timer_start ();
174174
sep = "\0";
@@ -177,7 +177,7 @@ do_file (const char *filename, double *reference, size_t reference_size,
177177
do { \
178178
if (IF) { \
179179
fprintf (outfile, "%s" indicator_printf_format, sep, \
180-
FUN(nobj, minmax, points_a, size_a, reference, (int) reference_size, ## __VA_ARGS__)); \
180+
FUN((dimension_t) nobj, minmax, points_a, size_a, reference, reference_size, ## __VA_ARGS__)); \
181181
sep = "\t"; \
182182
} \
183183
} while (0)

c/igd.h

Lines changed: 74 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,22 @@
5858
#include "nondominated.h" // minmax_from_bool
5959

6060
static inline double
61-
gd_common (int dim, const signed char * restrict minmax,
62-
const double * restrict points_a, int size_a,
63-
const double * restrict points_r, int size_r,
64-
bool plus, bool psize, uint_fast8_t p)
61+
gd_common(dimension_t dim, const signed char * restrict minmax,
62+
const double * restrict points_a, size_t size_a,
63+
const double * restrict points_r, size_t size_r,
64+
bool plus, bool psize, uint_fast8_t p)
6565
{
6666
if (size_a == 0) return INFINITY;
6767
ASSUME(size_a > 0);
6868
ASSUME(size_r > 0);
6969
ASSUME(dim >= 2);
70-
ASSUME(dim <= 32);
7170

7271
double gd = 0;
73-
for (int a = 0; a < size_a; a++) {
72+
for (size_t a = 0; a < size_a; a++) {
7473
double min_dist = INFINITY;
75-
for (int r = 0; r < size_r; r++) {
74+
for (size_t r = 0; r < size_r; r++) {
7675
double dist = 0.0;
77-
for (int d = 0; d < dim; d++) {
76+
for (dimension_t d = 0; d < dim; d++) {
7877
if (minmax[d] == 0) continue;
7978
double a_d = points_a[a * dim + d];
8079
double r_d = points_r[r * dim + d];
@@ -84,9 +83,8 @@ gd_common (int dim, const signed char * restrict minmax,
8483
// TODO: Implement taxicab and infinity norms
8584
dist += diff * diff;
8685
}
87-
// We should calculate here the sqrt() of the Euclidean, however
88-
// that would not change which one is the minimum, so we compute it
89-
// outside the loop, which is faster.
86+
// We calculate the sqrt() of the Euclidean outside the loop, which
87+
// is faster and does not change the minimum.
9088
if (dist < min_dist) min_dist = dist;
9189
}
9290
// Here we calculate the actual Euclidean distance.
@@ -108,114 +106,112 @@ gd_common (int dim, const signed char * restrict minmax,
108106
}
109107

110108
static inline double
111-
GD_minmax (int dim, const signed char * restrict minmax,
112-
const double * restrict points_a, int size_a,
113-
const double * restrict points_r, int size_r)
109+
GD_minmax(dimension_t dim, const signed char * restrict minmax,
110+
const double * restrict points_a, size_t size_a,
111+
const double * restrict points_r, size_t size_r)
114112
{
115-
return gd_common (dim, minmax,
116-
points_a, size_a,
117-
points_r, size_r,
118-
/*plus=*/false, /*psize=*/false,
119-
/*p=*/(uint_fast8_t)1);
113+
return gd_common(dim, minmax,
114+
points_a, size_a,
115+
points_r, size_r,
116+
/*plus=*/false, /*psize=*/false, /*p=*/1);
120117
}
121118

122119
static inline double
123-
IGD_minmax (int dim, const signed char * restrict minmax,
124-
const double * restrict points_a, int size_a,
125-
const double * restrict points_r, int size_r)
120+
IGD_minmax(dimension_t dim, const signed char * restrict minmax,
121+
const double * restrict points_a, size_t size_a,
122+
const double * restrict points_r, size_t size_r)
126123
{
127-
return gd_common (dim, minmax,
128-
points_r, size_r,
129-
points_a, size_a,
130-
/*plus=*/false, /*psize=*/false,
131-
/*p=*/(uint_fast8_t)1);
124+
return gd_common(dim, minmax,
125+
points_r, size_r,
126+
points_a, size_a,
127+
/*plus=*/false, /*psize=*/false, /*p=*/1);
132128
}
133129

134130
_attr_maybe_unused static double
135-
IGD (const double * restrict data, int nobj, int npoints,
136-
const double * restrict ref, int ref_size,
137-
const bool * restrict maximise)
131+
IGD(const double * restrict data, size_t npoints, dimension_t nobj,
132+
const double * restrict ref, size_t ref_size,
133+
const bool * restrict maximise)
138134
{
139-
ASSUME(nobj > 0 && nobj <= 128);
140-
const signed char *minmax = minmax_from_bool(maximise, (dimension_t) nobj);
141-
double value = IGD_minmax (nobj, minmax, data, npoints, ref, ref_size);
135+
const signed char * minmax = minmax_from_bool(maximise, nobj);
136+
double value = IGD_minmax(nobj, minmax, data, npoints, ref, ref_size);
142137
free ((void *)minmax);
143138
return value;
144139
}
145140

146141
static inline double
147-
GD_p (int dim, const signed char * restrict minmax,
148-
const double * restrict points_a, int size_a,
149-
const double * restrict points_r, int size_r, unsigned int p)
142+
GD_p(dimension_t dim, const signed char * restrict minmax,
143+
const double * restrict points_a, size_t size_a,
144+
const double * restrict points_r, size_t size_r, unsigned int p)
150145
{
151-
return gd_common (dim, minmax,
152-
points_a, size_a,
153-
points_r, size_r,
154-
/*plus=*/false, /*psize=*/true, (uint_fast8_t)p);
146+
return gd_common(dim, minmax,
147+
points_a, size_a,
148+
points_r, size_r,
149+
/*plus=*/false, /*psize=*/true, (uint_fast8_t)p);
155150
}
156151

157152
static inline double
158-
IGD_p (int dim, const signed char * restrict minmax,
159-
const double * restrict points_a, int size_a,
160-
const double * restrict points_r, int size_r, unsigned int p)
153+
IGD_p(dimension_t dim, const signed char * restrict minmax,
154+
const double * restrict points_a, size_t size_a,
155+
const double * restrict points_r, size_t size_r, unsigned int p)
161156
{
162-
return gd_common (dim, minmax,
163-
points_r, size_r,
164-
points_a, size_a,
165-
/*plus=*/false, /*psize=*/true, (uint_fast8_t) p);
157+
return gd_common(dim, minmax,
158+
points_r, size_r,
159+
points_a, size_a,
160+
/*plus=*/false, /*psize=*/true, (uint_fast8_t) p);
166161
}
167162

168163
static inline double
169-
IGD_plus_minmax (int dim, const signed char * restrict minmax,
170-
const double * restrict points_a, int size_a,
171-
const double * restrict points_r, int size_r)
164+
IGD_plus_minmax(dimension_t dim, const signed char * restrict minmax,
165+
const double * restrict points_a, size_t size_a,
166+
const double * restrict points_r, size_t size_r)
172167
{
173-
return gd_common (dim, minmax,
174-
points_r, size_r,
175-
points_a, size_a,
176-
/*plus=*/true, /*psize=*/true, /*p=*/(uint_fast8_t)1);
168+
return gd_common(dim, minmax,
169+
points_r, size_r,
170+
points_a, size_a,
171+
/*plus=*/true, /*psize=*/true, /*p=*/1);
177172
}
178173

179174
_attr_maybe_unused static double
180-
IGD_plus (const double * restrict data, int nobj, int npoints, const double * restrict ref, int ref_size,
181-
const bool * restrict maximise)
175+
IGD_plus(const double * restrict data, size_t npoints, dimension_t nobj,
176+
const double * restrict ref, int ref_size,
177+
const bool * restrict maximise)
182178
{
183-
ASSUME(nobj > 0 && nobj <= 128);
184-
const signed char *minmax = minmax_from_bool(maximise, (dimension_t) nobj);
185-
double value = IGD_plus_minmax (nobj, minmax, data, npoints, ref, ref_size);
179+
ASSUME(nobj > 0);
180+
const signed char * minmax = minmax_from_bool(maximise, nobj);
181+
double value = IGD_plus_minmax(nobj, minmax, data, npoints, ref, ref_size);
186182
free ((void *)minmax);
187-
return(value);
183+
return value;
188184
}
189185

190186
static inline double
191-
avg_Hausdorff_dist_minmax (int dim, const signed char * restrict minmax,
192-
const double * restrict points_a, int size_a,
193-
const double * restrict points_r, int size_r,
194-
unsigned int p)
187+
avg_Hausdorff_dist_minmax(dimension_t dim, const signed char * restrict minmax,
188+
const double * restrict points_a, size_t size_a,
189+
const double * restrict points_r, size_t size_r,
190+
unsigned int p)
195191
{
196-
double gd_p = gd_common (dim, minmax,
197-
points_a, size_a,
192+
double gd_p = gd_common(dim, minmax,
193+
points_a, size_a,
194+
points_r, size_r,
195+
/*plus=*/false, /*psize=*/true, (uint_fast8_t)p);
196+
197+
double igd_p = gd_common(dim, minmax,
198198
points_r, size_r,
199+
points_a, size_a,
199200
/*plus=*/false, /*psize=*/true, (uint_fast8_t)p);
200-
201-
double igd_p = gd_common (dim, minmax,
202-
points_r, size_r,
203-
points_a, size_a,
204-
/*plus=*/false, /*psize=*/true, (uint_fast8_t)p);
205201
return MAX(gd_p, igd_p);
206202
}
207203
/* TODO: Implement p=INFINITY See [4] */
208204

209205
_attr_maybe_unused static double
210-
avg_Hausdorff_dist (const double * restrict data, int nobj, int npoints,
211-
const double * restrict ref, int ref_size,
212-
const bool * restrict maximise, unsigned int p)
206+
avg_Hausdorff_dist(const double * restrict data, size_t npoints, dimension_t nobj,
207+
const double * restrict ref, size_t ref_size,
208+
const bool * restrict maximise, unsigned int p)
213209
{
214-
ASSUME(nobj > 0 && nobj <= 128);
215-
const signed char * minmax = minmax_from_bool(maximise, (dimension_t) nobj);
216-
double value = avg_Hausdorff_dist_minmax (nobj, minmax, data, npoints, ref, ref_size, p);
210+
ASSUME(nobj > 0);
211+
const signed char * minmax = minmax_from_bool(maximise, nobj);
212+
double value = avg_Hausdorff_dist_minmax(nobj, minmax, data, npoints, ref, ref_size, p);
217213
free ((void *)minmax);
218-
return(value);
214+
return value;
219215
}
220216

221217
#endif /* IGD_H */

0 commit comments

Comments
 (0)