From a89444826544520aa3323c348720546cc6bf4c99 Mon Sep 17 00:00:00 2001 From: Pablo San-Jose Date: Thu, 5 Dec 2024 12:40:00 +0100 Subject: [PATCH] don't allow CellOrbitals{L,Colon} reach slicers --- src/greenfunction.jl | 12 ++++++++---- src/slices.jl | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/greenfunction.jl b/src/greenfunction.jl index fb9bdcdd..d57a75cc 100644 --- a/src/greenfunction.jl +++ b/src/greenfunction.jl @@ -105,12 +105,16 @@ function Base.getindex(g::GreenSolution, args...; post = identity, symmetrize = end Base.getindex(g::GreenSolution, i::AnyCellOrbitals, j::AnyCellOrbitals) = - slicer(g)[sanitize_cellorbs(i), sanitize_cellorbs(j)] + slicer(g)[sanitize_cellorbs(i, g), sanitize_cellorbs(j, g)] # must ensure that orbindices is not a scalar, to consistently obtain a Matrix +# also, it should not be Colon, as GreenSlicers generally assume an explicit range +sanitize_cellorbs(c::CellOrbitals, g) = sites_to_orbs(c, g) # convert : to range sanitize_cellorbs(c::CellOrbitals) = c -sanitize_cellorbs(c::CellOrbital) = CellOrbitals(cell(c), orbindex(c):orbindex(c)) -sanitize_cellorbs(c::CellOrbitalsGrouped) = CellOrbitals(cell(c), orbindices(c)) +sanitize_cellorbs(c::CellOrbital, _...) = CellOrbitals(cell(c), orbindex(c):orbindex(c)) +sanitize_cellorbs(c::CellOrbitalsGrouped, _...) = CellOrbitals(cell(c), orbindices(c)) +sanitize_cellorbs(::CellOrbitals{<:Any,Colon}) = + internalerror("sanitize_cellorbs: Colon indices leaked!") ## common getindex! shortcut in terms of GreenSlice @@ -163,7 +167,7 @@ cell_orbindices(_, ::Missing) = Colon() ## GreenSlicer -> Matrix, dispatches to each solver's implementation -# fallback conversion to CellOrbitals +# simplify CellOrbitalGroups to CellOrbitals. No CellOrbitals{L,Colon} should get here Base.getindex(s::GreenSlicer, i::AnyCellOrbitals, j::AnyCellOrbitals = i; kw...) = getindex(s, sanitize_cellorbs(i), sanitize_cellorbs(j); kw...) diff --git a/src/slices.jl b/src/slices.jl index 40cf1c0b..f40e9c18 100644 --- a/src/slices.jl +++ b/src/slices.jl @@ -359,7 +359,7 @@ sites_to_orbs(c::SparseIndices{<:Any,<:Hamiltonian}, _) = c # unused # sites_to_orbs_nogroups(cs::CellOrbitals, _) = cs -## CellOrbitals{L,Colon} -> CellOrbitals with collected indices +## CellOrbitals{L,Colon} -> CellOrbitals with explicit index range sites_to_orbs(cs::CellOrbitals{<:Any,Colon}, g) = sites_to_orbs_nogroups(sites(cell(cs), :), g)