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

Define sector_type #2

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions src/gradedunitrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ Base.eltype(::Type{<:GradedUnitRange{T}}) where {T} = T
LabelledNumbers.label_type(g::AbstractGradedUnitRange) = label_type(typeof(g))
LabelledNumbers.label_type(T::Type{<:AbstractGradedUnitRange}) = label_type(eltype(T))

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

function gradedrange(lblocklengths::AbstractVector{<:LabelledInteger})
brange = blockedrange(unlabel.(lblocklengths))
lblocklasts = labelled.(blocklasts(brange), label.(lblocklengths))
Expand Down
5 changes: 5 additions & 0 deletions src/labelledunitrangedual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ blocklabels(la::LabelledUnitRangeDual) = [label(la)]
LabelledNumbers.label(a::LabelledUnitRangeDual) = dual(label(nondual(a)))
LabelledNumbers.unlabel(a::LabelledUnitRangeDual) = unlabel(nondual(a))
LabelledNumbers.LabelledStyle(::LabelledUnitRangeDual) = IsLabelled()
function LabelledNumbers.label_type(
::Type{<:LabelledUnitRangeDual{<:Any,NondualUnitRange}}
) where {NondualUnitRange}
return label_type(NondualUnitRange)
end
ogauthe marked this conversation as resolved.
Show resolved Hide resolved

for f in [:first, :getindex, :last, :length, :step]
@eval Base.$f(a::LabelledUnitRangeDual, args...) =
Expand Down
9 changes: 8 additions & 1 deletion test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ using BlockArrays:
combine_blockaxes,
mortar
using GradedUnitRanges:
GradedOneTo, GradedUnitRange, OneToOne, blocklabels, gradedrange, space_isequal
GradedOneTo,
GradedUnitRange,
OneToOne,
blocklabels,
gradedrange,
sector_type,
space_isequal
using LabelledNumbers:
LabelledUnitRange, islabelled, label, labelled, labelled_isequal, unlabel
using Test: @test, @test_broken, @testset
Expand Down Expand Up @@ -41,6 +47,7 @@ end
gradedrange(["x" => 2, "y" => 3]),
)
@test a isa GradedOneTo
@test sector_type(a) === String
@test labelled_isequal(a, a)
@test !labelled_isequal(a0, a)
@test !labelled_isequal(a, a0)
Expand Down
14 changes: 9 additions & 5 deletions test/test_dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ using BlockArrays:
mortar,
combine_blockaxes
using GradedUnitRanges:
GradedUnitRanges,
AbstractGradedUnitRange,
GradedUnitRanges,
GradedUnitRangeDual,
LabelledUnitRangeDual,
OneToOne,
Expand All @@ -24,10 +24,11 @@ using GradedUnitRanges:
blocksortperm,
dual,
flip,
space_isequal,
gradedrange,
isdual,
nondual
nondual,
space_isequal,
sector_type
using LabelledNumbers:
LabelledInteger, LabelledUnitRange, label, label_type, labelled, labelled_isequal, unlabel
using Test: @test, @test_broken, @testset
Expand Down Expand Up @@ -70,7 +71,8 @@ end
@test !isdual(la)
@test labelled_isequal(la, la)
@test space_isequal(la, la)
@test label_type(la) == U1
@test label_type(la) === U1
@test sector_type(la) === U1

@test iterate(la) == (1, 1)
@test iterate(la) == (1, 1)
Expand All @@ -90,7 +92,8 @@ end
@test isdual(lad)
@test nondual(lad) === la
@test dual(lad) === la
@test label_type(lad) == U1
@test label_type(lad) === U1
@test sector_type(lad) === U1

@test iterate(lad) == (1, 1)
@test iterate(lad) == (1, 1)
Expand Down Expand Up @@ -155,6 +158,7 @@ end
@test eltype(ad) == LabelledInteger{Int,U1}
@test blocklengths(ad) isa Vector
@test eltype(blocklengths(ad)) == eltype(blocklengths(a))
@test sector_type(a) === U1

@test space_isequal(dual(ad), a)
@test space_isequal(nondual(ad), a)
Expand Down
Loading