Skip to content

Commit

Permalink
Drop zero blocks affter setting an element
Browse files Browse the repository at this point in the history
  • Loading branch information
kmp5VT committed Sep 15, 2023
1 parent 5268395 commit 3931c3a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/itensor/qnitensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
::HasQNs, T::Tensor, x::Number, I::Integer...
)
fluxT = flux(T)
setting_flux = isnothing(fluxT)
if !NDTensors.is_unallocated_zeros(T) && fluxT != flux(T, I...)
error(
"In `setindex!`, the element $I of ITensor: \n$(T)\n you are trying to set is in a block with flux $(flux(T, I...)), which is different from the flux $fluxT of the other blocks of the ITensor. You may be trying to create an ITensor that does not have a well defined quantum number flux.",
)
end
if isnothing(fluxT)

if setting_flux && NDTensors.is_unallocated_zeros(T)
T = tensor(ITensor(eltype(T), flux(T, I...), inds(T)))
T = setindex!!(T, x, I...)
T = NDTensors.dropzeros(T; tol = zero(eltype(T)))
return T
end
return setindex!!(T, x, I...)
end
Expand Down Expand Up @@ -364,16 +369,20 @@ end

function dropzeros(T::ITensor; tol=0)
# XXX: replace with empty(T)
= emptyITensor(eltype(T), inds(T))
= ITensor(eltype(T), inds(T))
for b in eachnzblock(T)
Tb = T[b]
@show norm(Tb)
@show typeof(Tb)
@show dim(Tb)
if norm(Tb) > tol
T̃[b] = Tb
#T̃[b] = Tb
end
end
return
end


function δ_split(i1::Index, i2::Index)
d = emptyITensor(i1, i2)
for n in 1:min(dim(i1), dim(i2))
Expand Down

0 comments on commit 3931c3a

Please sign in to comment.