From d29ced7b1e3c4c1248200c20baaaecdfdf6ab751 Mon Sep 17 00:00:00 2001 From: Colin Summers Date: Sun, 26 Apr 2020 16:10:21 -0700 Subject: [PATCH] remove reliance on StaticArrays.get (#20) Co-authored-by: colinxs --- Project.toml | 4 ++-- src/Shapes.jl | 4 ++-- src/traits.jl | 12 ++++++------ test/Manifest.toml | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 28c6d7f..e20e984 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Shapes" uuid = "175de200-b73b-11e9-28b7-9b5b306cec37" authors = ["Colin Summers", "The Contributors of Shapes"] -version = "0.2.2" +version = "0.2.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -15,6 +15,6 @@ UnsafeArrays = "c4a57d5a-5b31-53a6-b365-19f8c011fbd6" Adapt = "1" MacroTools = "0.5" Requires = "1" -StaticArrays = "= 0.12.0, = 0.12.1" +StaticArrays = "0.12.2" UnsafeArrays = "1" julia = "1.3" diff --git a/src/Shapes.jl b/src/Shapes.jl index 1ad7b7d..7f712b6 100644 --- a/src/Shapes.jl +++ b/src/Shapes.jl @@ -46,7 +46,7 @@ include("ShapedView.jl") getdims(shape::AbstractShape, dims) = getdims(Size(shape), dims) -getdims(s::Size, dims) = ((get(s)..., dims...)) +getdims(s::Size, dims) = ((Tuple(s)..., dims...)) getdims(::Size{()}, dims) = dims Base.Array{T}(::UndefInitializer, shape::AbstractShape, dims::Dims) where {T} = @@ -101,7 +101,7 @@ _rand(T, dims::Dims) = rand(T, dims) # StaticArrays support similar_type(::Type{SH}) where {SH<:AbstractShape} = - SArray{tuple_to_size(get(Size(SH))),concrete_eltype(SH),ndims(SH),length(SH)} + SArray{tuple_to_size(Tuple(Size(SH))),concrete_eltype(SH),ndims(SH),length(SH)} similar_type(::SH) where {SH<:AbstractShape} = similar_type(SH) similar_type(::Type{SA}, ::Type{SH}) where {SA<:StaticArray,SH<:AbstractShape} = diff --git a/src/traits.jl b/src/traits.jl index 63faf4c..be8c9a7 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -23,10 +23,10 @@ Length(shape::SH) where {SH<:AbstractShape} = Length(typeof(shape)) Base.eltype(::Type{SH}) where {S<:Tuple,T,SH<:AbstractShape{S,T}} = T -@pure Base.length(::Type{SH}) where {SH<:AbstractShape} = get(Length(SH)) +@pure Base.length(::Type{SH}) where {SH<:AbstractShape} = Int(Length(SH)) @inline Base.length(shape::AbstractShape) = length(typeof(shape)) -@pure Base.size(::Type{SH}) where {SH<:AbstractShape} = get(Size(SH)) +@pure Base.size(::Type{SH}) where {SH<:AbstractShape} = Tuple(Size(SH)) @inline function Base.size(T::Type{<:AbstractShape}, d::Int) S = size(T) d > length(S) ? 1 : S[d] @@ -131,10 +131,10 @@ ScalarShape(T::Type) = Shape(T) VectorShape(T::Type, dim::Integer) = Shape(T, dim) MatrixShape(T::Type, d1::Integer, d2::Integer) = Shape(T, d1, d2) -Shape(S::Size, T::Type) = Shape{tuple_to_size(get(S)),T}() +Shape(S::Size, T::Type) = Shape{tuple_to_size(Tuple(S)),T}() Shape(::Type{A}) where {A<:AbstractArray} = Shape(Size(A), eltype(A)) function Shape(A::AbstractArray) - size = get(Size(A)) + size = Tuple(Size(A)) check_dynamicsize(size) Shape{tuple_to_size(size),eltype(A)}() end @@ -188,7 +188,7 @@ Base.merge(ms1::MultiShape, ms2::MultiShape) = MultiShape(merge(NamedTuple(ms1), @pure function namedtuple_length(nt::NamedTuple{<:Any,<:Tuple{Vararg{AbstractShape}}}) - sum(shape -> get(Length(shape)), values(nt)) + sum(shape -> Int(Length(shape)), values(nt)) end @generated function check_multishape_namedtuple(::Type{Val{namedtuple}}) where {namedtuple} @@ -237,4 +237,4 @@ end @pure function getoffset(ms::MultiShape, name::Symbol) idx = shapeindex(ms, name) idx == firstindex(ms) ? 0 : sum(i -> length(ms[i]), 1:(idx-1)) -end \ No newline at end of file +end diff --git a/test/Manifest.toml b/test/Manifest.toml index 54c29b5..58f7aa9 100644 --- a/test/Manifest.toml +++ b/test/Manifest.toml @@ -57,7 +57,7 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" deps = ["Adapt", "MacroTools", "Random", "Requires", "StaticArrays", "UnsafeArrays"] path = ".." uuid = "175de200-b73b-11e9-28b7-9b5b306cec37" -version = "0.2.2" +version = "0.2.3" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" @@ -68,9 +68,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[StaticArrays]] deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "5a3bcb6233adabde68ebc97be66e95dcb787424c" +git-tree-sha1 = "4118cba3529e99af61aea9a83f7bfd3cff5ffb28" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.12.1" +version = "0.12.2" [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"]