Error in input.contiguous()

I am getting this error
error: passing ‘const at::Tensor’ as ‘this’ argument discards qualifiers
while running the following code

input = input.contiguous()

where input is a torch tensor defined as const Tensor& input

Is it because of const?

Yes we can’t do input = input.contiguous() if input is const Tensor&. Changing it to Tensor should work :smiley:

One might add that if input is an input to your function, the correct way is to leave it const Tensor& and declare a new local variable as
auto cont_input = input.contiguous();
This is assuming that your function won’t actually try to change input (which it should not when you call contiguous()

Best regards

Thomas