[Numpy-discussion] Adopt Mersenne Twister 64bit?
Thu Mar 14 08:25:53 CDT 2013
Robert Kern wrote:
> On Thu, Mar 14, 2013 at 11:00 AM, Neal Becker <email@example.com> wrote:
>> Robert Kern wrote:
>>> On Wed, Mar 13, 2013 at 12:16 AM, Neal Becker <firstname.lastname@example.org> wrote:
>>>> I guess I talked to you about 100 years ago about sharing state between
>>>> rng and code I have in c++ that wraps boost::random. So is there a C-api
>>>> this RandomState object I could use to call from c++? Maybe I could do
>>>> something with that.
>>> There is not one currently. Cython has provisions for sharing such
>>> low-level access to other Cython extensions, but I'm not sure how well
>>> it works for exporting data pointers and function pointers to general
>>> C/++ code. We could probably package the necessities into a struct and
>>> export a pointer to it via a PyCapsule.
>> One thing this code doesn't do: it requires construction of the wrapper class
>> passing in a RandomState object. It doesn't verify you actually gave it a
>> RandomState object. It's hard to do that. The problem as I see it is to
>> perform this check, I need the RandomStateType object, which unfortunately
>> mtrand.so does not export.
>> The only way to do it is in c++ code:
>> 1. import numpy.random
>> 2. get RandomState class
>> 3. call it to create RandomState instance
>> 4. get the ob_type pointer.
>> Pretty ugly:
>> object mod = object (handle<>
>> object rs_obj = mod.attr("RandomState");
>> object rs_inst = call<object> (rs_obj.ptr(), 0);
>> RandomStateTypeObj = rs_inst.ptr()->ob_type;
> PyObject_IsInstance() should be sufficient.
> Robert Kern
For the record, an updated version attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 7852 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130314/e658774f/attachment.bin
More information about the NumPy-Discussion