Skip to content

Commit

Permalink
Add conditional scipy
Browse files Browse the repository at this point in the history
  • Loading branch information
fmder committed Jun 15, 2019
1 parent 8375879 commit aeb346a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ branches:
only:
- master
- develop

matrix:
include:
- python: "2.7"
Expand Down Expand Up @@ -40,7 +40,7 @@ install:
NUMPY=$NUMPY"@pypy-4.0.1"
pip install nose
fi
- pip install $NUMPY
- pip install $NUMPY scipy
# command to run tests
script:
- python setup.py nosetests --verbosity=3 --with-doctest
Expand Down
8 changes: 7 additions & 1 deletion deap/benchmarks/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
except ImportError:
numpy = False

from scipy.spatial import distance
try:
from scipy.spatial import distance
except ImportError:
scipy = False

try:
# try importing the C version
Expand Down Expand Up @@ -305,8 +308,11 @@ def hypervolume(front, ref=None):
ref = numpy.max(wobj, axis=0) + 1
return hv.hypervolume(wobj, ref)


def igd(A, Z):
"""Inverse generational distance.
"""
if not scipy:
raise ImportError("idg requires scipy module")
distances = distance.cdist(A, Z)
return numpy.average(numpy.min(distances, axis=0))
2 changes: 2 additions & 0 deletions doc/api/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Selection

.. autofunction:: deap.tools.selNSGA3

.. autofunction:: deap.tools.selNSGA3WithMemory

.. autofunction:: deap.tools.uniform_reference_points

.. autofunction:: deap.tools.selSPEA2
Expand Down

0 comments on commit aeb346a

Please sign in to comment.