Skip to content

Commit 020e0a5

Browse files
committed
fix recursive_unitless_eltype for general StaticArrays
1 parent 4b45d9b commit 020e0a5

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ FillArrays = "0.11, 0.12, 0.13"
2929
GPUArraysCore = "0.1"
3030
IteratorInterfaceExtensions = "1"
3131
RecipesBase = "0.7, 0.8, 1.0"
32-
StaticArraysCore = "1"
32+
StaticArraysCore = "1.1"
3333
Tables = "1"
3434
ZygoteRules = "0.2"
3535
julia = "1.6"

src/utils.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,7 @@ ones has a `Array{Array{Float64,N},N}`, this will return `Array{Float64,N}`.
210210
recursive_unitless_eltype(a) = recursive_unitless_eltype(eltype(a))
211211
recursive_unitless_eltype(a::Type{Any}) = Any
212212

213-
# Should be:
214-
# recursive_unitless_eltype(a::Type{T}) where {T<:StaticArray} = similar_type(a,recursive_unitless_eltype(eltype(a)))
215-
# But missing from StaticArraysCore
216-
recursive_unitless_eltype(a::Type{StaticArraysCore.SArray{S, T, N, L}}) where {S, T, N, L} = StaticArraysCore.SArray{S, typeof(one(T)), N, L}
217-
recursive_unitless_eltype(a::Type{StaticArraysCore.MArray{S, T, N, L}}) where {S, T, N, L} = StaticArraysCore.MArray{S, typeof(one(T)), N, L}
218-
recursive_unitless_eltype(a::Type{StaticArraysCore.SizedArray{S, T, N, M, TData}}) where {
219-
S, T, N, M, TData} = StaticArraysCore.SizedArray{S, typeof(one(T)), N, M, TData}
213+
recursive_unitless_eltype(a::Type{T}) where {T<:StaticArraysCore.StaticArray} = StaticArraysCore.similar_type(a, recursive_unitless_eltype(eltype(a)))
220214

221215
recursive_unitless_eltype(a::Type{T}) where {T<:Array} = Array{recursive_unitless_eltype(eltype(a)),ndims(a)}
222216
recursive_unitless_eltype(a::Type{T}) where {T<:Number} = typeof(one(eltype(a)))

test/copy_static_array_test.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ end
1313
# Immutable FieldVector
1414
vec = ImmutableFV(1.,2.)
1515
a = [vec]
16+
@test recursive_unitless_eltype(a) == ImmutableFV
1617
b = zero(a)
1718
recursivecopy!(b, a)
1819
@test a[1] == b[1]
@@ -25,6 +26,7 @@ copyat_or_push!(a, 2, b[1])
2526
# Mutable FieldVector
2627
vec = MutableFV(1.,2.)
2728
a = [vec]
29+
@test recursive_unitless_eltype(a) == MutableFV
2830
b = zero(a)
2931
recursivecopy!(b, a)
3032
@test a[1] == b[1]

0 commit comments

Comments
 (0)