Discussion:
[Pyublas] Python argument types not matching (Windows)
Julien-Charles Lévesque
2012-03-14 22:09:39 UTC
Permalink
Hi,

I have the following simple test, in which I believe everything should be
running fine :

cpp file (main.cpp):

#include <string>
#include <boost/python.hpp>
#include <pyublas/numpy.hpp>
using namespace boost::python;
using namespace pyublas;
void as_param(numpy_vector<int> input)
{
const npy_intp* dims = input.dims();
printf("dims_0: %i, dims_1: %i", dims[0], dims[1]);
return;
}
BOOST_PYTHON_MODULE(simple_mod)
{
def("as_a_parameter", as_param);
}
This cpp file is built as a dll, called simple_mod.pyd and put in the
folder simple_mod. It is then called by the following python script
(simple_example.py)

import numpy as np
import simple_mod.simple_mod as sm
import pyublas
pyublas.set_trace(True)
x = np.array(5)
pyublas.why_not(x,dtype=int)
sm.as_a_parameter(x)
python simple_example.py
File "simple_example.py", line 12, in <module>
sm.as_a_parameter(x)
Boost.Python.ArgumentError: Python argument types in
simple_mod.simple_mod.as_a_parameter(numpy.ndarray)
as_a_parameter(class pyublas::numpy_vector<int>)
I have looked at numerous examples and have even used similar code under
linux without any errors. Do you have any idea what might be going wrong?

Thanks in advance,

Julien-Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20120314/525e02bf/attachment.html>
Andreas Kloeckner
2012-03-15 02:03:21 UTC
Permalink
<#part sign=pgpmime>
Post by Julien-Charles Lévesque
I have looked at numerous examples and have even used similar code under
linux without any errors. Do you have any idea what might be going wrong?
Not sure, but if you have two different versions of Boost.Python that
get included (perhaps from PyCUDA/PyOpenCL's shipped versions?) then
this might happen, as the BPL contains a global type registry that is
initialized on module load--and if there are two or more of these
registries, things could easily go wrong.

Andreas
Julien-Charles Lévesque
2012-03-15 18:08:58 UTC
Permalink
That was it, not caused by PyCUDA or PyOpenCL but none other than myself.
My program was linking against static boost python, while pyublas was
linked against dynamic boost python, causing this problem.

Thanks for providing the intuition allowing me to find the bug!

Julien-Charles


On Wed, Mar 14, 2012 at 10:03 PM, Andreas Kloeckner <lists at informa.tiker.net
Post by Andreas Kloeckner
<#part sign=pgpmime>
On Wed, 14 Mar 2012 18:09:39 -0400, Julien-Charles L?vesque <
Post by Julien-Charles Lévesque
I have looked at numerous examples and have even used similar code under
linux without any errors. Do you have any idea what might be going wrong?
Not sure, but if you have two different versions of Boost.Python that
get included (perhaps from PyCUDA/PyOpenCL's shipped versions?) then
this might happen, as the BPL contains a global type registry that is
initialized on module load--and if there are two or more of these
registries, things could easily go wrong.
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20120315/a889fa3c/attachment.html>
Loading...