Skip to content

Commit

Permalink
preventing writing np.float in create for regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikohansen committed Nov 28, 2024
1 parent 6650cd0 commit 0cd5478
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/regression-test/create/create_suite_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def solution_array(dimension, number=10):
return (0.1 * (np.random.randn(number) / (np.abs(np.random.randn(number)) + 1e-6)) *
np.random.randn(number, dimension).T).T

def _to_float_tuple(x):
return tuple(float(xi) for xi in x)

def generate_test_data_for_suite(suite_name, filename, solution_array=solution_array):
"""write regression test data into file.
Expand All @@ -48,10 +50,10 @@ def generate_test_data_for_suite(suite_name, filename, solution_array=solution_a
for i, f in enumerate(suite):
for j, x in enumerate(solution_array(f.dimension)):
fval = f(x)
res = (fval if f.number_of_objectives == 1 else list(fval),
list(f.constraint(x) if f.number_of_constraints > 0 else []))
res = (float(fval) if f.number_of_objectives == 1 else _to_float_tuple(fval),
_to_float_tuple(f.constraint(x)) if f.number_of_constraints > 0 else [])
if is_finite(res) and is_smaller_than(res, 1e22):
xfc_dict[i, j, tuple(x)] = res # tuple, because keys must be immutable
xfc_dict[i, j, _to_float_tuple(x)] = res # tuple, because keys must be immutable
else:
print("rejected: ", f.name, i, x, res)

Expand Down

0 comments on commit 0cd5478

Please sign in to comment.