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 209fab9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 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
1 change: 0 additions & 1 deletion src/Constructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export
Overwrite,
Try,
Sequence,
Repeater,
SizedArray,
GreedyVector

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)) <: Construct{BitArray{2}}
@test Constructs.deducetype((x, y) -> SizedArray(Int, x, y), Int, Int) <: Construct{Array{Int, 2}}
@test Constructs.deducetype((x, y) -> SizedArray(BitArray{2}, Bool, x, y), Int, Int) <: Construct{BitArray{2}}
@test Constructs.deducetype((size) -> SizedArray(Int, size), NTuple{3, Int}) <: Construct{Array{Int, 3}}
@test Constructs.deducetype((size) -> SizedArray(BitArray{5}, Bool, size), NTuple{5, Int}) <: Construct{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 209fab9

Please sign in to comment.