<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi James,<br><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; "><div><span class="Apple-style-span" style="font-size: large; ">1. The first example should really throw an exception, because silent failures like this can be catastrophic:</span></div><div><font class="Apple-style-span" size="4"><br></font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font class="Apple-style-span" face="Monaco">py&gt; from numpy import random</font></div><div><font class="Apple-style-span" face="Monaco">py&gt; r = random.randint(2, size=10)</font></div><div><font class="Apple-style-span" face="Monaco">py&gt; r</font></div><div><font class="Apple-style-span" face="Monaco">array([1, 0, 1, 1, 0, 1, 0, 1, 1, 1])</font></div><div><font class="Apple-style-span" face="Monaco">py&gt; list(flex.bool(r))</font></div><div><font class="Apple-style-span" face="Monaco">[True, False, False, False, False, False, False, False, False, False]</font></div></blockquote><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">This example is clearly due to incorrect assumptions about the internal representations of numpy ndarrays.</font></div></div></blockquote><div><br></div><div>As far as I can tell, this is much worse than that as the numpy-to-flex conversion assumes the same element type in the source and target array.&nbsp;</div><div>Thus converting a numpy array of int's into a flex array of bools is illegal but this precondition is not asserted unfortunately.</div><div>Nasty indeed. I do not understand numpy well enough to propose a solution, I am afraid.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><font class="Apple-style-span" size="4">2. Although not as potentially catastrophic as the first, t</font><span class="Apple-style-span" style="font-size: large; "></span></div><div><font class="Apple-style-span" size="4"><br></font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font class="Apple-style-span" face="Monaco">py&gt; flex.int(range(10))[r[0]]</font></div><div><font class="Apple-style-span" face="Monaco">---------------------------------------------------------------------------</font></div><div><font class="Apple-style-span" face="Monaco">TypeError &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Traceback (most recent call last)</font></div><div><font class="Apple-style-span" face="Monaco">/Users/jstroud/Unison/Code/radialx/testdata/&lt;ipython-input-753-f14587f0ceeb&gt; in &lt;module&gt;()</font></div><div><font class="Apple-style-span" face="Monaco">----&gt; 1 flex.int(range(10))[r[0]]</font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div><div><font class="Apple-style-span" face="Monaco">TypeError: 'numpy.int64' object is not iterable</font></div></blockquote></div></blockquote><div><br></div><div></div><div>For flex arrays, the following __getitem__ variants are tried in this order:</div><div>1. one that takes a tuple</div><div>2. one that takes a slice</div><div>3. one that takes a single index, of type long in C++</div><div><br></div><div>The problem I think is that we are missing a registered conversion from the type numpy.int64 to the type long, and therefore all 3 variants fail.&nbsp;</div><div>Somehow the first failure is reported.</div><div><br></div><div>Best wishes,</div><div><br></div><div>Luc</div><div><br></div><br></div><div><br></div><br></body></html>