Skip to content

Commit c83328b

Browse files
Merge pull request #67 from Tokazama/master
Fix #53 with ismutable default
2 parents 48cd97c + 71d5210 commit c83328b

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/ArrayInterface.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,23 @@ https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/issues/19.
7171
"""
7272
ismutable(x) = ismutable(typeof(x))
7373

74-
ismutable(::Type{<:AbstractArray}) = true
75-
ismutable(::Type{<:Number}) = false
74+
function ismutable(::Type{T}) where {T<:AbstractArray}
75+
if parent_type(T) <: T
76+
return true
77+
else
78+
return ismutable(parent_type(T))
79+
end
80+
end
7681
ismutable(::Type{<:AbstractRange}) = false
77-
ismutable(::Type{<:Tuple}) = false
82+
ismutable(::Type{<:AbstractDict}) = true
83+
ismutable(::Type{<:Base.ImmutableDict}) = false
84+
function ismutable(::Type{T}) where {T}
85+
if parent_type(T) <: T
86+
return T.mutable
87+
else
88+
return ismutable(parent_type(T))
89+
end
90+
end
7891

7992
# Piracy
8093
function Base.setindex(x::AbstractArray,v,i...)

test/runtests.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import ArrayInterface: has_sparsestruct, findstructralnz, fast_scalar_indexing,
44
@test ArrayInterface.ismutable(rand(3))
55

66
using StaticArrays
7-
@test ArrayInterface.ismutable(@SVector [1,2,3]) == false
8-
@test ArrayInterface.ismutable(@MVector [1,2,3]) == true
7+
x = @SVector [1,2,3]
8+
@test ArrayInterface.ismutable(x) == false
9+
@test ArrayInterface.ismutable(view(x, 1:2)) == false
10+
x = @MVector [1,2,3]
11+
@test ArrayInterface.ismutable(x) == true
12+
@test ArrayInterface.ismutable(view(x, 1:2)) == true
913
@test ArrayInterface.ismutable(1:10) == false
1014
@test ArrayInterface.ismutable((0.1,1.0)) == false
15+
@test ArrayInterface.ismutable(Base.ImmutableDict{Symbol,Int64}) == false
16+
@test ArrayInterface.ismutable((;x=1)) == false
17+
1118
@test isone(ArrayInterface.known_first(typeof(StaticArrays.SOneTo(7))))
1219
@test ArrayInterface.known_last(typeof(StaticArrays.SOneTo(7))) == 7
1320
@test ArrayInterface.known_length(typeof(StaticArrays.SOneTo(7))) == 7
@@ -47,6 +54,7 @@ rowind,colind=findstructralnz(Sp)
4754
@test ArrayInterface.ismutable(spzeros(1, 1))
4855
@test ArrayInterface.ismutable(spzeros(1))
4956

57+
5058
@test !fast_scalar_indexing(qr(rand(10, 10)).Q)
5159
@test !fast_scalar_indexing(qr(rand(10, 10), Val(true)).Q)
5260
@test !fast_scalar_indexing(lq(rand(10, 10)).Q)

0 commit comments

Comments
 (0)