Skip to content

Commit 3e6ce25

Browse files
authored
Merge pull request #3 from QuantumKitHub/jh/improveproduct
speedup isless productsector
2 parents 3905686 + b658c67 commit 3e6ce25

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
version:
25-
- '1.10' # replace with LTS once it is released
26-
# - '1' # automatically expands to the latest stable 1.x release of Julia
25+
- 'lts' # current lts release
26+
- '1' # latest stable release
2727
os:
2828
- ubuntu-latest
2929
- macOS-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorKitSectors"
22
uuid = "13a9c161-d5da-41f0-bcbd-e1a08ae0647f"
33
authors = ["Lukas Devos", "Jutho Haegeman"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"

src/auxiliary.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
end
3232

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

5656
# inverse mapping
5757
@inline invertlocaloffset(d, offset, sz::Tuple{Int}) = (d + 1,)
58-
@inline function invertlocaloffset(d, offset, sz)
58+
@inline function invertlocaloffset(d, offset, sz::Tuple{Int,Int,Vararg{Int}})
5959
i₁ = 1
6060
while i₁ < sz[1]
6161
jump = num_manhattan_points(d - i₁ + 1, Base.tail(sz))

src/irreps.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Base.conj(c::U1Irrep) = U1Irrep(-c.charge)
135135
(c1::U1Irrep, c2::U1Irrep) = (U1Irrep(c1.charge + c2.charge),)
136136

137137
Base.IteratorSize(::Type{SectorValues{U1Irrep}}) = IsInfinite()
138-
function Base.iterate(::SectorValues{U1Irrep}, i=0)
138+
function Base.iterate(::SectorValues{U1Irrep}, i::Int=0)
139139
return i <= 0 ? (U1Irrep(half(i)), (-i + 1)) : (U1Irrep(half(i)), -i)
140140
end
141141
function Base.getindex(::SectorValues{U1Irrep}, i::Int)
@@ -188,7 +188,7 @@ Base.conj(s::SU2Irrep) = s
188188
(s1::SU2Irrep, s2::SU2Irrep) = SectorSet{SU2Irrep}(abs(s1.j - s2.j):(s1.j + s2.j))
189189

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

271271
Base.IteratorSize(::Type{SectorValues{CU1Irrep}}) = IsInfinite()
272-
function Base.iterate(::SectorValues{CU1Irrep}, state=(0, 0))
272+
function Base.iterate(::SectorValues{CU1Irrep}, state::Tuple{Int,Int}=(0, 0))
273273
j, s = state
274274
if iszero(j) && s == 0
275275
return CU1Irrep(j, s), (j, 1)

src/product.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,14 @@ dim(p::ProductSector) = *(dim.(p.sectors)...)
166166

167167
Base.isequal(p1::ProductSector, p2::ProductSector) = isequal(p1.sectors, p2.sectors)
168168
Base.hash(p::ProductSector, h::UInt) = hash(p.sectors, h)
169-
function Base.isless(p1::P, p2::P) where {P<:ProductSector}
170-
return isless(findindex(values(P), p1), findindex(values(P), p2))
169+
function Base.isless(p1::ProductSector{T}, p2::ProductSector{T}) where {T<:SectorTuple}
170+
I1 = findindex.(values.(_sectors(T)), p1.sectors)
171+
I2 = findindex.(values.(_sectors(T)), p2.sectors)
172+
d1 = sum(I1) - length(I1)
173+
d2 = sum(I2) - length(I2)
174+
d1 < d2 && return true
175+
d1 > d2 && return false
176+
return isless(I1, I2)
171177
end
172178

173179
# Default construction from tensor product of sectors

0 commit comments

Comments
 (0)