[cctbxbb] flex and numpy caveats
luc_j_bourhis at mac.com
Fri Apr 5 23:38:37 PDT 2013
On 5 Apr 2013, at 19:38, James Stroud wrote:
> Hu Luc,
> On Apr 5, 2013, at 6:46 AM, Luc Bourhis wrote:
>> However, we haven't address the important question: what behaviour do we really want?
>> (i) the numpy array and the flex array must have the same element type, and an exception is thrown if this precondition is violated;
>> (ii) we use a fast copy of the numpy array to the flex array if the element types are the same; otherwise we fall back to a slower conversion.
> My understanding of the "python way" would be that the desired behavior is (ii). [...]
Good demonstration: I fully agree with you. We will try to implement (ii) then.
> Taking the "pythonic" approach only requires
> For each of the element types that could comprise flex arrays, one only needs to write one PyArray_Descr
> which becomes the second argument for PyArray_CastToType.
Thanks again to look into this for me.
Unfortunately the real difficulty is that a flex array does not have a descriptor as a numpy array does. In some sense the latter does not know the type of its elements: only the C++ compiler does. Thus some template trickery is still needed to map the each numpy array element type to the right flex element type.
But thanks for your researches, that has helped a long way.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cctbxbb