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

error in convert for Diagonal #564

Closed
JeffBezanson opened this issue Sep 5, 2018 · 2 comments · May be fixed by JuliaLang/julia#29599
Closed

error in convert for Diagonal #564

JeffBezanson opened this issue Sep 5, 2018 · 2 comments · May be fixed by JuliaLang/julia#29599
Labels
bug Something isn't working

Comments

@JeffBezanson
Copy link
Member

Playing with #563, I discovered this:

julia> convert(Diagonal{Int,Vector{Int}}, Diagonal(1:4))
ERROR: MethodError: no method matching Array{Int64,1}(::Diagonal{Int64,UnitRange{Int64}})

The reason is that the only constructor for instantiated Diagonal types like Diagonal{Int,Vector{Int}} (the "inner" constructor) expects its argument to be a vector. Diagonal(x) accepts both vectors and matrices.

This could be fixed by adding another inner constructor. Or we could add convert methods, since it seems at least conversion should work. Also we could add ::AbstractVector to the argument of the current inner constructor.

@JeffBezanson JeffBezanson added bug Something isn't working linear algebra labels Sep 5, 2018
@mcognetta
Copy link
Contributor

These should be defined individually for all of these matrices (Bidiagonal, Tridiagonal, etc) right?
If this is the case, adding

Diagonal{T, V}(A::Diagonal) where {T, V<:AbstractVector{T}} = Diagonal(convert(V, A.diag)) and analogous ones for the other types should be sufficient.

@ViralBShah
Copy link
Member

julia> convert(Diagonal{Int,Vector{Int}}, Diagonal(1:4))
4×4 Diagonal{Int64, Vector{Int64}}:
 1  ⋅  ⋅  ⋅
 ⋅  2  ⋅  ⋅
 ⋅  ⋅  3  ⋅
 ⋅  ⋅  ⋅  4

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants