From 32cefb0a2d7c048d8b182aa15a55d579371ee4b3 Mon Sep 17 00:00:00 2001 From: "Zachary P. Christensen" Date: Mon, 10 Aug 2020 21:31:20 -0400 Subject: [PATCH 1/3] Address #22 --- src/ArrayInterface.jl | 12 ++++++++++++ test/runtests.jl | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ArrayInterface.jl b/src/ArrayInterface.jl index 385333c8b..ac4f7ddbb 100644 --- a/src/ArrayInterface.jl +++ b/src/ArrayInterface.jl @@ -22,6 +22,18 @@ parent_type(::Type{Symmetric{T,S}}) where {T,S} = S parent_type(::Type{<:LinearAlgebra.AbstractTriangular{T,S}}) where {T,S} = S parent_type(::Type{T}) where {T} = T +""" + is_dynamic(::Type{T}) -> Bool + +Returns `true` if the size of `T` is dynamic. If `T` is dynamic then operations +such as `pop!` and `popfirst!` are available for collections of type `T`. +""" +is_dynamic(x) = is_dynamic(typeof(x)) +is_dynamic(::Type{T}) where {T} = false +is_dynamic(::Type{<:Vector}) = true +is_dynamic(::Type{<:AbstractDict}) = true +is_dynamic(::Type{<:Base.ImmutableDict}) = false + function ismutable end """ diff --git a/test/runtests.jl b/test/runtests.jl index a8f40d96e..9752a7163 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -182,9 +182,17 @@ end @test isnothing(ArrayInterface.known_last(1:4)) @test isnothing(ArrayInterface.known_last(typeof(1:4))) - + @test isnothing(ArrayInterface.known_step(typeof(1:0.2:4))) @test isone(ArrayInterface.known_step(1:4)) @test isone(ArrayInterface.known_step(typeof(1:4))) end +@testset "is_dynamic" begin + @test ArrayInterface.is_dynamic([1]) + @test ArrayInterface.is_dynamic(Vector{Int}) + @test ArrayInterface.is_dynamic(Dict{Symbol,Any}) + @test !ArrayInterface.is_dynamic(Base.ImmutableDict{Symbol,Int64}) + @test !ArrayInterface.is_dynamic(Tuple{}) +end + From aafaf7cf1225cd4306ead2c6a40e6631a94e7c64 Mon Sep 17 00:00:00 2001 From: "Zachary P. Christensen" Date: Mon, 10 Aug 2020 21:35:28 -0400 Subject: [PATCH 2/3] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 1f0bc7c2b..83cd5c6df 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,15 @@ serve as a staging ground for ideas before they merged into Base Julia. For this reason, no functionality is exported so that way if such functions are added and exported in a future Base Julia there will be no issues with the upgrade. +## parent_type(x) + +Returns the parent array that `x` wraps. + +## is_dynamic(x) + +Returns `true` if the size of `T` is dynamic. If `T` is dynamic then operations +such as `pop!` and `popfirst!` are available for collections of type `T`. + ## ismutable(x) A trait function for whether `x` is a mutable or immutable array. Used for From 087d3063e3b50046b66222734695a1fd0c6157e3 Mon Sep 17 00:00:00 2001 From: "Zachary P. Christensen" Date: Tue, 11 Aug 2020 14:14:31 -0400 Subject: [PATCH 3/3] is_dynamic -> can_change_size Also update docstring to reflect this change --- README.md | 4 ++-- src/ArrayInterface.jl | 14 +++++++------- test/runtests.jl | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 83cd5c6df..d7c293ce7 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ and exported in a future Base Julia there will be no issues with the upgrade. Returns the parent array that `x` wraps. -## is_dynamic(x) +## can_change_size(x) -Returns `true` if the size of `T` is dynamic. If `T` is dynamic then operations +Returns `true` if the size of `T` can change, in which case operations such as `pop!` and `popfirst!` are available for collections of type `T`. ## ismutable(x) diff --git a/src/ArrayInterface.jl b/src/ArrayInterface.jl index ac4f7ddbb..85b601e78 100644 --- a/src/ArrayInterface.jl +++ b/src/ArrayInterface.jl @@ -23,16 +23,16 @@ parent_type(::Type{<:LinearAlgebra.AbstractTriangular{T,S}}) where {T,S} = S parent_type(::Type{T}) where {T} = T """ - is_dynamic(::Type{T}) -> Bool + can_change_size(::Type{T}) -> Bool -Returns `true` if the size of `T` is dynamic. If `T` is dynamic then operations +Returns `true` if the size of `T` can change, in which case operations such as `pop!` and `popfirst!` are available for collections of type `T`. """ -is_dynamic(x) = is_dynamic(typeof(x)) -is_dynamic(::Type{T}) where {T} = false -is_dynamic(::Type{<:Vector}) = true -is_dynamic(::Type{<:AbstractDict}) = true -is_dynamic(::Type{<:Base.ImmutableDict}) = false +can_change_size(x) = can_change_size(typeof(x)) +can_change_size(::Type{T}) where {T} = false +can_change_size(::Type{<:Vector}) = true +can_change_size(::Type{<:AbstractDict}) = true +can_change_size(::Type{<:Base.ImmutableDict}) = false function ismutable end diff --git a/test/runtests.jl b/test/runtests.jl index 9752a7163..f25fae932 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -188,11 +188,11 @@ end @test isone(ArrayInterface.known_step(typeof(1:4))) end -@testset "is_dynamic" begin - @test ArrayInterface.is_dynamic([1]) - @test ArrayInterface.is_dynamic(Vector{Int}) - @test ArrayInterface.is_dynamic(Dict{Symbol,Any}) - @test !ArrayInterface.is_dynamic(Base.ImmutableDict{Symbol,Int64}) - @test !ArrayInterface.is_dynamic(Tuple{}) +@testset "can_change_size" begin + @test ArrayInterface.can_change_size([1]) + @test ArrayInterface.can_change_size(Vector{Int}) + @test ArrayInterface.can_change_size(Dict{Symbol,Any}) + @test !ArrayInterface.can_change_size(Base.ImmutableDict{Symbol,Int64}) + @test !ArrayInterface.can_change_size(Tuple{}) end