<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 5 Apr 2013, at 19:38, James Stroud wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hu Luc,<div><br></div><div><div>On Apr 5, 2013, at 6:46 AM, Luc Bourhis wrote:</div><blockquote type="cite"><div>However, we haven't address the important question: what behaviour do we really want?<br>(i) the numpy array and the flex array must have the same element type, and an exception is thrown if this precondition is violated;<br>(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.</div></blockquote></div><div><br></div><div>My understanding of the "python way" would be that the desired behavior is (ii). [...]</div></div></blockquote><div><br></div><div>Good demonstration: I fully agree with you. We will try to implement (ii) then.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Taking the "pythonic" approach only requires</div><div><br></div><div>&nbsp; &nbsp; <a href="http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_CastToType">http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_CastToType</a></div><div><br></div><div>For each of the element types that could comprise flex arrays, one only needs to write one PyArray_Descr</div><div><br></div><div>&nbsp; &nbsp;<a href="http://docs.scipy.org/doc/numpy/reference/c-api.types-and-structures.html#PyArray_Descr">http://docs.scipy.org/doc/numpy/reference/c-api.types-and-structures.html#PyArray_Descr</a></div><div><br></div><div>which becomes the second argument for PyArray_CastToType.</div></div></blockquote><br></div><div>Thanks again to look into this for me.&nbsp;</div><div><br></div><div>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.</div><div><br></div><div>But thanks for your researches, that has helped a long way.&nbsp;</div><div><br></div><div>Best wishes,</div><div><br></div><div>Luc</div><div><br></div></body></html>