[pythran] Hello everyone - a first bug report

  • From: Ian Ozsvald <ian@xxxxxxxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Fri, 14 Mar 2014 17:25:44 +0000

Hi all. I have some odd behaviour in Pythran that I'd like to
understand. bool arrays should (according to numpy) be summable, but
pythran sums only to a bool dtype. Here's a working example.

----mod.py----
import numpy as np

#pythran export afn(float[])
def afn(xs):
    the_sum = np.sum((xs * xs) <= 0.5)  # numpy sum uses wrong dtype
    the_other_sum = sum((xs * xs) <= 0.5)  # python sum works correctly
    return the_sum, the_other_sum

----main.py----
import numpy as np
import mod

# Compile with:
# pythran mod.py

if __name__ == "__main__":
    xs = np.zeros(1000)
    xs.fill(0.1)
    print mod.afn(xs)
----

Result:
$ pythran mod.py
$ python main.py
(True, 1000)

np.sum produces a bool rather than a summed integer.

I think you're not promoting the dtype:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html
"dtype : dtype, optional
    The type of the returned array and of the accumulator in which the
elements are summed. By default, the dtype of a is used. An exception
is when a has an integer type with less precision than the default
platform integer. In that case, the default platform integer is used
instead."

Do you agree that np.sum should have different behaviour?

If I try adding:
    the_sum = np.sum((xs * xs) <= 0.5, dtype=np.int)
then pythran won't compile.

We hit the same thing in PyPy-numpy recently:
https://bugs.pypy.org/issue1663

Sorry for saying Hello with a bug :-)
Ian.

-- 
Ian Ozsvald (A.I. researcher)
ian@xxxxxxxxxxxxxx

http://IanOzsvald.com
http://MorConsulting.com/
http://Annotate.IO
http://SocialTiesApp.com/
http://TheScreencastingHandbook.com
http://FivePoundApp.com/
http://twitter.com/IanOzsvald
http://ShowMeDo.com

Other related posts: