Skip to content

Commit

Permalink
remove reliance on StaticArrays.get (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: colinxs <[email protected]>
  • Loading branch information
colinxs and colinxs authored Apr 26, 2020
1 parent 92d3688 commit d29ced7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
4 changes: 2 additions & 2 deletions src/Shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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} =
Expand Down Expand Up @@ -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} =
Expand Down
12 changes: 6 additions & 6 deletions src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
end
6 changes: 3 additions & 3 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down

0 comments on commit d29ced7

Please sign in to comment.