Right now, a view of the vector storage of a Tensor can be obtained with the function data. We could consider adopting the Julia SparseArrays function name nonzeros for this purpose (https://docs.julialang.org/en/v1/stdlib/SparseArrays/#SparseArrays.nonzeros), which returns a view of the structural nonzeros of a sparse array.
This is helpful for iteration, any time the iteration is only supposed to work on the elements that are already nonzero.
The line for what data should be touched is a bit blurry from the ITensor perspective. For example, for a QN ITensor, what is supposed to be meant by A .+= 2? It could be interpreted in 3 ways:
Modifying only the structurally nonzero elements.
Modifying any element consistent with the flux (with a reminder that even determining which blocks are consistent with the flux can be slow in the limit of many blocks).
Modifying every element of the ITensor (which would be inconsistent with the flux in general, so would necessitate making the storage dense).
(1) is probably the most common, but likely it is best to make it explicit using nonzeros(A) .+= 2, and possibly it is best to disallow A .+= 2 unless a use case is found where the operations are meant to act on something besides the current structurally nonzero elements.
Right now, a view of the vector storage of a
Tensor
can be obtained with the functiondata
. We could consider adopting the Julia SparseArrays function namenonzeros
for this purpose (https://docs.julialang.org/en/v1/stdlib/SparseArrays/#SparseArrays.nonzeros), which returns a view of the structural nonzeros of a sparse array.This is helpful for iteration, any time the iteration is only supposed to work on the elements that are already nonzero.
The line for what data should be touched is a bit blurry from the ITensor perspective. For example, for a QN ITensor, what is supposed to be meant by
A .+= 2
? It could be interpreted in 3 ways:(1) is probably the most common, but likely it is best to make it explicit using
nonzeros(A) .+= 2
, and possibly it is best to disallowA .+= 2
unless a use case is found where the operations are meant to act on something besides the current structurally nonzero elements.