Skip to content

Commit 40cd54e

Browse files
committed
moved numpy compatibility stuff to a new file
1 parent e3ebddb commit 40cd54e

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
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

src/prpy/ik_ranking.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,8 @@
2828
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929
# POSSIBILITY OF SUCH DAMAGE.
3030

31-
from distutils.version import LooseVersion
3231
import numpy
3332

34-
# handle older versions of numpy without norm axis argument
35-
if LooseVersion(numpy.__version__) < LooseVersion('1.8.0'):
36-
oldnorm = numpy.linalg.norm
37-
def newnorm(x, ord=None, axis=None):
38-
if axis is None:
39-
return oldnorm(x, ord=ord)
40-
elif isinstance(axis, (int,long)):
41-
return numpy.apply_along_axis(oldnorm, axis, x)
42-
else:
43-
raise NotImplementedError('older numpy without norm axis')
44-
numpy.linalg.norm = newnorm
45-
4633
def NoRanking(robot, ik_solutions):
4734
"""
4835
Return IK solutions with an arbitrary ranking.

0 commit comments

Comments
 (0)