cornell-zhang/heterocl

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

ezw2 opened this issue · 0 comments

ezw2 commented
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.