Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Broadcasting incongruent numpy arrays causes segmentation fault #2618

Open
hylkedonker opened this issue May 11, 2024 · 1 comment
Open
Labels
bug Something isn't working help wanted Extra attention is needed mojo-python-interop mojo-repo Tag all issues with this label

Comments

@hylkedonker
Copy link

hylkedonker commented May 11, 2024

Bug description

In Numpy, when attempting to perform operations on pairs of arrays of different shapes, Numpy tries to broadcast the arrays to make the shapes compatible. When this is not successful, an exception is raised in Python.
In mojo, no exception is raised and mojo continues execution with a `` pointer.

Steps to reproduce

Here is a minimal example:

from python import Python
 
def main():
    var np = Python.import_module("numpy")
    x = np.array([1.0, 2.0, 3.0]).reshape(-1, 1)
    y = np.array([3.0, 4.0]).reshape(-1, 1)
    z = x + y # No exception; z is .
    print(z.shape) # This statement causes the segmentation fault.

Which segfaults with the following message:

[35825:35825:20240511,144639.183223:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.183636:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.183917:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.184069:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.184222:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.184442:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.184665:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.184837:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185010:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185186:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185366:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185572:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185718:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.185867:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.186017:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.186171:ERROR elf_dynamic_array_reader.h:64] tag not found
[35825:35825:20240511,144639.186319:ERROR elf_dynamic_array_reader.h:64] tag not found
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: /home/user/.modular/pkg/packages.modular.com_mojo/bin/mojo /home/user/workspace/mojo-tutorial/crash_add.mojo
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0 mojo 0x00005f4c79e43407
1 mojo 0x00005f4c79e4125e
2 mojo 0x00005f4c79e43a9f
3 libc.so.6 0x0000741bc8a42990
4 libpython3.11.so.1.0 0x0000741bc09ce47d PyObject_GetAttrString + 13
5 libpython3.11.so.1.0 0x0000741b740068d8 PyObject_GetAttrString + 18446744072424227944
mojo crashed!
Please file a bug report.
[1] 35823 segmentation fault (core dumped) '/home/user/.modular/pkg/packages.modular.com_mojo/bin/mojo'

System information

OS: Ubuntu 23.10
`mojo -v`: mojo 24.3.0 (9882e19d)
`modular -v`: modular 0.7.4 (df7a9e8b)
@hylkedonker hylkedonker added bug Something isn't working mojo-repo Tag all issues with this label labels May 11, 2024
Copy link
Collaborator

We should dig into why the x + y expression is not raising as it does in Python:

ValueError: operands could not be broadcast together with shapes (3,1) (2,1)

@JoeLoser JoeLoser added the help wanted Extra attention is needed label Jul 24, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed mojo-python-interop mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants