Skip to content

Commit

Permalink
Fixed sum to ensure numba type copatability (#662)
Browse files Browse the repository at this point in the history
* Fixed numba errors in age.py

* Changed sum to np.sum for numba compatability
  • Loading branch information
oliverweissl authored Nov 24, 2024
1 parent 5a2bd2a commit a76fc5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pymoo/algorithms/moo/age.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def minkowski_distances(A, B, p):
distances = np.zeros((m1, m2))
for i in range(m1):
for j in range(m2):
distances[i][j] = sum(np.abs(A[i] - B[j]) ** p) ** (1 / p)
distances[i][j] = np.sum(np.abs(A[i] - B[j]) ** p) ** (1 / p)

return distances

Expand Down Expand Up @@ -262,13 +262,13 @@ def find_corner_solutions(front):

@jit(nopython=True, fastmath=True)
def point_2_line_distance(P, A, B):
d = np.zeros(P.shape[0])
d = np.zeros(P.shape[0], dtype=numba.float64)

for i in range(P.shape[0]):
pa = P[i] - A
ba = B - A
t = np.dot(pa, ba) / np.dot(ba, ba)
d[i] = sum((pa - t * ba) ** 2)
d[i] = np.sum((pa - t * ba) ** 2)

return d

Expand Down
8 changes: 4 additions & 4 deletions pymoo/algorithms/moo/age2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self,

@jit(nopython=True, fastmath=True)
def project_on_manifold(point, p):
dist = sum(point[point > 0] ** p) ** (1/p)
dist = np.sum(point[point > 0] ** p) ** (1/p)
return np.multiply(point, 1 / dist)


Expand Down Expand Up @@ -178,16 +178,16 @@ def pairwise_distances(front, p):
if 0.95 < p < 1.05:
for row in range(0, m - 1):
for column in range(row + 1, m):
distances[row][column] = sum(np.abs(projected_front[row] - projected_front[column]) ** 2) ** 0.5
distances[row][column] = np.sum(np.abs(projected_front[row] - projected_front[column]) ** 2) ** 0.5

else:
for row in range(0, m-1):
for column in range(row+1, m):
mid_point = projected_front[row] * 0.5 + projected_front[column] * 0.5
mid_point = project_on_manifold(mid_point, p)

distances[row][column] = sum(np.abs(projected_front[row] - mid_point) ** 2) ** 0.5 + \
sum(np.abs(projected_front[column] - mid_point) ** 2) ** 0.5
distances[row][column] = np.sum(np.abs(projected_front[row] - mid_point) ** 2) ** 0.5 + \
np.sum(np.abs(projected_front[column] - mid_point) ** 2) ** 0.5

return distances + distances.T

Expand Down

0 comments on commit a76fc5e

Please sign in to comment.