Discussion:
[Pyublas] Datatype problem with doublify example
Andrew Wagner
2010-01-25 02:03:51 UTC
Permalink
Hello-

I'm trying out pyublas for the first time, and am very excited about
it. Thanks again for all your hard work Andreas!

I'm having trouble running the doubleify example that is on the
website, in the test subdirectory of the pyublas source.
_____________
Here's the (unmodified) code:

$ cat sample_ext.cpp
#include <pyublas/numpy.hpp>

pyublas::numpy_vector<double> doublify(pyublas::numpy_vector<double> x)
{
return 2*x;
}

BOOST_PYTHON_MODULE(sample_ext)
{
boost::python::def("doublify", doublify);
}

_______________
Here's how I'm trying to call it from python:

$ cat sample.py
import numpy
import sample_ext
import pyublas # not explicitly used--but makes converters available

vec = numpy.ones((5,), dtype=float)
print vec
print sample_ext.doublify(vec)

________________
Here's how I'm building:

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
LINK_LIBRARIES(boost_python)
INCLUDE_DIRECTORIES("/usr/include/python2.5")
INCLUDE_DIRECTORIES("/usr/local/include")
LINK_DIRECTORIES("/usr/lib/python2.5")
ADD_LIBRARY(sample_ext SHARED sample_ext.cpp)
SET_TARGET_PROPERTIES(sample_ext PROPERTIES PREFIX "")

(The build finishes cleanly)
__________________
Here's the error I get:

$ python sample.py
[ 1. 1. 1. 1. 1.]
Traceback (most recent call last):
File "sample.py", line 7, in <module>
print sample_ext.doublify(vec)
Boost.Python.ArgumentError: Python argument types in
sample_ext.doublify(numpy.ndarray)
did not match C++ signature:
doublify(pyublas::numpy_vector<double>)

__________________
Here's my ~/.aksetup-defaults.py:

BOOST_BINDINGS_INC_DIR = ['/usr/local/include/pyublas']
BOOST_INC_DIR = ['/usr/include/boost-1_35']
BOOST_LIB_DIR = ['/usr/lib']
BOOST_PYTHON_LIBNAME = ['boost_python-gcc42-mt-1_35-py25']
__________________

As far as I can tell, every thing up to that went cleanly. Any
suggestions? I'm using Debian, x86-64, and boost 1.35 that's in apt.
The pyublas was pulled from the git repository today.

Thanks!
Drew
Andrew Wagner
2010-01-25 03:01:02 UTC
Permalink
Oh, and I probably should have mentioned that the other test included
with the source runs cleanly:
_____________
$ python strided_speed.py
test_ublas_speed: 0.055871s
test_unstrided_speed: 0.448766s
test_strided_speed: 0.569441s
test_ublas_speed2: 0.051022s
test_unstrided_speed2: 0.051387s
test_strided_speed2: 0.108830s
_____________

Perhaps there is some problem with the way I'm building the sample.

Cheers,
Drew
Post by Andrew Wagner
Hello-
I'm trying out pyublas for the first time, and am very excited about
it. ?Thanks again for all your hard work Andreas!
I'm having trouble running the doubleify example that is on the
website, in the test subdirectory of the pyublas source.
_____________
$ cat sample_ext.cpp
#include <pyublas/numpy.hpp>
pyublas::numpy_vector<double> doublify(pyublas::numpy_vector<double> x)
{
?return 2*x;
}
BOOST_PYTHON_MODULE(sample_ext)
{
?boost::python::def("doublify", doublify);
}
_______________
$ cat sample.py
import numpy
import sample_ext
import pyublas # not explicitly used--but makes converters available
vec = numpy.ones((5,), dtype=float)
print vec
print sample_ext.doublify(vec)
________________
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
LINK_LIBRARIES(boost_python)
INCLUDE_DIRECTORIES("/usr/include/python2.5")
INCLUDE_DIRECTORIES("/usr/local/include")
LINK_DIRECTORIES("/usr/lib/python2.5")
ADD_LIBRARY(sample_ext SHARED sample_ext.cpp)
SET_TARGET_PROPERTIES(sample_ext PROPERTIES PREFIX "")
(The build finishes cleanly)
__________________
$ python sample.py
[ 1. ?1. ?1. ?1. ?1.]
?File "sample.py", line 7, in <module>
? ?print sample_ext.doublify(vec)
Boost.Python.ArgumentError: Python argument types in
? ?sample_ext.doublify(numpy.ndarray)
? ?doublify(pyublas::numpy_vector<double>)
__________________
BOOST_BINDINGS_INC_DIR = ['/usr/local/include/pyublas']
BOOST_INC_DIR = ['/usr/include/boost-1_35']
BOOST_LIB_DIR = ['/usr/lib']
BOOST_PYTHON_LIBNAME = ['boost_python-gcc42-mt-1_35-py25']
__________________
As far as I can tell, every thing up to that went cleanly. ?Any
suggestions? ?I'm using Debian, x86-64, and boost 1.35 that's in apt.
The pyublas was pulled from the git repository today.
Thanks!
Drew
Andreas Klöckner
2010-01-25 21:34:43 UTC
Permalink
Post by Andrew Wagner
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
LINK_LIBRARIES(boost_python)
INCLUDE_DIRECTORIES("/usr/include/python2.5")
INCLUDE_DIRECTORIES("/usr/local/include")
LINK_DIRECTORIES("/usr/lib/python2.5")
ADD_LIBRARY(sample_ext SHARED sample_ext.cpp)
SET_TARGET_PROPERTIES(sample_ext PROPERTIES PREFIX "")
I'd stronly suggest distutils for building. If that's not an option, can
you please post compiler command lines from both CMake and PyUblas's own
build?

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20100125/6d0975e7/attachment.pgp>
Loading...