Skip to content

Commit

Permalink
array: remove Repeater base type
Browse files Browse the repository at this point in the history
it is useless but misleading
  • Loading branch information
miRoox committed Nov 1, 2022
1 parent 8247d74 commit 9fdc522
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
1 change: 0 additions & 1 deletion docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Sequence
## Repeaters

```@docs
Repeater
SizedArray
GreedyVector
```
Expand Down
10 changes: 2 additions & 8 deletions src/Array.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
"""
Repeater{T, TA<:AbstractArray{T}} <: Wrapper{T, TA}
Abstract base type for Array wrapper.
"""
abstract type Repeater{T, TA<:AbstractArray{T}} <: Wrapper{T, TA} end

deduceArrayType(::Type{TA}, ::Type{T}, N::Integer) where {T, TA<:AbstractArray} = deducetype(Base.similar, TA, Type{T}, Dims{N})

struct SizedArray{T, N, TA<:AbstractArray{T,N}, TSubCon<:Construct{T}} <: Repeater{T, TA}
struct SizedArray{T, N, TA<:AbstractArray{T,N}, TSubCon<:Construct{T}} <: Wrapper{T, TA}
subcon::TSubCon
size::NTuple{N, UInt}

Expand Down Expand Up @@ -66,7 +60,7 @@ function serialize(array::SizedArray{T, N, TA, TSubCon}, s::IO, obj::TA; context
end
estimatesize(array::SizedArray; contextkw...) = prod(array.size) * estimatesize(array.subcon; contextkw...)

struct GreedyVector{T, TSubCon<:Construct{T}} <: Repeater{T, Vector{T}}
struct GreedyVector{T, TSubCon<:Construct{T}} <: Wrapper{T, Vector{T}}
subcon::TSubCon
end

Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ end
end
@testset "SizedArray" begin
@testset "deduce type" begin
@test Constructs.deducetype(() -> SizedArray(Int, 1, 2)) <: Repeater{Int, Array{Int, 2}}
@test Constructs.deducetype(() -> SizedArray(BitArray{2}, Bool, 1, 2)) <: Repeater{Bool, BitArray{2}}
@test Constructs.deducetype((x, y) -> SizedArray(Int, x, y), Int, Int) <: Repeater{Int, Array{Int, 2}}
@test Constructs.deducetype((x, y) -> SizedArray(BitArray{2}, Bool, x, y), Int, Int) <: Repeater{Bool, BitArray{2}}
@test Constructs.deducetype((size) -> SizedArray(Int, size), NTuple{3, Int}) <: Repeater{Int, Array{Int, 3}}
@test Constructs.deducetype((size) -> SizedArray(BitArray{5}, Bool, size), NTuple{5, Int}) <: Repeater{Bool, BitArray{5}}
@test Constructs.deducetype(() -> SizedArray(Int, 1, 2)) <: Construct{Array{Int, 2}}
@test Constructs.deducetype(() -> SizedArray(BitArray{2}, Bool, 1, 2)) <: Repeater{BitArray{2}}
@test Constructs.deducetype((x, y) -> SizedArray(Int, x, y), Int, Int) <: Repeater{Array{Int, 2}}
@test Constructs.deducetype((x, y) -> SizedArray(BitArray{2}, Bool, x, y), Int, Int) <: Repeater{BitArray{2}}
@test Constructs.deducetype((size) -> SizedArray(Int, size), NTuple{3, Int}) <: Repeater{Array{Int, 3}}
@test Constructs.deducetype((size) -> SizedArray(BitArray{5}, Bool, size), NTuple{5, Int}) <: Repeater{BitArray{5}}
end
@test_throws TypeError SizedArray(BitArray{3}, Int, (2, 3, 5)) # element type mismatch
@test_throws TypeError SizedArray(UnitRange{Int}, Int, 3) # immutable array cannot be deserialized
Expand Down

0 comments on commit 9fdc522

Please sign in to comment.