-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
Showing
2 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters