[pythran] Re: Hello everyone - a first bug report

  • From: Pierrick Brunet <pierrick.brunet@xxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx, ian@xxxxxxxxxxxxxx
  • Date: Fri, 14 Mar 2014 19:09:11 +0100 (CET)

Hi Ian,

Thanks for the bug report. I think it is not really long to solve it but Serge 
has finish a really big job with numpy array (performance improvement) so we 
will review it before as it change the same part of the code.
If you really need it. Just ask and I will create a temporary branch for it.

Have a nice week end,
Pierrick

----- Mail original -----
> De: "Ian Ozsvald" <ian@xxxxxxxxxxxxxx>
> À: pythran@xxxxxxxxxxxxx
> Envoyé: Vendredi 14 Mars 2014 18:25:44
> Objet: [pythran] Hello everyone - a first bug report
> 
> 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: