ITensor / NDTensors.jl

A Julia package for n-dimensional sparse tensors.
Apache License 2.0
27 stars 7 forks source link

Use nonzeros as an alternative name for data #46

Open mtfishman opened 3 years ago

mtfishman commented 3 years ago

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:

  1. Modifying only the structurally nonzero elements.
  2. 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).
  3. 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.

emstoudenmire commented 3 years ago

Agreed that it's a bit blurry. I think it would be good to think of some specific use cases where #2 might make more sense than #1 or vice versa.