Skip to content

Commit

Permalink
Merge pull request #67 from Tokazama/master
Browse files Browse the repository at this point in the history
Fix #53 with ismutable default
  • Loading branch information
ChrisRackauckas authored Sep 4, 2020
2 parents 48cd97c + 71d5210 commit c83328b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/ArrayInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,23 @@ https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/issues/19.
"""
ismutable(x) = ismutable(typeof(x))

ismutable(::Type{<:AbstractArray}) = true
ismutable(::Type{<:Number}) = false
function ismutable(::Type{T}) where {T<:AbstractArray}
if parent_type(T) <: T
return true
else
return ismutable(parent_type(T))
end
end
ismutable(::Type{<:AbstractRange}) = false
ismutable(::Type{<:Tuple}) = false
ismutable(::Type{<:AbstractDict}) = true
ismutable(::Type{<:Base.ImmutableDict}) = false
function ismutable(::Type{T}) where {T}
if parent_type(T) <: T
return T.mutable
else
return ismutable(parent_type(T))
end
end

# Piracy
function Base.setindex(x::AbstractArray,v,i...)
Expand Down
12 changes: 10 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import ArrayInterface: has_sparsestruct, findstructralnz, fast_scalar_indexing,
@test ArrayInterface.ismutable(rand(3))

using StaticArrays
@test ArrayInterface.ismutable(@SVector [1,2,3]) == false
@test ArrayInterface.ismutable(@MVector [1,2,3]) == true
x = @SVector [1,2,3]
@test ArrayInterface.ismutable(x) == false
@test ArrayInterface.ismutable(view(x, 1:2)) == false
x = @MVector [1,2,3]
@test ArrayInterface.ismutable(x) == true
@test ArrayInterface.ismutable(view(x, 1:2)) == true
@test ArrayInterface.ismutable(1:10) == false
@test ArrayInterface.ismutable((0.1,1.0)) == false
@test ArrayInterface.ismutable(Base.ImmutableDict{Symbol,Int64}) == false
@test ArrayInterface.ismutable((;x=1)) == false

@test isone(ArrayInterface.known_first(typeof(StaticArrays.SOneTo(7))))
@test ArrayInterface.known_last(typeof(StaticArrays.SOneTo(7))) == 7
@test ArrayInterface.known_length(typeof(StaticArrays.SOneTo(7))) == 7
Expand Down Expand Up @@ -47,6 +54,7 @@ rowind,colind=findstructralnz(Sp)
@test ArrayInterface.ismutable(spzeros(1, 1))
@test ArrayInterface.ismutable(spzeros(1))


@test !fast_scalar_indexing(qr(rand(10, 10)).Q)
@test !fast_scalar_indexing(qr(rand(10, 10), Val(true)).Q)
@test !fast_scalar_indexing(lq(rand(10, 10)).Q)
Expand Down

0 comments on commit c83328b

Please sign in to comment.