Re: [C++-sig] buildin converter for long double

2012-11-05 Thread jiangzuo...@gmail.com
how about return a wrap type of long double to cheating boost/python, and
register youself converter as

  PyObject * o = PyArrayScalar_New(LongDouble);
  PyLongDoubleScalarObject * s = (PyLongDoubleScalarObject*)o;
  s->obval = value;

Don't forget to call import_array() in your model init function.

BTW, I think float128 is not useful, it's slow. and in most case, change
algorithm to avoid precision problem is another *better* approach.


  Changsheng Jiang


On Mon, Nov 5, 2012 at 6:27 PM, Holger Brandsmeier wrote:

> Dear list,
>
> the boost python buildin converter for long double:
>   BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double,
> ::PyFloat_FromDouble(x), &PyFloat_Type)
>   converter/builtin_converters.hpp
> identifies long double, which on my system is a 128bit float, with a
> 64bit float in python. I would like to identify it with numpy`s
> float128. Can you give me any hings how I would be able to do that?
>
> -Holger
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] From python converter for builtin types

2012-11-08 Thread jiangzuo...@gmail.com
I'm afraid of you can't, according to the code, it's implemented in
builtin_converters.cpp:

slot_rvalue_from_python();

Boost/Python using global registration only according type saw in C++, I
don't known is it possible to overrides these.

  Changsheng Jiang


On Thu, Nov 8, 2012 at 7:23 PM, Holger Brandsmeier wrote:

> Dear list,
>
> where does boost python define the from python converters for buildin
> types such as double / PyLong_Type?
>
> With the help of Changsheng Jiang I was able to modify
> builtin_converters.hpp and was able to change a to python converter
> for long double to produce numpy.float128. I do not find the place
> where the from python conversion is done, though.
>
> -Holger
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig