mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-14 03:39:53 +03:00
Update numpy `ptp()` function to fix failed tests. ``` list_fitness = array([218.7586253 , 171.72733885, 233.40347259, 442.70814095, 100.83268922, 253.5196244 , 457.55837116, 170.45...32393, 264.05407671, 134.28810168, 219.71994452, 209.16796685, 225.74575111, 377.59826666, 84.63354317]) def get_index_roulette_wheel_selection(self, list_fitness: np.array): """ This method can handle min/max problem, and negative or positive fitness value. Args: list_fitness (nd.array): 1-D numpy array Returns: int: Index of selected solution """ if type(list_fitness) in [list, tuple, np.ndarray]: list_fitness = np.array(list_fitness).flatten() > if list_fitness.ptp() == 0: E AttributeError: `ptp` was removed from the ndarray class in NumPy 2.0. Use np.ptp(arr, ...) instead. mealpy/optimizer.py:625: AttributeError ```
13 lines
535 B
Diff
13 lines
535 B
Diff
Update numpy ptp function for 2.0 compatibility.
|
|
|
|
--- mealpy-3.0.1-origin/mealpy/optimizer.py
|
|
+++ mealpy-3.0.1/mealpy/optimizer.py
|
|
@@ -622,7 +622,7 @@
|
|
"""
|
|
if type(list_fitness) in [list, tuple, np.ndarray]:
|
|
list_fitness = np.array(list_fitness).flatten()
|
|
- if list_fitness.ptp() == 0:
|
|
+ if np.ptp(list_fitness) == 0:
|
|
return int(self.generator.integers(0, len(list_fitness)))
|
|
if np.any(list_fitness) < 0:
|
|
list_fitness = list_fitness - np.min(list_fitness)
|