mojo
mojo copied to clipboard
[BUG] Broadcasting incongruent numpy arrays causes segmentation fault
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)
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)