[NumPy-Tickets] [NumPy] #1604: distutils/command/config.py binary search needs floordiv '//' to work under Python3
NumPy Trac
numpy-tickets@scipy....
Sat Sep 4 04:28:04 CDT 2010
#1604: distutils/command/config.py binary search needs floordiv '//' to work under
Python3
--------------------+-------------------------------------------------------
Reporter: cb123 | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.5.0
Component: Other | Version:
Keywords: |
--------------------+-------------------------------------------------------
There is a bug in the build under Python3. The symptom is an infinite
loop of recompiling a _configtest.c file.
numpy/distutils/command/config.py uses (hi+lo) / 2 in a binary search. In
py2 '/' is "integer floor div" but in py3 is "float converting div". The
fix is just using '//' which has been available since python2.2 (or '>> 1'
instead of '/ 2'). As coded, binary search requires floordiv to converge.
Beyond the non-convergence issue, the tests themselves fail erroneously.
Using a float divide creates a float. Upon conversion to a string via
"%(size)s", that creates constants in the generated code like "<= 16.0".
Though the value of the expression is integral, as required, these being
".0" instead of round numbers cause the left operand of the inequality to
be promoted to double and '<=' to be evaluated in compile-time floating
point arithmetic. Some compilers, e.g. gcc-4.5.1, do not support FP math
for compile-time constants like an array length even if it evalutes to an
integer. Other compilers, e.g. clang-1.1, g++-4.5.1, work fine with it.
I have not looked into what relevant standards say, but using '//' makes
forward python behavior imitate the python-2.7 and early behavior and
seems a reasonable fix.
Ok. This is possibly the longest explanation I have ever had for what
amounts to a one-character patch. :)
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1604>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list