-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
[LinearALgebra] Should Diagonal specialize on AdjOrTransAbsVec? #785
Comments
It seems this is a feature, and we have tests for that. See JuliaLang/julia#23706. From the discussion in #466, this was done on purpose, to make |
I think it wouldn't be crazy to call this a bug, and fix it. Adjoint vectors pretend to be The tests that |
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.4 (2018-07-09 19:09 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin14.5.0
julia> x = rand(2)'
1×2 RowVector{Float64,Array{Float64,1}}:
0.658066 0.302965
julia> Diagonal(x)
ERROR: StackOverflowError:
Stacktrace:
[1] steprange_last(::Int64, ::Int64, ::Int64) at ./range.jl:0
[2] Type at ./range.jl:93 [inlined]
[3] _range at ./range.jl:61 [inlined]
[4] range at ./range.jl:60 [inlined]
[5] diagind(::Int64, ::Int64, ::Int64) at ./linalg/dense.jl:206
[6] diag(::RowVector{Float64,Array{Float64,1}}, ::Int64) at ./linalg/dense.jl:250
[7] Diagonal(::RowVector{Float64,Array{Float64,1}}) at ./linalg/diagonal.jl:29 (repeats 79997 times) So, it hasn't been fixed in v0.6.x. I don't have a real preference. I think I can see both points: |
I was surprised that
Diagonal
turns1×n
adjoints into1×1
diagonals:That's because
Diagonal
considers the adjoint vector as a 2D array via this method:https://github.com/JuliaLang/julia/blob/28ff641fa9130d760173122bb231ced2fedf839f/stdlib/LinearAlgebra/src/diagonal.jl#L36
Maybe we could instead add another specialized
Diagonal
method for adjoints/transposes of vectors (usingAdjOrTransAbsVec
)?Specifically, I was thinking of essentially duplicating
https://github.com/JuliaLang/julia/blob/28ff641fa9130d760173122bb231ced2fedf839f/stdlib/LinearAlgebra/src/diagonal.jl#L13-L14
but using
AdjOrTransAbsVec
instead ofAbstractVector
.What do you think?
The text was updated successfully, but these errors were encountered: