Skip to content

Commit e3ebddb

Browse files
committed
added support for numpy <1.8 (released 2013-10-28) which don't support
the axis argument to numpy.linalg.norm. this commit monkeypatches a custom version when necessary which uses numpy.apply_along_axis() to achieve the same effect.
1 parent 1e2da26 commit e3ebddb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/prpy/ik_ranking.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,20 @@
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
3132
import numpy
3233

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
3345

3446
def NoRanking(robot, ik_solutions):
3547
"""

0 commit comments

Comments
 (0)