[C++-sig] Extract from numpy uint32

John Reid j.reid at mail.cryst.bbk.ac.uk
Thu Apr 19 18:39:12 CEST 2007


Hi,

Anyone know why the following extract< unsigned >() fail?


C++:
int test_unsigned_extraction( boost::python::object i )
{
	return boost::python::extract< unsigned >( i );
}

int test_signed_extraction( boost::python::object i )
{
	return boost::python::extract< int >( i );
}

export ...



Python:
import ...

In [5]: test_unsigned_extraction( numpy.uint32( 1 ) )
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

C:\Dev\MyProjects\Bio\hmm\python\<ipython console> in <module>()

<type 'exceptions.TypeError'>: No registered converter was able to 
produce a C++ rvalue of type unsigned int from this Python object of 
type numpy.uint32

In [6]: test_unsigned_extraction( numpy.int32( 1 ) )
Out[6]: 1

In [7]: test_signed_extraction( numpy.uint32( 1 ) )
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

C:\Dev\MyProjects\Bio\hmm\python\<ipython console> in <module>()

<type 'exceptions.TypeError'>: No registered converter was able to 
produce a C++ rvalue of type int from this Python object of type 
numpy.uint32

In [8]: test_signed_extraction( numpy.int32( 1 ) )
Out[8]: 1




I guess this is something to do with the numpy int32 and uint32 types 
but I thought it must be worth asking here. I had a quick look at 
extract.hpp but didn't manage to make sense of it yet.

Thanks,
John.




More information about the Cplusplus-sig mailing list