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] Tensor reshape only compiles when inlined #3430

Open
hylkedonker opened this issue Aug 29, 2024 · 0 comments
Open

[BUG] Tensor reshape only compiles when inlined #3430

hylkedonker opened this issue Aug 29, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@hylkedonker
Copy link

hylkedonker commented Aug 29, 2024

Bug description

It looks like it is only possible to reshape a tensor immediately following it's definition.

Steps to reproduce

The following works as expected, when inlining all statements one after another:

from tensor import Tensor, TensorShape

def main():
    var a = Tensor[DType.float64](2, 1.0)
    var a_expanded_shape = TensorShape(1, 2)
    var a_reshaped = a.reshape(a_expanded_shape)

If the reshape is, however, placed inside a different function than the code no longer compiles:

from tensor import Tensor, TensorShape

fn my_reshape(a: Tensor[DType.float64]):
    var a_expanded_shape = TensorShape(1, 2)
    var a_reshaped = a.reshape(a_expanded_shape)

def main():
    var a = Tensor[DType.float64](2, 1.0)
    my_reshape(a)

Which gives the compilation error:

error: invalid call to 'reshape': invalid use of mutating method on rvalue of type 'Tensor[float64]'
var a_reshaped = a.reshape(a_expanded_shape)

Am I missing something obvious?

Reading the Tensor.reshape docs, I am expecting a.reshape to return a copy. So no mutations on the function's argument a, right?

Thanks in advance,

Hylke

System information

- Ubuntu 24.04
- `mojo --version`: mojo 2024.8.2805 (fd3bceba)
- `modular -v`: modular 0.9.2 (b3079bd5)
@hylkedonker hylkedonker added bug Something isn't working mojo-repo Tag all issues with this label labels Aug 29, 2024
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-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant