taco
taco copied to clipboard
Assign new values to tensor coordinates
@stephenchouca Hi Stephen, I was looking for a way to assign a new value to a specific tensor coordinate after initialization of the tensor. Assume the tensor is A, and I have tried "A(i, j) = 10;" and "A.insert({i,j}, 10);", which add 10 to the old value at {i, j}, instead of overwriting the old value. I also tried do "A(i, j) = 10;" two times and printed out the value at A(i, j), and it returned 20, which is not expected. Note that "i" and "j" are integers in both cases.
Is there anything in TACO that I can use to solve this problem? Thank you very much for help. -Lenny
Hi Lenny,
Sorry for the late response. Unfortunately the tensor API currently only supports incrementing the value of an element (i.e. A(i, j) = 10
actually behaves more like A(i, j) += 10
), which explains what you saw. If performance is not a concern, one solution might be to try something like A(i, j) = 10 - A(i, j)
, which clears the element (by subtracting out its current value) and then increments it to the desired final value. Another approach (not as elegant, but likely more efficient) could be to directly modify the underlying array that TACO uses to store values; you can invoke A.getStorage().getValues().getData()
to get the values array, and if for instance your tensor is stored as a dense array, you can use i
and j
to directly index into that array as you would any other multidimensional array in C++.
are there any news regarding this behavior? Are there any plans to remedy this?
I hit upon this issue as well, and it is more than unintuitive if operator=
in fact behaves like operator+=
...