Skip to content

Commit 8290a66

Browse files
committed
c/hvapprox.c: Simplify ASSUME conditions.
1 parent d443ecf commit 8290a66

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

c/hvapprox.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ transform_and_filter(const double * restrict data, size_t * restrict npoints_p,
2929
const bool * restrict maximise)
3030
{
3131
size_t npoints = *npoints_p;
32-
double * points = malloc(dim * npoints * sizeof(double));
32+
double * points = malloc(dim * npoints * sizeof(*points));
3333
size_t i, j;
3434
// Transform points (ref - points)
3535
for (i = 0, j = 0; i < npoints; i++) {
@@ -54,14 +54,14 @@ transform_and_filter(const double * restrict data, size_t * restrict npoints_p,
5454
}
5555

5656
_attr_optimize_finite_math // Required so that GCC will vectorize the inner loop.
57-
static inline double
57+
static double
5858
get_expected_value(const double * restrict points, size_t npoints,
5959
dimension_t dim, const double * restrict w)
6060
{
6161
ASSUME(1 <= dim && dim <= 32);
6262
ASSUME(npoints > 0);
6363
// points >= 0 && w >=0 so max_s_w cannot be < 0.
64-
double max_s_w = 0;
64+
double max_s_w = -INFINITY;
6565
for (size_t i = 0; i < npoints; i++) {
6666
const double * restrict p = points + i * dim;
6767
double min_ratio = p[0] * w[0];
@@ -71,6 +71,7 @@ get_expected_value(const double * restrict points, size_t npoints,
7171
}
7272
max_s_w = MAX(max_s_w, min_ratio);
7373
}
74+
ASSUME(max_s_w >= 0);
7475
return pow_uint(max_s_w, dim);
7576
}
7677

@@ -160,7 +161,7 @@ static const long double sphere_area_div_2_pow_d_times_d[] = {
160161
_attr_pure_func static double
161162
euclidean_norm(const double * restrict w, dimension_t dim)
162163
{
163-
ASSUME(dim >= 2 && dim <= 32);
164+
ASSUME(2 <= dim && dim <= 32);
164165
double norm = (w[0] * w[0]) + (w[1] * w[1]);
165166
for (dimension_t k = 2; k < dim; k++)
166167
norm += w[k] * w[k];
@@ -530,8 +531,6 @@ solve_inverse_int_of_power_sin(long double theta, dimension_t dim)
530531
static long double *
531532
compute_int_all(dimension_t dm1)
532533
{
533-
ASSUME(dm1 >= 1);
534-
ASSUME(dm1 < 32);
535534
long double * int_all = malloc(dm1 * sizeof(long double));
536535
dimension_t i;
537536
DEBUG2_PRINT("int_all[%u] =", (unsigned int)dm1);
@@ -560,8 +559,7 @@ static void
560559
compute_theta(long double * restrict theta, dimension_t dim,
561560
const long double * restrict int_all)
562561
{
563-
ASSUME(dim >= 2);
564-
ASSUME(dim <= 32);
562+
ASSUME(2 <= dim && dim <= 32);
565563
for (dimension_t j = 0; j < dim - 1; j++) {
566564
// We multiply here because we computed 1 / int_all[j] before.
567565
theta[j] = solve_inverse_int_of_power_sin(theta[j] * int_all[(dim - 2) - j],
@@ -573,8 +571,7 @@ static void
573571
compute_hua_wang_direction(double * restrict direction, dimension_t dim,
574572
const long double * restrict theta)
575573
{
576-
ASSUME(dim >= 2);
577-
ASSUME(dim <= 32);
574+
ASSUME(2 <= dim && dim <= 32);
578575
dimension_t k, j;
579576
direction[0] = STATIC_CAST(double, sinl(theta[0]));
580577
for (k = 1; k < dim - 1; k++)

0 commit comments

Comments
 (0)