diff --git a/src/qn/flux.jl b/src/qn/flux.jl index 0f804d0b60..5eb2c83f0b 100644 --- a/src/qn/flux.jl +++ b/src/qn/flux.jl @@ -68,8 +68,12 @@ allfluxequal(T::Tensor) = allequal(flux(T, b) for b in nzblocks(T)) Check that fluxes of all non-zero blocks of a blocked or symmetric Tensor are equal. Throws an error if one or more blocks have a different flux. +If the tensor is dense (is not blocked) then `checkflux` returns `nothing`. """ -checkflux(T::Tensor) = allfluxequal(T) ? nothing : error("Fluxes not all equal") +function checkflux(T::Tensor) + (!hasqns(T) || isempty(T)) && return nothing + return allfluxequal(T) ? nothing : error("Fluxes not all equal") +end """ checkflux(T::Tensor, flux) diff --git a/test/base/test_itensor.jl b/test/base/test_itensor.jl index d5e1d9298a..bcf4a866a7 100644 --- a/test/base/test_itensor.jl +++ b/test/base/test_itensor.jl @@ -1838,6 +1838,11 @@ end n = uniqueindex(N, A) @test dim(n) == dim(j) - dim(i) end + + @testset "checkflux test" begin + # Calling checkflux should not error (issue #1283) + @test ITensors.checkflux(randomITensor(Index(2))) == nothing + end end # End Dense ITensor basic functionality # Disable debug checking once tests are completed