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
Higher-order functions in factorize to obtain structure (#1135)
Instead of looping over the entire array to check the matrix structure,
we may use higher-order querying functions like `istriu` and
`issymmetric`. The advantage of this is that matrices might have
optimized methods for these functions.
We still loop over the entire matrix for `StridedMatrix`es as before,
and obtain the structure in one-pass. The performance therefore isn't
impacted in this case.
An example with a sparse array wrapper:
```julia
julia> using LinearAlgebra
julia> struct MyMatrix{T,M<:AbstractMatrix{T}} <: AbstractMatrix{T}
A::M
end
julia> Base.size(M::MyMatrix) = size(M.A)
julia> Base.getindex(M::MyMatrix, i::Int, j::Int) = M.A[i, j]
julia> LinearAlgebra.istriu(M::MyMatrix, k::Integer=0) = istriu(M.A, k)
julia> LinearAlgebra.istril(M::MyMatrix, k::Integer=0) = istril(M.A, k)
julia> LinearAlgebra.issymmetric(M::MyMatrix) = issymmetric(M.A)
julia> LinearAlgebra.ishermitian(M::MyMatrix) = ishermitian(M.A)
julia> using SparseArrays
julia> S = sparse(1:4000, 1:4000, 1:4000);
julia> M = MyMatrix(S);
julia> @Btime factorize($M);
178.231 ms (4 allocations: 31.34 KiB) # master
22.165 ms (10 allocations: 94.04 KiB) # this PR
```
0 commit comments