-
Notifications
You must be signed in to change notification settings - Fork 148
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
Type instability in pinv() for non-square matrix #803
Comments
Looking at the implementation of Here's a more minimal reproduction of that issue: julia> using StaticArrays, LinearAlgebra
julia> foo(A) = svd(A, full=false)
foo (generic function with 1 method)
julia> @code_warntype foo(SA[1 2; 3 4; 5 6])
Variables
#self#::Core.Compiler.Const(foo, false)
A::SArray{Tuple{3,2},Int64,2,6}
Body::Union{StaticArrays.SVD{Float64,SArray{Tuple{3,2},Float64,2,6},SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}, StaticArrays.SVD{Float64,SArray{Tuple{3,3},Float64,2,9},SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}}
1 ─ %1 = (:full,)::Core.Compiler.Const((:full,), false)
│ %2 = Core.apply_type(Core.NamedTuple, %1)::Core.Compiler.Const(NamedTuple{(:full,),T} where T<:Tuple, false)
│ %3 = Core.tuple(false)::Core.Compiler.Const((false,), false)
│ %4 = (%2)(%3)::Core.Compiler.Const((full = false,), false)
│ %5 = Core.kwfunc(Main.svd)::Core.Compiler.Const(LinearAlgebra.var"#svd##kw"(), false)
│ %6 = (%5)(%4, Main.svd, A)::Union{StaticArrays.SVD{Float64,SArray{Tuple{3,2},Float64,2,6},SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}, StaticArrays.SVD{Float64,SArray{Tuple{3,3},Float64,2,9},SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}}
└── return %6 This union is the killer and it propagates through the rest of the On the other hand, if julia> bar(A) = svd(A, full=Val(false)) |
Options for StaticArrays include:
|
Specifically, this problem can be seen in the above Actually, if I mark one of the internal |
Ok, #805 should fix this on Julia 1.5, though Will that work for you once 1.5 is out, or do we need a more comprehensive workaround? |
It would be really helpful if lowering made the extra functions it makes for keyword arguments always |
That will do, I'm on 1.5 already. Thanks for the quick turnaround. |
Nice! |
Using a non-square matrix leads to a type instability in
pinv
. The operation is type-stable for standard arrays.A = @SMatrix rand(3,4)
The text was updated successfully, but these errors were encountered: