Skip to content
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

adapt to DualSector #15

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GradedUnitRanges"
uuid = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.6"
version = "0.2.0"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand Down
2 changes: 0 additions & 2 deletions src/GradedUnitRanges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export gradedrange
include("blockedunitrange.jl")
include("gradedunitrange.jl")
include("dual.jl")
include("labelledunitrangedual.jl")
include("gradedunitrangedual.jl")
include("onetoone.jl")
include("fusion.jl")

Expand Down
17 changes: 10 additions & 7 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
is self-dual.
"""
dual(x) = x
isdual(x) = isdual(typeof(x))
isdual(::Type) = false

Check warning on line 12 in src/dual.jl

View check run for this annotation

Codecov / codecov/patch

src/dual.jl#L11-L12

Added lines #L11 - L12 were not covered by tests

nondual(r::AbstractUnitRange) = r
isdual(::AbstractUnitRange) = false

dual_type(x) = dual_type(typeof(x))
dual_type(T::Type) = T
nondual_type(x) = nondual_type(typeof(x))
nondual_type(T::Type) = T
nondual_type(T::Type) = isdual(T) ? dual_type(T) : T
nondual(r::AbstractUnitRange) = map_blocklabels(nondual, r)
isdual(R::Type{<:AbstractUnitRange}) = isdual(eltype(R))
isdual(L::Type{<:LabelledInteger}) = isdual(label_type(L))

Check warning on line 18 in src/dual.jl

View check run for this annotation

Codecov / codecov/patch

src/dual.jl#L15-L18

Added lines #L15 - L18 were not covered by tests

dual(i::LabelledInteger) = labelled(unlabel(i), dual(label(i)))
flip(a::AbstractUnitRange) = dual(map_blocklabels(dual, a))
dual(a::AbstractUnitRange) = map_blocklabels(dual, a)
flip(a::AbstractUnitRange) = map_blocklabels(flip, a)

Check warning on line 22 in src/dual.jl

View check run for this annotation

Codecov / codecov/patch

src/dual.jl#L21-L22

Added lines #L21 - L22 were not covered by tests

flip_dual(x) = isdual(x) ? flip(x) : x

Check warning on line 24 in src/dual.jl

View check run for this annotation

Codecov / codecov/patch

src/dual.jl#L24

Added line #L24 was not covered by tests

"""
dag(r::AbstractUnitRange)
Expand Down
3 changes: 0 additions & 3 deletions src/fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function tensor_product(
end

flip_dual(r::AbstractUnitRange) = r
flip_dual(r::GradedUnitRangeDual) = flip(r)
function tensor_product(a1::AbstractUnitRange, a2::AbstractUnitRange)
return tensor_product(flip_dual(a1), flip_dual(a2))
end
Expand Down Expand Up @@ -93,7 +92,6 @@ function blockmergesort(g::AbstractGradedUnitRange)
return gradedrange(new_blocklengths)
end

blockmergesort(g::GradedUnitRangeDual) = flip(blockmergesort(flip(g)))
blockmergesort(g::AbstractUnitRange) = g

# fusion_product produces a sorted, non-dual GradedUnitRange
Expand All @@ -102,7 +100,6 @@ function fusion_product(g1, g2)
end

fusion_product(g::AbstractUnitRange) = blockmergesort(g)
fusion_product(g::GradedUnitRangeDual) = fusion_product(flip(g))

# recursive fusion_product. Simpler than reduce + fix type stability issues with reduce
function fusion_product(g1, g2, g3...)
Expand Down
10 changes: 4 additions & 6 deletions src/gradedunitrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BlockedUnitRange,
block,
blockedrange,
blockfirsts,
blockisequal,
blocklasts,
blocklength,
Expand Down Expand Up @@ -72,10 +73,6 @@
return blockisequal(a1, a2) && (blocklabels(a1) == blocklabels(a2))
end

function space_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange)
return (isdual(a1) == isdual(a2)) && labelled_isequal(a1, a2)
end

# needed in BlockSparseArrays
function Base.AbstractUnitRange{T}(
a::AbstractGradedUnitRange{<:LabelledInteger{T}}
Expand All @@ -95,8 +92,9 @@
to_sector(x) = x

sector_type(x) = sector_type(typeof(x))
sector_type(T::Type) = error("Not implemented")
sector_type(T::Type{<:AbstractUnitRange}) = label_type(T)
sector_type(::Type) = error("Not implemented")
sector_type(T::Type{<:AbstractUnitRange}) = sector_type(eltype(T))
sector_type(T::Type{<:LabelledInteger}) = nondual_type(label_type(T))

Check warning on line 97 in src/gradedunitrange.jl

View check run for this annotation

Codecov / codecov/patch

src/gradedunitrange.jl#L95-L97

Added lines #L95 - L97 were not covered by tests

# To help with generic code.
function BlockArrays.blockedrange(lblocklengths::AbstractVector{<:LabelledInteger})
Expand Down
155 changes: 0 additions & 155 deletions src/gradedunitrangedual.jl

This file was deleted.

66 changes: 0 additions & 66 deletions src/labelledunitrangedual.jl

This file was deleted.

1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"

[compat]
Aqua = "0.8.9"
Expand Down
4 changes: 2 additions & 2 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using GradedUnitRanges:
blocklabels,
gradedrange,
sector_type,
space_isequal
labelled_isequal
using LabelledNumbers:
LabelledUnitRange, islabelled, label, labelled, labelled_isequal, unlabel
using Test: @test, @test_broken, @testset
Expand Down Expand Up @@ -110,7 +110,7 @@ end
b = combine_blockaxes(a, a)
@test b isa GradedOneTo
@test b == 1:5
@test space_isequal(b, a)
@test labelled_isequal(b, a)
end

# Slicing operations
Expand Down
Loading
Loading