Skip to content

Commit

Permalink
don't allow CellOrbitals{L,Colon} reach slicers
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanjose committed Dec 5, 2024
1 parent 8b0d1da commit a894448
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/greenfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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...)

Expand Down
2 changes: 1 addition & 1 deletion src/slices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a894448

Please sign in to comment.