Skip to content

Commit

Permalink
Merge pull request #3 from QuantumKitHub/jh/improveproduct
Browse files Browse the repository at this point in the history
speedup isless productsector
  • Loading branch information
Jutho authored Oct 29, 2024
2 parents 3905686 + b658c67 commit 3e6ce25
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
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

4 comments on commit 3e6ce25

@Jutho
Copy link
Member Author

@Jutho Jutho commented on 3e6ce25 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:
Faster isless for ProductSector types, speeds up SectorDict{<:ProductSector} indexing.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Register Failed
@Jutho, it looks like you are not a publicly listed member/owner in the parent organization (QuantumKitHub).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

@Jutho
Copy link
Member Author

@Jutho Jutho commented on 3e6ce25 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:
Faster isless for ProductSector types, speeds up SectorDict{<:ProductSector} indexing.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118337

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 3e6ce251008769e993b6a085e40a45fab981d018
git push origin v0.1.1

Please sign in to comment.