Commit b22cad65 authored by Nicolas Mansard's avatar Nicolas Mansard Committed by nmansard
Browse files

First complete version.

parent 023a1502
...@@ -19,22 +19,25 @@ IF(Boost_FOUND) ...@@ -19,22 +19,25 @@ IF(Boost_FOUND)
SET(Boost_USE_STATIC_RUNTIME OFF) SET(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost 1.45.0 COMPONENTS python) FIND_PACKAGE(Boost 1.45.0 COMPONENTS python)
ADD_LIBRARY(simple SHARED src/simple.cpp) ADD_LIBRARY(eigenpy SHARED unittest/libeigenpy.cpp)
TARGET_LINK_LIBRARIES(eigenpy ${Boost_LIBRARIES})
ADD_LIBRARY(simple SHARED unittest/alpha/simple.cpp)
TARGET_LINK_LIBRARIES(simple ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(simple ${Boost_LIBRARIES})
ADD_LIBRARY(mystring SHARED src/mystring.cpp) ADD_LIBRARY(mystring SHARED unittest/alpha/mystring.cpp)
TARGET_LINK_LIBRARIES(mystring ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(mystring ${Boost_LIBRARIES})
ADD_LIBRARY(bnpy SHARED src/bnpy.cpp) ADD_LIBRARY(bnpy SHARED unittest/alpha/bnpy.cpp)
TARGET_LINK_LIBRARIES(bnpy ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(bnpy ${Boost_LIBRARIES})
ADD_LIBRARY(eigen SHARED src/eigen.cpp) ADD_LIBRARY(eigen SHARED unittest/alpha/eigen.cpp)
TARGET_LINK_LIBRARIES(eigen ${Boost_LIBRARIES} libboost_numpy.so) TARGET_LINK_LIBRARIES(eigen ${Boost_LIBRARIES} libboost_numpy.so)
ADD_LIBRARY(eigenc SHARED src/eigenc.cpp) ADD_LIBRARY(eigenc SHARED unittest/alpha/eigenc.cpp)
TARGET_LINK_LIBRARIES(eigenc ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(eigenc ${Boost_LIBRARIES})
ADD_LIBRARY(eigentemplate SHARED src/eigentemplate.cpp) ADD_LIBRARY(eigentemplate SHARED unittest/alpha/eigentemplate.cpp)
TARGET_LINK_LIBRARIES(eigentemplate ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(eigentemplate ${Boost_LIBRARIES})
ELSEIF(NOT Boost_FOUND) ELSEIF(NOT Boost_FOUND)
......
#!/usr/bin/python
import numpy as np
'''
import libsimple
print libsimple.char()
print libsimple.str()
try:
a = libsimple.eigenvec()
print a
except:
print "Error when calling simple eigenvec"
import libmystring
print libmystring.hello()
print libmystring.size("toto+5")
import libeigen
print libeigen.test()
a = np.matrix([11,2,3,4,5]).T
b = np.array([11,2,3,4,5])
#b = np.array([[15,],[1,],[1,],[1,],[1,],])
#b = np.array([ [[10,2],[3,4]],[[10,2],[3,4]] ])
print "matrix ===> "
libeigen.test2(a)
print "array ===> "
libeigen.test2(b)
'''
import libeigenpy
# print "===> From C++ to Py"
# print libeigentemplate.test()
# print "===> From Vec C++ to Py"
# print libeigentemplate.testVec()
# print "===> From Py to C++"
a = np.random.random([5,5])
for i in range(5):
for j in range(5):
a[i,j] = i*5+j
#a = np.random.random([
print a
libeigentemplate.test2(a)
# print "===> From Py::slice to C++"
# b=a[1:5,1:3]
# print b
# libeigentemplate.test2(b)
# print "===> From Py::transpose to C++"
# b=a[1:5,1:3].T
# print b
# libeigentemplate.test2(b)
print "===> From py::vec to C++ Vec"
v = np.array([range(5),],np.float64).T
print v
libeigentemplate.test2Vec(v)
v = np.array(range(5),np.float64)
print "v = ", v
libeigentemplate.test2Vec(v)
v = np.array(range(10),np.float64)
v2 = v[0:10:5]
print "v2 = ", v2
libeigentemplate.test2Vec(v2)
'''
import libbnpy
a=libbnpy.array()
print a.__class__
b=libbnpy.matrix()
print b.__class__
'''
#!/usr/bin/python #!/usr/bin/python
import numpy as np import numpy as np
import libeigenpy
''' print "===> From MatrixXd to Py"
import libsimple print libeigenpy.test()
print libsimple.char() print "===> From VectorXd to Py"
print libsimple.str() print libeigenpy.testVec()
try:
a = libsimple.eigenvec()
print a
except:
print "Error when calling simple eigenvec"
import libmystring print "===> From Py to C++"
print libmystring.hello()
print libmystring.size("toto+5")
import libeigen
print libeigen.test()
a = np.matrix([11,2,3,4,5]).T
b = np.array([11,2,3,4,5])
#b = np.array([[15,],[1,],[1,],[1,],[1,],])
#b = np.array([ [[10,2],[3,4]],[[10,2],[3,4]] ])
print "matrix ===> "
libeigen.test2(a)
print "array ===> "
libeigen.test2(b)
'''
import libeigentemplate
# print "===> From C++ to Py"
# print libeigentemplate.test()
# print "===> From Vec C++ to Py"
# print libeigentemplate.testVec()
# print "===> From Py to C++"
a = np.random.random([5,5]) a = np.random.random([5,5])
for i in range(5): for i in range(5):
for j in range(5): for j in range(5):
a[i,j] = i*5+j a[i,j] = i*5+j
#a = np.random.random([
print a print a
libeigentemplate.test2(a) libeigenpy.test2(a)
# print "===> From Py::slice to C++"
# b=a[1:5,1:3]
# print b
# libeigentemplate.test2(b)
# print "===> From Py::transpose to C++" print "===> From Py::slice to C++"
# b=a[1:5,1:3].T b=a[1:5,1:3]
# print b print b
# libeigentemplate.test2(b) libeigenpy.test2(b)
print "===> From Py::transpose to C++"
b=a[1:5,1:3].T
libeigenpy.test2(b)
print "===> From py::vec to C++ Vec" print "===> From py::vec to C++ Vec"
v = np.array([range(5),],np.float64).T v = np.array([range(5),],np.float64).T
print v libeigenpy.test2Vec(v)
libeigentemplate.test2Vec(v)
print "===> From one-dim py::vec to C++ Vec"
v = np.array(range(5),np.float64) v = np.array(range(5),np.float64)
print "v = ", v libeigenpy.test2Vec(v)
libeigentemplate.test2Vec(v)
print "===> From one-dim sliced py::vec to C++ Vec"
v = np.array(range(10),np.float64) v = np.array(range(10),np.float64)
v2 = v[0:10:5] v2 = v[0:10:3]
print "v2 = ", v2 libeigenpy.test2Vec(v2)
libeigentemplate.test2Vec(v2)
'''
import libbnpy
a=libbnpy.array()
print a.__class__
b=libbnpy.matrix()
print b.__class__
'''
#include "../src/eigenpy.hpp"
Eigen::MatrixXd test()
{
Eigen::MatrixXd mat = Eigen::MatrixXd::Random(3,6);
std::cout << "EigenMAt = " << mat << std::endl;
return mat;
}
Eigen::VectorXd testVec()
{
Eigen::VectorXd mat = Eigen::VectorXd::Random(6);
std::cout << "EigenVec = " << mat << std::endl;
return mat;
}
void test2( Eigen::MatrixXd mat )
{
std::cout << "Test2 mat = " << mat << std::endl;
}
void test2Vec( Eigen::VectorXd v )
{
std::cout << "Test2 vec = " << v << std::endl;
}
BOOST_PYTHON_MODULE(libeigenpy)
{
namespace bp = boost::python;
eigenpy::enableEigenPy();
bp::def("test", test);
bp::def("testVec", testVec);
bp::def("test2", test2);
bp::def("test2Vec", test2Vec);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment