Skip to content
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

sub displays #undef when AbstractArray subtype does not define getindex. #166

Closed
jakebolewski opened this issue Feb 1, 2015 · 4 comments

Comments

@jakebolewski
Copy link
Member

For example:

julia> t
5x5 Base.LinAlg.SymTridiagonal{Float64}:
 1.58856   0.13194    0.0        0.0        0.0
 0.13194   2.24674   -0.389461   0.0        0.0
 0.0      -0.389461   0.912113  -0.819463   0.0
 0.0       0.0       -0.819463   3.82956   -1.05546
 0.0       0.0        0.0       -1.05546    1.40946

julia> sub(t, [1:2])
2-element SubArray{Float64,1,Base.LinAlg.SymTridiagonal{Float64},(Array{Int64,1},),0}:
 #undef
 #undef

julia> sub(full(t), [1:2])
2-element SubArray{Float64,1,Array{Float64,2},(Array{Int64,1},),0}:
 1.58856
 0.13194

Shouldn't this throw a method error instead?

@jakebolewski jakebolewski changed the title sub returns #undef when AbstractMatrix subtype does not defined getindex. sub returns #undef when AbstractMatrix subtype does not define getindex. Feb 1, 2015
@jakebolewski jakebolewski changed the title sub returns #undef when AbstractMatrix subtype does not define getindex. sub returns #undef when AbstractArray subtype does not define getindex. Feb 1, 2015
@timholy
Copy link
Member

timholy commented Feb 1, 2015

The #undef has nothing to do with sub, it's the display functionality. For example:

julia> t = SymTridiagonal(rand(5),rand(4))
5x5 Base.LinAlg.SymTridiagonal{Float64}:
 0.450664  0.594558  0.0       0.0        0.0     
 0.594558  0.863439  0.304512  0.0        0.0     
 0.0       0.304512  0.757572  0.520557   0.0     
 0.0       0.0       0.520557  0.0303424  0.155352
 0.0       0.0       0.0       0.155352   0.4823  

julia> t[3]
ERROR: indexing not defined for Base.LinAlg.SymTridiagonal{Float64}
 in getindex at abstractarray.jl:434

julia> a = sub(t, 1:2)
2-element SubArray{Float64,1,Base.LinAlg.SymTridiagonal{Float64},(UnitRange{Int64},),0}:
 #undef
 #undef

julia> a[1]
ERROR: indexing not defined for Base.LinAlg.SymTridiagonal{Float64}
 in anonymous at subarray2.jl:34

which is indeed the method error you were hoping for. IIRC there are some try statements in the display functionality.

All of these work if you first define

Base.getindex(A::SymTridiagonal, i::Real) = getindex(A, ind2sub(size(A), i)...)

before performing the above steps. It also doesn't happen with sub(t, 1:2, 1).

But perhaps you're thinking that the display functionality needs to be changed? This isn't the first time this has proved confusing, see timholy/Grid.jl#48 and JuliaMath/Interpolations.jl#14.

@jakebolewski jakebolewski changed the title sub returns #undef when AbstractArray subtype does not define getindex. sub displays #undef when AbstractArray subtype does not define getindex. Feb 2, 2015
@jakebolewski
Copy link
Member Author

Sorry, the wording wasn't correct. I think we should display something other than #undef in this case.

@mbauman
Copy link
Member

mbauman commented Jun 4, 2015

This works now with JuliaLang/julia#10525 since SymTridiagonal just got one-dimensional indexing for free.

@timholy
Copy link
Member

timholy commented Jun 4, 2015

I love the cascade of closed issues from JuliaLang/julia#10525.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants