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] Unable to add numpy arrays #2617

Open
hylkedonker opened this issue May 11, 2024 · 1 comment
Open

[BUG] Unable to add numpy arrays #2617

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

Comments

@hylkedonker
Copy link

hylkedonker commented May 11, 2024

Bug description

The following code snippet, that adds two matrices, doesn't run:

from python import Python
 
def main():
    var np = Python.import_module("numpy")
    x = np.array([[1.0, 2.0]])
    y = np.array([[3.0, 4.0]])
    z = x + y

Running the file gives the error message:

/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: error: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:136:4: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:119:4: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:131:57: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:91:4: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:107:18: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:128:8: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo:129:22: note: call expansion failed - no concrete specializations
/home/user/workspace/mojo-tutorial/myfile.mojo:4:5: note: function instantiation failed
def main():
^
/home/user/workspace/mojo-tutorial/myfile.mojo:7:18: note: call expansion failed - no concrete specializations
y = np.array([[3.0, 4.0]])
^
/__w/modular/modular/Kernels/mojo/stdlib/python/object.mojo:212:8: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/python/object.mojo:251:44: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:30:4: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:41:33: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:60:4: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/utils/loop.mojo:67:18: note: call expansion failed - no concrete specializations
/__w/modular/modular/Kernels/mojo/stdlib/python/object.mojo:225:12: note: function instantiation failed
/__w/modular/modular/Kernels/mojo/stdlib/builtin/constrained.mojo:34:6: note: constraint failed: cannot convert nested list element to object
/home/user/.modular/pkg/packages.modular.com_mojo/bin/mojo: error: failed to run the pass manager

Observe that vectors instead of matrices do work:

x = np.array([1.0, 2.0])
y = np.array([3.0, 4.0])
z = x + y

Steps to reproduce

To reproduce, save the snippet as myfile.mojo and run mojo myfile.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
@Ultra-Code
Copy link

I am having similar issues with concatenate and hstack

# Reshape xx and yy
xx_reshaped = xx.reshape(-1, 1)
yy_reshaped = yy.reshape(-1, 1)

# Concatenate xx and yy
#var reshaped_array = np.concatenate((xx_reshaped, yy_reshaped), axis=1)
var reshaped_array = np.hstack((xx_reshaped,yy_reshaped))

Summary of error

Expression [34] wrapper:73:26:       call expansion failed - no concrete specializations
  __mojo_repl_expr_body__()
                         ^

Expression [34] wrapper:36:7:         function instantiation failed
  def __mojo_repl_expr_body__() -> None:
      ^

Expression [34]:28:44:           call expansion failed - no concrete specializations
var reshaped_array = np.hstack((xx_reshaped,yy_reshaped))
                                           ^

expression failed to parse (no further compiler diagnostics)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-python-interop mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants