serge-sans-paille / pythran

Ahead of Time compiler for numeric kernels
https://pythran.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.01k stars 193 forks source link

Problems when broadcasting with ones in the shape #2086

Closed Dapid closed 1 year ago

Dapid commented 1 year ago

This works in Python, but sends Pythran calling for Jack:

import numpy as np

# pythran export f
def f():
    data = np.zeros(5)
    data[:] = np.ones([1, 5])
    return data

This modification compiles successfully:

# pythran export f
def f():
    data = np.zeros(5)
    return data * np.ones([1, 5])

but coredumps when importing it.

It is odd because this is the Python version pythran spits out:

def f():
   return __pythran_import_numpy.array(((0.0, 0.0, 0.0, 0.0, 0.0),), __pythran_import_numpy.float64)
Dapid commented 1 year ago

The backtrace isn't very illuminating for me, but maybe it will give you a hint:

https://gist.github.com/Dapid/989e12bef7702b85b3439f2bddb3d897

serge-sans-paille commented 1 year ago

Ahhh, this Jack, he's always lurking around :-) I'll have a look. Thanks for reporting!

serge-sans-paille commented 1 year ago
# pythran export f

should be

# pythran export f()

that solves the second issue, not the first (but we should warn about this, exporting a function as a global variable is not allowed)

serge-sans-paille commented 1 year ago

Hey Dapid, can you tell me if #2088 fixes both the incorrect annotation and the original issue? Thanks!

Dapid commented 1 year ago

It does, thank you!