Skip to content

Add cheap lu_instance/qr_instance for FixedSizeArrays - #511

Open
devmotion wants to merge 1 commit into
JuliaArrays:masterfrom
devmotion:dmw/fixedsizearrays-instances
Open

devmotion wants to merge 1 commit into
JuliaArrays:masterfrom
devmotion:dmw/fixedsizearrays-instances

Conversation

@devmotion

Copy link
Copy Markdown

Fixes #510.

lu_instance and qr_instance had cheap methods only for Matrix. A FixedSizeMatrix went through the generic fallback and ran a full factorization. LinearSolve's init calls these, so building a cache was about 50× slower than for a Matrix.

Changes

  • Adds the extension FixedSizeArraysExt, which defines lu_instance and qr_instance for FixedSizeMatrix. Both factorize an empty similar(A, 0, 0) instead of A.
    • The real factorization types vary by eltype. For example, BigFloat gets Vector pivots and a QR instead of a QRCompactWY. Factorizing an empty matrix gives exactly the type of the real factorization, so these cases need no special handling.
    • qr_instance passes pivot on to qr. The generic fallback ignores it.
  • Adds FixedSizeArrays as a weak dependency and test dependency with compat "1".
  • Adds test/fixedsizearrays.jl. It checks Float64, Float32, ComplexF64, Int and BigFloat, with and without ColumnNorm(). Each test checks that the instance has the same type as the real factorization and that its factors are 0×0.

Benchmarks

64×64 FixedSizeMatrix{Float64}, Julia 1.13.1, FixedSizeArrays 1.3.0, Chairmarks @b:

before (full factorization) after
lu_instance(F) 19.3 μs, 3 allocs, 32.6 KiB 16 ns, 0 allocs
qr_instance(F) 50.5 μs, 6 allocs, 72.1 KiB 18 ns, 0 allocs

The Core test group passes locally, including Aqua.

🤖 Generated with Claude Code

Previously `lu_instance` and `qr_instance` fell back to a full
factorization for `FixedSizeMatrix`. The new `FixedSizeArraysExt`
factorizes an empty `similar(A, 0, 0)` instead, which matches the
factorization types for all eltypes (including BigFloat) and pivot modes.

Fixes JuliaArrays#510

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lu_instance/qr_instance run a full factorization for FixedSizeArrays

1 participant