Skip to content

Commit

Permalink
Merge pull request DEAP#483 from caglorithm/master
Browse files Browse the repository at this point in the history
Fix: scipy and numpy import error for nsga-3 example
  • Loading branch information
fmder authored Aug 15, 2020
2 parents 87318fc + f045049 commit 6bf1b0d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions deap/benchmarks/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from itertools import repeat
try:
import numpy
numpy_imported = True
except ImportError:
numpy = False
numpy_imported = False

try:
import scipy.spatial
scipy_imported = True
except ImportError:
scipy = False
scipy_imported = False

try:
# try importing the C version
Expand Down Expand Up @@ -79,7 +81,7 @@ class rotate(object):
Q, _ = numpy.linalg.qr(A)
"""
def __init__(self, matrix):
if not numpy:
if not numpy_imported:
raise RuntimeError("Numpy is required for using the rotation "
"decorator")
# The inverse is taken since the rotation is applied to the individual
Expand Down Expand Up @@ -312,7 +314,7 @@ def hypervolume(front, ref=None):
def igd(A, Z):
"""Inverse generational distance.
"""
if not scipy:
if not scipy_imported:
raise ImportError("idg requires scipy module")
distances = scipy.spatial.distance.cdist(A, Z)
return numpy.average(numpy.min(distances, axis=0))

0 comments on commit 6bf1b0d

Please sign in to comment.