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

tensor$repeat(c(...)) not working? #1288

Open
AlexLeeR opened this issue Mar 3, 2025 · 1 comment
Open

tensor$repeat(c(...)) not working? #1288

AlexLeeR opened this issue Mar 3, 2025 · 1 comment

Comments

@AlexLeeR
Copy link

AlexLeeR commented Mar 3, 2025

Hi there,

I would like to repeat tensor along the first dimension 4 times.

First I create the tensor
x <- torch_tensor(c(1, 2, 3))

Then I add a dimension at position 1:
x2 = x$unsqueeze(1)

Here I'm attempting to repeat the first dimension four times and it throws an error:

>repeated_matrix <- x$repeat(c(2, 1))
Error: unexpected 'repeat' in "repeated_matrix <- x$repeat"

I also tried different variations:

> repeated_matrix <- x$repeat(list(2, 1))
Error: unexpected 'repeat' in "repeated_matrix <- x$repeat"
> repeated_matrix <- x$repeat(dim=c(2, 1))
Error: unexpected 'repeat' in "repeated_matrix <- x$repeat"
> repeated_matrix <- x$repeat(dims=c(2, 1))
Error: unexpected 'repeat' in "repeated_matrix <- x$repeat"

All of which are not working!

Thank you

@rdinnager
Copy link
Collaborator

Ah yes, I came across this bug a while back too. I figured out a workaround but unfortunately I was busy at the time and forgot to post an issue as I had intended. Here is the workaround:

x <- torch_tensor(c(1, 2, 3))
x2 = x$unsqueeze(1)
repeated_matrix <- x$`repeat`(c(2, 1))
repeated_matrix
#> torch_tensor
#>  1  2  3
#>  1  2  3
#> [ CPUFloatType{2,3} ]

Posting it here in case it helps diagnose the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants