heterocl icon indicating copy to clipboard operation
heterocl copied to clipboard

Accessing a tensor slice references the original tensor instead of generating a copy

Open ezw2 opened this issue 4 years ago • 0 comments

A = hcl.compute((10, 10), lambda x, y: x + y)
B = A[0]
B[3] = 50
hcl.print(A[0][3]) # prints 50

To avoid this, a copy must be explicitly created

A = hcl.compute((10, 10), lambda x, y: x + y)
B = hcl.copy(A[0])
B[3] = 50
hcl.print(A[0][3]) # prints 3
hcl.print(B[3]) # prints 50

This could be confusing, so it might be more intuitive to automatically create a copy of the tensor in this example.

ezw2 avatar Aug 06 '21 17:08 ezw2