Skip to content

Fix init_cacheval for SizedMatrix (StaticArrays.LU has no field factors)#1056

Merged
ChrisRackauckas merged 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:fix-sizedmatrix-genericlu-init-cacheval
Jun 21, 2026
Merged

Fix init_cacheval for SizedMatrix (StaticArrays.LU has no field factors)#1056
ChrisRackauckas merged 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:fix-sizedmatrix-genericlu-init-cacheval

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Problem

init(LinearProblem(A, b)) with a SizedMatrix (StaticArrays) throws on GenericLUFactorization (the default for small dense systems):

FieldError: type StaticArrays.LU has no field `factors`, available fields: `L`, `U`, `p`
  @ StaticArrays/src/lu.jl:20
init_cacheval(::GenericLUFactorization, A::SizedMatrix{9,9}, ...) @ LinearSolve/src/factorization.jl:346

#1038 ("Handle dense, contiguous non-Array matrices (e.g. FixedSizeArray)") changed init_cacheval(::GenericLUFactorization, ...) and init_cacheval(::RFLUFactorization, ...) from

return ArrayInterface.lu_instance(convert(AbstractMatrix, A)), ipiv

to

luinst = ArrayInterface.lu_instance(convert(AbstractMatrix, A))
return LinearAlgebra.LU(luinst.factors, ipiv, luinst.info), ipiv

This assumes lu_instance always returns a LinearAlgebra.LU (fields factors/ipiv/info). For a SizedMatrix, ArrayInterface.lu_instance returns a StaticArrays.LU (fields L/U/p), so luinst.factors errors.

Fix

Guard the LinearAlgebra.LU rebuild: when lu_instance returns something that is not a LinearAlgebra.LU (e.g. a StaticArrays.LU), return it as-is — the pre-#1038 behavior, which already carried a Vector pivot for these containers. The FixedSizeArray case from #1038 (where lu_instance does return a LinearAlgebra.LU but with a container-typed pivot) still takes the rebuild path, so its fix is preserved.

luinst = ArrayInterface.lu_instance(convert(AbstractMatrix, A))
luinst isa LinearAlgebra.LU || return luinst, ipiv
return LinearAlgebra.LU(luinst.factors, ipiv, luinst.info), ipiv

Verification (local, Julia 1.10 and 1.12)

  • Before: init(LinearProblem(SizedMatrix{9,9}, b)) throws type LU has no field factors on 3.85.2.
  • After (this branch, dev'd): init(LinearProblem(SizedMatrix, b)) succeeds; a normal Matrix solve still returns the correct result.
  • Runic clean on src/factorization.jl.

This is the root cause of SciML/OrdinaryDiffEq.jl's InterfaceIV master CI failure (sized_matrix_tests.jl, Rodas4 on a SizedMatrix), which OrdinaryDiffEq is temporarily working around by capping LinearSolve at 3.85.1.

Please ignore until reviewed by @ChrisRackauckas

…rays.LU)

PR SciML#1038 changed init_cacheval(::GenericLUFactorization/::RFLUFactorization)
to rebuild a LinearAlgebra.LU via `luinst.factors`/`luinst.info` so the
cacheval pivot slot type matches for non-Array dense containers
(e.g. FixedSizeArray). But ArrayInterface.lu_instance returns a
StaticArrays.LU (fields L/U/p, no factors/info) for a SizedMatrix, so
`luinst.factors` throws `type StaticArrays.LU has no field factors` and
init(LinearProblem(SizedMatrix, ...)) errors.

Guard the rebuild: when lu_instance does not return a LinearAlgebra.LU,
return it as-is (the pre-SciML#1038 behavior, which already carries a Vector
pivot). Preserves the FixedSizeArray fix while restoring SizedMatrix.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas marked this pull request as ready for review June 21, 2026 11:01
@ChrisRackauckas ChrisRackauckas merged commit 01e6e63 into SciML:main Jun 21, 2026
49 of 57 checks passed
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.

2 participants