Skip to content

Commit a53c8e1

Browse files
committed
python: Fixes for Numpy 2.
1 parent 284e8ea commit a53c8e1

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

python/src/moocore/_moocore.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -547,27 +547,7 @@ def pareto_rank(data, /, *, maximise=False):
547547
4, 9, 4, 3, 11, 2, 3, 13, 2, 3, 10, 5, 3, 6, 3],
548548
dtype=int32)
549549
550-
551-
We can now sort the points according to their Pareto rank:
552-
553-
>>> x[ranks.argsort(), :] # doctest: +ELLIPSIS
554-
array([[0.20816431, 4.62275469],
555-
[1.54506255, 0.38303122],
556-
[0.22997367, 1.11772205],
557-
[0.17470556, 8.89066343],
558-
[0.58799475, 0.73891181],
559-
[8.57911868, 0.35169752],
560-
[0.2901393 , 8.32259412],
561-
[6.78498493, 0.56380796],
562-
...
563-
[9.73057875, 6.15847562],
564-
[8.17231096, 9.76977853],
565-
[9.69531949, 7.22212523],
566-
[9.30608102, 7.69433246],
567-
[8.75833731, 8.98886885]])
568-
569-
570-
Or split the original set into a list of nondominated sets ordered by Pareto rank:
550+
We can now split the original set into a list of nondominated sets ordered by Pareto rank:
571551
572552
>>> paretos = [x.compress((g == ranks), axis=0) for g in np.unique(ranks)]
573553
>>> len(paretos)
@@ -912,7 +892,7 @@ def vorobT(data, /, reference):
912892
diff = prev_hyp - tmp
913893
prev_hyp = tmp
914894

915-
return dict(threshold=c, VE=eaf_res, avg_hyp=avg_hyp)
895+
return dict(threshold=c, VE=eaf_res, avg_hyp=float(avg_hyp))
916896

917897

918898
def vorobDev(x, /, reference, *, VE=None) -> float:
@@ -976,16 +956,13 @@ def vorobDev(x, /, reference, *, VE=None) -> float:
976956
).mean()
977957
VD = (
978958
np.fromiter(
979-
(
980-
hypervolume(np.row_stack((g, VE)), ref=reference)
981-
for g in x_split
982-
),
959+
(hypervolume(np.vstack((g, VE)), ref=reference) for g in x_split),
983960
dtype=float,
984961
count=len(x_split),
985962
).mean()
986963
* 2.0
987964
)
988-
return VD - H1 - H2
965+
return float(VD - H1 - H2)
989966

990967

991968
def eafdiff(x, y, /, *, intervals=None, maximise=False, rectangles=False):
@@ -1093,7 +1070,7 @@ def eafdiff(x, y, /, *, intervals=None, maximise=False, rectangles=False):
10931070
cumsizes = np.concatenate((cumsizes_x, cumsizes_x[-1] + cumsizes_y))
10941071
nsets = len(cumsizes)
10951072

1096-
data = np.row_stack((x[:, :-1], y[:, :-1]))
1073+
data = np.vstack((x[:, :-1], y[:, :-1]))
10971074
if maximise.any():
10981075
data[:, maximise] = -data[:, maximise]
10991076

python/tox.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
requires =
33
tox>=4.2
44
env_list =
5+
numpy-v2
56
py{311, 310, 39, 38}
67

78
[testenv]
89
description = Run unit tests
910
package = wheel
1011
wheel_build_env = .pkg
1112
deps =
13+
numpy<2
14+
pytest>=7
15+
cov: coverage[toml]
16+
cov: gcovr
17+
commands =
18+
pytest --doctest-modules --doctest-continue-on-failure --import-mode=importlib {envsitepackagesdir}/moocore tests
19+
20+
[testenv:numpy-v2]
21+
description = Run unit tests with Numpy v2
22+
base_python = py310
23+
package = wheel
24+
wheel_build_env = .pkg
25+
deps =
26+
numpy>=2
1227
pytest>=7
1328
cov: coverage[toml]
1429
cov: gcovr

0 commit comments

Comments
 (0)