You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current idiom for accessing components of a matrix Factorization object is by indexing. For example, eigfact(M)[:values] returns the eigenvalues of M after computing its spectral factorization, which is stored in an Eigen type. However, eigfact(M)[:values] returns a vector while eigfact(M)[:vectors] returns a matrix. The result is that getindex(::Eigen) is not type stable and static analysis cannot infer a concrete return type.
Consequently, linear algebra code building upon computed matrix factors must either make special effort to avoid the type instability, or break the abstraction of the Factorization object by directly accessing its fields, or else risk degraded performance if the lack of a concrete return type pollutes type inference downstream.
and also this simple code illustrating the problem, annotated with the inferred types given by code_warntype:
functionsvdvals_in_ascending_order(A::Matrix{Float64})
S =svdfact(A) #SVD{Float64,Float64,Matrix{Float64}}
Σ = S[:S] #Union{Array{Float64,1},Array{Float64,2}}sort!(Σ, rev=false) #Any; method with kwarg is hard for Julia to analyzeend
It seems like we should think more about whether the getindex idiom makes sense when the Factorization object consists of heterogeneous fields. I vaguely recall this issue being raised before, but I couldn't find it on GitHub.
The text was updated successfully, but these errors were encountered:
The current idiom for accessing components of a matrix
Factorization
object is by indexing. For example,eigfact(M)[:values]
returns the eigenvalues ofM
after computing its spectral factorization, which is stored in anEigen
type. However,eigfact(M)[:values]
returns a vector whileeigfact(M)[:vectors]
returns a matrix. The result is thatgetindex(::Eigen)
is not type stable and static analysis cannot infer a concrete return type.Consequently, linear algebra code building upon computed matrix factors must either make special effort to avoid the type instability, or break the abstraction of the
Factorization
object by directly accessing its fields, or else risk degraded performance if the lack of a concrete return type pollutes type inference downstream.See
getindex
and also this simple code illustrating the problem, annotated with the inferred types given by
code_warntype
:It seems like we should think more about whether the
getindex
idiom makes sense when theFactorization
object consists of heterogeneous fields. I vaguely recall this issue being raised before, but I couldn't find it on GitHub.The text was updated successfully, but these errors were encountered: