cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

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

Open ezw2 opened 3 years ago

ezw2 commented 3 years ago
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.