You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on indexing and slicing by means of the __getitem__ method of structs. I noticed that when the arguments are Variant[Slice, AnyType), the syntax x[Slice(0,10,1)] works but x[0:10:1] fails.
It seems that x:y:z cannot be interpretted by compiler as Slice in square brackets.
Steps to reproduce
Here is an example that prints either an Int or the start of a Slice.
The error message is also provided.
We can see that Slice(5, 2, 1) works but foo[5:2:1] fails.
from utils import Variant
fnmain():
varfoo= Foo(List[Int](0, 1, 2, 3, 4, 5, 6, 7))
foo[5] # works
foo[Slice(5, 2, 1)] # works
foo[5:2:1] # fails!# error: invalid call to '__getitem__': index cannot be converted from initializer list to 'Variant[Int, Slice]'# foo[5:2:1]~~~^~~~~~~structFoo:
varbuf: List[Int]
fn__init__(out self, data: List[Int]):
self.buf = data
fn__getitem__(self, i: Variant[Int, Slice]):
if i.isa[Int]():
print(self.buf[i._get_ptr[Int]()[0]])
else:
vars= i._get_ptr[Slice]()[0]
print(self.buf[s.start.or_else(1)])
Error message:
error: invalid call to '__getitem__': index cannot be converted from initializer list to 'Variant[Int, Slice]' foo[5:2:1] ~~~^~~~~~~note: try resolving the overloaded function first foo[5:2:1] ^note: function declared here fn __getitem__(self, i: Variant[Int, Slice]): ^
System information
- What OS did you do install Mojo on?
MacOS 15.2
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 24.6.0 (4487cd6e)
- Provide Magic CLI version by pasting the output of `magic -V` or `magic --version`
magic 0.5.1 - (based on pixi 0.37.0)
- Optionally, provide more information with `magic info`.
Magic version: 0.5.1
System
------------
Pixi version: 0.37.0
Platform: osx-arm64
Virtual packages: __unix=0=0
: __osx=15.2=0
: __archspec=1=m2
Cache dir: /Users/ZHU/Library/Caches/rattler/cache
Auth storage: /Users/ZHU/.rattler/credentials.json
Config locations: No config files found
Global
------------
Bin dir: /Users/ZHU/.modular/bin
Environment dir: /Users/ZHU/.modular/envs
Manifest dir: /Users/ZHU/.modular/manifests/pixi-global.toml
Project
------------
Name: NuMojo
Version: 0.4.0
Manifest file: /Users/ZHU/Programs/NuMojo/mojoproject.toml
Last updated: 22-12-2024 19:54:34
Environments
------------
Environment: default
Features: default
Channels: conda-forge, https://conda.modular.com/max
Dependency count: 4
Dependencies: max, python, numpy, scipy
Target platforms: osx-arm64, linux-64
Tasks: p, package, final, test, t, f, format
The text was updated successfully, but these errors were encountered:
Bug description
I am working on indexing and slicing by means of the
__getitem__
method of structs. I noticed that when the arguments areVariant[Slice, AnyType)
, the syntaxx[Slice(0,10,1)]
works butx[0:10:1]
fails.It seems that
x:y:z
cannot be interpretted by compiler asSlice
in square brackets.Steps to reproduce
Here is an example that prints either an
Int
or the start of aSlice
.The error message is also provided.
We can see that
Slice(5, 2, 1)
works butfoo[5:2:1]
fails.Error message:
System information
The text was updated successfully, but these errors were encountered: