Skip to content

speedup isless productsector #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.10' # replace with LTS once it is released
# - '1' # automatically expands to the latest stable 1.x release of Julia
- 'lts' # current lts release
- '1' # latest stable release
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorKitSectors"
uuid = "13a9c161-d5da-41f0-bcbd-e1a08ae0647f"
authors = ["Lukas Devos", "Jutho Haegeman"]
version = "0.1.0"
version = "0.1.1"

[deps]
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"
Expand Down
4 changes: 2 additions & 2 deletions src/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
end

@inline localoffset(d, I::Tuple{Int}, sz::Tuple{Int}) = 0
@inline function localoffset(d, I, sz)
@inline function localoffset(d, I::NTuple{N,Int}, sz::NTuple{N,Int}) where {N}
offset = 0
for i in 1:(I[1] - 1)
offset += num_manhattan_points(d - i + 1, Base.tail(sz))
Expand All @@ -55,7 +55,7 @@ end

# inverse mapping
@inline invertlocaloffset(d, offset, sz::Tuple{Int}) = (d + 1,)
@inline function invertlocaloffset(d, offset, sz)
@inline function invertlocaloffset(d, offset, sz::Tuple{Int,Int,Vararg{Int}})
i₁ = 1
while i₁ < sz[1]
jump = num_manhattan_points(d - i₁ + 1, Base.tail(sz))
Expand Down
6 changes: 3 additions & 3 deletions src/irreps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Base.conj(c::U1Irrep) = U1Irrep(-c.charge)
⊗(c1::U1Irrep, c2::U1Irrep) = (U1Irrep(c1.charge + c2.charge),)

Base.IteratorSize(::Type{SectorValues{U1Irrep}}) = IsInfinite()
function Base.iterate(::SectorValues{U1Irrep}, i=0)
function Base.iterate(::SectorValues{U1Irrep}, i::Int=0)
return i <= 0 ? (U1Irrep(half(i)), (-i + 1)) : (U1Irrep(half(i)), -i)
end
function Base.getindex(::SectorValues{U1Irrep}, i::Int)
Expand Down Expand Up @@ -188,7 +188,7 @@ Base.conj(s::SU2Irrep) = s
⊗(s1::SU2Irrep, s2::SU2Irrep) = SectorSet{SU2Irrep}(abs(s1.j - s2.j):(s1.j + s2.j))

Base.IteratorSize(::Type{SectorValues{SU2Irrep}}) = IsInfinite()
Base.iterate(::SectorValues{SU2Irrep}, i=0) = (SU2Irrep(half(i)), i + 1)
Base.iterate(::SectorValues{SU2Irrep}, i::Int=0) = (SU2Irrep(half(i)), i + 1)
function Base.getindex(::SectorValues{SU2Irrep}, i::Int)
return 1 <= i ? SU2Irrep(half(i - 1)) : throw(BoundsError(values(SU2Irrep), i))
end
Expand Down Expand Up @@ -269,7 +269,7 @@ Base.getindex(::IrrepTable, ::Type{CU₁}) = CU1Irrep
Base.convert(::Type{CU1Irrep}, (j, s)::Tuple{Real,Integer}) = CU1Irrep(j, s)

Base.IteratorSize(::Type{SectorValues{CU1Irrep}}) = IsInfinite()
function Base.iterate(::SectorValues{CU1Irrep}, state=(0, 0))
function Base.iterate(::SectorValues{CU1Irrep}, state::Tuple{Int,Int}=(0, 0))
j, s = state
if iszero(j) && s == 0
return CU1Irrep(j, s), (j, 1)
Expand Down
10 changes: 8 additions & 2 deletions src/product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ dim(p::ProductSector) = *(dim.(p.sectors)...)

Base.isequal(p1::ProductSector, p2::ProductSector) = isequal(p1.sectors, p2.sectors)
Base.hash(p::ProductSector, h::UInt) = hash(p.sectors, h)
function Base.isless(p1::P, p2::P) where {P<:ProductSector}
return isless(findindex(values(P), p1), findindex(values(P), p2))
function Base.isless(p1::ProductSector{T}, p2::ProductSector{T}) where {T<:SectorTuple}
I1 = findindex.(values.(_sectors(T)), p1.sectors)
I2 = findindex.(values.(_sectors(T)), p2.sectors)
d1 = sum(I1) - length(I1)
d2 = sum(I2) - length(I2)
d1 < d2 && return true
d1 > d2 && return false
return isless(I1, I2)
end

# Default construction from tensor product of sectors
Expand Down
Loading