Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

[Feature Request] Please implement a __setitem__ method for Tensor type #865

Open
1 task done
cheburakshu opened this issue Sep 20, 2023 · 0 comments
Open
1 task done
Labels
enhancement New feature or request mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library tensor

Comments

@cheburakshu
Copy link

Review Mojo's priorities

What is your request?

Please implement a __setitem__ method for Tensor that allows implicit indexing (just like how it has been implemented for __getitem__, see t[0, 0] in the example below) instead of having to use Index(m, n).

# Tensor multiplication

from tensor import Tensor
from utils.index import Index


var t = Tensor[DType.float32](2, 2)
t[Index(0, 0)] = 0
t[Index(0, 1)] = t[0, 0]
t[Index(1, 0)] = 2
t[Index(1, 1)] = 3

var t1 = Tensor[DType.float32](2, 2)
t1[0, 0] = 0

Output:

error: Expression [7]:27:7: no matching function in call to '__setitem__': 
    t1[0, 0] = 0
    ~~^~~~~~

Expression [0]:1:1: candidate not viable: callee expects 3 arguments, but 4 were specified
from memory.unsafe import Pointer
^

Expression [0]:1:1: candidate not viable: callee expects 3 arguments, but 4 were specified
from memory.unsafe import Pointer
^

Expression [0]:1:1: candidate not viable: callee expects 2 input parameters but 1 was provided
from memory.unsafe import Pointer
^

expression failed to parse (no further compiler diagnostics)

What is your motivation for this change?

Idiomatic usage of a Tensor/matrix.

Any other details?

No response

@cheburakshu cheburakshu added enhancement New feature or request mojo Issues that are related to mojo labels Sep 20, 2023
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label Sep 20, 2023
@ematejska ematejska added the mojo-repo Tag all issues with this label label Apr 29, 2024
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 3, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 3, 2024 — with Linear
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 6, 2024 — with Linear
@JoeLoser JoeLoser added the tensor label Jun 26, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library tensor
Projects
None yet
Development

No branches or pull requests

3 participants