Mojo-Numerics-and-Algorithms-group / NuMojo

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.
Apache License 2.0
86 stars 15 forks source link

Update the `__int__` method to match the behavior of Numpy #74

Closed forFudan closed 1 month ago

forFudan commented 1 month ago

Update the __int__ method to match the behavior of Numpy.

Similar to Numpy, only 0-D arrays or length-1 arrays can be converted to scalars.

Example:

> var A = NDArray[dtype](6, random=True)
> print(int(A))
Unhandled exception caught during execution: Only 0-D arrays or length-1 arrays can be converted to scalars
mojo: error: execution exited with a non-zero result: 1
> var B = NDArray[dtype](1, 1, random=True)
> print(int(B))
14