-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SubArray getindex doesn't work on immutable array types #10001
Comments
The line of julia> d = Diagonal(rand(10,10));
julia> d[[1, 2, 3, 4, 5], :]
ERROR: MethodError: `getindex` has no method matching getindex(::Base.LinAlg.Diagonal{Float64}, ::Array{Int64,1}, ::UnitRange{Int64})
Closest candidates are:
getindex(::AbstractArray{T,2}, ::Any, ::Any, ::Any, ::Any...)
getindex{T,N,P,IV}(::SubArray{T,N,P,IV,LD}, ::Union(Array{Int64,1},Range{Int64},Int64,Colon)...)
getindex{T,N,P,IV}(::SubArray{T,N,P,IV,LD}, ::Union(AbstractArray{T,1},Real), ::Union(AbstractArray{T,1},Real))
...
julia> s = sub(d, 1:5, 1:5);
julia> s[[1, 2, 3, 4, 5], :]
ERROR: MethodError: `setindex!` has no method matching setindex!(::Base.LinAlg.Diagonal{Float64}, ::Float64, ::Int64, ::Int64)
Closest candidates are:
setindex!(::AbstractArray{T,2}, ::Any, ::Any, ::Any, ::Any, ::Any...)
setindex!{T}(::Array{T,N}, ::Any, ::Real, ::Real)
setindex!{T}(::Array{T,N}, ::Any, ::Real, ::Real, ::Real)
...
in copy! at multidimensional.jl:436
in getindex at subarray2.jl:82 |
Yes, the "mutation" is an implementation of |
This seems to be evidence that the solution to JuliaLang/LinearAlgebra.jl#168 should be to provide a full array from |
From |
(response in #11574) |
Fixed by #11582. All the examples above look much better now: julia> d = Diagonal(rand(10,10));
julia> s = sub(d, 1:5, 1:5);
julia> sortrows(d)
ERROR: ArgumentError: cannot set an off-diagonal index (10, 1) to a nonzero value (0.05324786837334572)
julia> sortrows(s)
ERROR: ArgumentError: cannot set an off-diagonal index (5, 1) to a nonzero value (0.05324786837334572)
julia> d[[1, 2, 3, 4, 5], :]
ERROR: ArgumentError: diagonal matrix must be square
julia> s[[1, 2, 3, 4, 5], :]
5x5 Diagonal{Float64}:
0.160014 ⋅ ⋅ ⋅ ⋅
⋅ 0.574236 ⋅ ⋅ ⋅
⋅ ⋅ 0.0339231 ⋅ ⋅
⋅ ⋅ ⋅ 0.151776 ⋅
⋅ ⋅ ⋅ ⋅ 0.509368 |
Should this method be renamed to
sortrows!
/sortcols
? It currently fails forAbstractMatrix
subtypes which do not definesetindex!
.Ex.
The text was updated successfully, but these errors were encountered: