Skip to content

Commit 0fe6933

Browse files
committed
Merge pull request #157 from personalrobotics/feature/older_numpy_support
Add support for numpy <1.8 which don't support norm(axis=1)
2 parents 47b8d59 + bec5da9 commit 0fe6933

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/prpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
from named_config import ConfigurationLibrary
3333
from clone import Clone, Cloned
3434
from bind import bind_subclass
35+
import compatibility

src/prpy/compatibility.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from distutils.version import LooseVersion
2+
import numpy
3+
4+
# handle older versions of numpy without norm axis argument
5+
if LooseVersion(numpy.__version__) < LooseVersion('1.8.0'):
6+
oldnorm = numpy.linalg.norm
7+
def newnorm(x, ord=None, axis=None):
8+
if axis is None:
9+
return oldnorm(x, ord=ord)
10+
elif isinstance(axis, (int,long)):
11+
return numpy.apply_along_axis(lambda x: oldnorm(x,ord=ord), axis, x)
12+
else:
13+
raise NotImplementedError('older numpy without norm axis')
14+
numpy.linalg.norm = newnorm

0 commit comments

Comments
 (0)