Skip to content
Snippets Groups Projects
Commit 7e4439d1 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Python] compatibility with 2.7 & 3.4

parent 2478b586
No related branches found
No related tags found
No related merge requests found
language: generic language: python
python: python:
- "2.7" - "2.7"
- "3.4"
sudo: required sudo: required
dist: trusty dist: trusty
compiler: compiler:
...@@ -9,7 +10,7 @@ compiler: ...@@ -9,7 +10,7 @@ compiler:
env: env:
global: global:
- secure: "SnIBG/xLIHX3CSvUbqqsX8xTVqIqQ7fFS6HWO6KZQVBsT6yugTwYHbyhNiU531JejYJ/I3ZrDhXfYH3qFZiYxnH1sifvwV+fnTtMXpPN7qPZwIymkjcmm6gJF51e0C7VOfUbvKFv0ngwj+ul21rgZSMuoEvxPK0WxtE3/ZSfn9c=" - secure: "SnIBG/xLIHX3CSvUbqqsX8xTVqIqQ7fFS6HWO6KZQVBsT6yugTwYHbyhNiU531JejYJ/I3ZrDhXfYH3qFZiYxnH1sifvwV+fnTtMXpPN7qPZwIymkjcmm6gJF51e0C7VOfUbvKFv0ngwj+ul21rgZSMuoEvxPK0WxtE3/ZSfn9c="
- APT_DEPENDENCIES="doxygen libeigen3-dev " - APT_DEPENDENCIES="doxygen libeigen3-dev libboost-test-dev libboost-python-dev libeigen3-dev"
- DEBSIGN_KEYID=5AE5CD75 - DEBSIGN_KEYID=5AE5CD75
- CC=gcc - CC=gcc
- DO_COVERAGE_ON_BRANCH="master;release" - DO_COVERAGE_ON_BRANCH="master;release"
...@@ -19,24 +20,18 @@ env: ...@@ -19,24 +20,18 @@ env:
- BUILDTYPE=Release - BUILDTYPE=Release
- BUILDTYPE=Debug - BUILDTYPE=Debug
notifications: notifications:
email: email:
- pinocchio@laas.fr - pinocchio-build@laas.fr
branches: branches:
only: only:
- master - master
- debian - debian
- devel - devel
matrix: before_install: ./.travis/run before_install
allow_failures: install: pip install coveralls numpy
- compiler:
before_install: ./travis_custom/custom_before_install
install:
- pip install --user coveralls
- pip install --user numpy
script: script:
- export CMAKE_ADDITIONAL_OPTIONS="-DCMAKE_BUILD_TYPE=${BUILDTYPE}" - export CMAKE_ADDITIONAL_OPTIONS="-DCMAKE_BUILD_TYPE=${BUILDTYPE}"
- sudo free -m -t - sudo free -m -t
- ./.travis/run ../travis_custom/custom_build - ./.travis/run ../travis_custom/custom_build
after_failure: ./.travis/run after_failure after_failure: ./.travis/run after_failure
after_success: after_success: ./.travis/run after_success
- ./.travis/run after_success
#!/bin/bash
set -e
# Setup environment variables.
export APT_DEPENDENCIES="doxygen libboost-test-dev libboost-python-dev libeigen3-dev python2.7-dev python-numpy"
# When this script is called the current directory is ./custom_travis
. ./.travis/run ../.travis/before_install
from __future__ import print_function
import numpy as np import numpy as np
import matrix as eigenpy import matrix as eigenpy
verbose = False verbose = False
if verbose: print "===> From MatrixXd to Py" if verbose: print("===> From MatrixXd to Py")
M = eigenpy.naturals(3,3,verbose) M = eigenpy.naturals(3,3,verbose)
Mcheck = np.reshape(np.matrix(range(9),np.double),[3,3]) Mcheck = np.reshape(np.matrix(range(9),np.double),[3,3])
assert np.array_equal(Mcheck,M) assert np.array_equal(Mcheck,M)
if verbose: print "===> From Matrix3d to Py" if verbose: print("===> From Matrix3d to Py")
M33= eigenpy.naturals33(verbose) M33= eigenpy.naturals33(verbose)
assert np.array_equal(Mcheck,M33) assert np.array_equal(Mcheck,M33)
if verbose: print "===> From VectorXd to Py" if verbose: print("===> From VectorXd to Py")
v = eigenpy.naturalsX(3,verbose) v = eigenpy.naturalsX(3,verbose)
vcheck = np.matrix([range(3),],np.double).T vcheck = np.matrix([range(3),],np.double).T
assert np.array_equal(vcheck ,v) assert np.array_equal(vcheck ,v)
if verbose: print "===> From Py to Eigen::MatrixXd" if verbose: print("===> From Py to Eigen::MatrixXd")
if verbose: print "===> From Py to Eigen::MatrixXd" if verbose: print("===> From Py to Eigen::MatrixXd")
if verbose: print "===> From Py to Eigen::MatrixXd" if verbose: print("===> From Py to Eigen::MatrixXd")
Mref = np.reshape(np.matrix(range(64),np.double),[8,8]) Mref = np.reshape(np.matrix(range(64),np.double),[8,8])
if verbose: print "===> Matrix 8x8" if verbose: print("===> Matrix 8x8")
M = Mref M = Mref
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block 0:3x0:3" if verbose: print("===> Block 0:3x0:3")
M = Mref[0:3,0:3] M = Mref[0:3,0:3]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block 1:3x1:3" if verbose: print("===> Block 1:3x1:3")
M = Mref[1:3,1:3] M = Mref[1:3,1:3]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block 1:5:2x1:5:2" if verbose: print("===> Block 1:5:2x1:5:2")
M = Mref[1:5:2,1:5:2] M = Mref[1:5:2,1:5:2]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block 1:8:3x1:5" if verbose: print("===> Block 1:8:3x1:5")
M = Mref[1:8:3,1:5] M = Mref[1:8:3,1:5]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block transpose 1:8:3x1:6:2" if verbose: print("===> Block transpose 1:8:3x1:6:2")
M = Mref[1:8:3,0:6:2].T M = Mref[1:8:3,0:6:2].T
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block Vector 1x0:6:2" if verbose: print("===> Block Vector 1x0:6:2")
M = Mref[1:2,0:6:2] M = Mref[1:2,0:6:2]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block Vector 1x0:6:2 tanspose" if verbose: print("===> Block Vector 1x0:6:2 tanspose")
M = Mref[1:2,0:6:2].T M = Mref[1:2,0:6:2].T
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block Vector 0:6:2x1" if verbose: print("===> Block Vector 0:6:2x1")
M = Mref[0:6:2,1:2] M = Mref[0:6:2,1:2]
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> Block Vector 0:6:2x1 tanspose" if verbose: print("===> Block Vector 0:6:2x1 tanspose")
M = Mref[0:6:2,1:2].T M = Mref[0:6:2,1:2].T
assert( np.array_equal(M,eigenpy.reflex(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
if verbose: print "===> From Py to Eigen::VectorXd" if verbose: print("===> From Py to Eigen::VectorXd")
if verbose: print "===> From Py to Eigen::VectorXd" if verbose: print("===> From Py to Eigen::VectorXd")
if verbose: print "===> From Py to Eigen::VectorXd" if verbose: print("===> From Py to Eigen::VectorXd")
if verbose: print "===> Block Vector 0:6:2x1 1 dim" if verbose: print("===> Block Vector 0:6:2x1 1 dim")
M = Mref[0:6:2,1].T M = Mref[0:6:2,1].T
assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) ); assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
if verbose: print "===> Block Vector 0:6:2x1" if verbose: print("===> Block Vector 0:6:2x1")
M = Mref[0:6:2,1:2] M = Mref[0:6:2,1:2]
assert( np.array_equal(M,eigenpy.reflexV(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflexV(M,verbose)) );
if verbose: print "===> Block Vector 0:6:2x1 transpose" if verbose: print("===> Block Vector 0:6:2x1 transpose")
M = Mref[0:6:2,1:2].T M = Mref[0:6:2,1:2].T
assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) ); assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
if verbose: print "===> From Py to Eigen::Matrix3d" if verbose: print("===> From Py to Eigen::Matrix3d")
if verbose: print "===> From Py to Eigen::Matrix3d" if verbose: print("===> From Py to Eigen::Matrix3d")
if verbose: print "===> From Py to Eigen::Matrix3d" if verbose: print("===> From Py to Eigen::Matrix3d")
if verbose: print "===> Block Vector 0:3x0:6:2 " if verbose: print("===> Block Vector 0:3x0:6:2 ")
M = Mref[0:3,0:6:2] M = Mref[0:3,0:6:2]
assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
if verbose: print "===> Block Vector 0:3x0:6:2 T" if verbose: print("===> Block Vector 0:3x0:6:2 T")
M = Mref[0:3,0:6].T M = Mref[0:3,0:6].T
try: try:
assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
except eigenpy.Exception, e: except eigenpy.Exception as e:
if verbose: print "As expected, got the following /ROW/ error:", e.message if verbose: print("As expected, got the following /ROW/ error:", e.message)
if verbose: print "===> From Py to Eigen::Vector3d" if verbose: print("===> From Py to Eigen::Vector3d")
if verbose: print "===> From Py to Eigen::Vector3d" if verbose: print("===> From Py to Eigen::Vector3d")
if verbose: print "===> From Py to Eigen::Vector3d" if verbose: print("===> From Py to Eigen::Vector3d")
M = Mref[0:3,1:2] M = Mref[0:3,1:2]
assert( np.array_equal(M,eigenpy.reflex3(M,verbose)) ); assert( np.array_equal(M,eigenpy.reflex3(M,verbose)) );
......
from __future__ import print_function
from geometry import * from geometry import *
import numpy as np import numpy as np
from numpy import cos,sin from numpy import cos,sin
...@@ -33,13 +35,13 @@ assert(isapprox(q.coeffs(),qR.coeffs())) ...@@ -33,13 +35,13 @@ assert(isapprox(q.coeffs(),qR.coeffs()))
assert(isapprox(qR[3],1./np.sqrt(30))) assert(isapprox(qR[3],1./np.sqrt(30)))
try: try:
qR[5] qR[5]
print "Error, this message should not appear." print("Error, this message should not appear.")
except Exception,e: except Exception as e:
if verbose: print "As expected, catched exception: ",e.message if verbose: print("As expected, catched exception: ",e.message)
# --- Angle Vector ------------------------------------------------ # --- Angle Vector ------------------------------------------------
r = AngleAxis(.1,np.array([1,0,0],np.double)) r = AngleAxis(.1,np.array([1,0,0],np.double))
if verbose: print "Rx(.1) = \n\n",r.matrix(),"\n" if verbose: print("Rx(.1) = \n\n",r.matrix(),"\n")
assert( isapprox(r.matrix()[2,2],cos(r.angle))) assert( isapprox(r.matrix()[2,2],cos(r.angle)))
assert( isapprox(r.axis,np.matrix("1;0;0")) ) assert( isapprox(r.axis,np.matrix("1;0;0")) )
assert( isapprox(r.angle,0.1) ) assert( isapprox(r.angle,0.1) )
...@@ -66,6 +68,6 @@ res = testInQuaternion_fx(q) ...@@ -66,6 +68,6 @@ res = testInQuaternion_fx(q)
assert(q.norm() == res) assert(q.norm() == res)
try: try:
testInQuaternion(q) testInQuaternion(q)
print "Error, this message should not appear." print("Error, this message should not appear.")
except: except:
if verbose: print "As expected, catch a Boost::python::ArgError exception." if verbose: print("As expected, catch a Boost::python::ArgError exception.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment