Fix init_cacheval for SizedMatrix (StaticArrays.LU has no field factors)#1056
Merged
ChrisRackauckas merged 1 commit intoJun 21, 2026
Conversation
…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>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
init(LinearProblem(A, b))with aSizedMatrix(StaticArrays) throws onGenericLUFactorization(the default for small dense systems):#1038 ("Handle dense, contiguous non-
Arraymatrices (e.g. FixedSizeArray)") changedinit_cacheval(::GenericLUFactorization, ...)andinit_cacheval(::RFLUFactorization, ...)fromto
This assumes
lu_instancealways returns aLinearAlgebra.LU(fieldsfactors/ipiv/info). For aSizedMatrix,ArrayInterface.lu_instancereturns aStaticArrays.LU(fieldsL/U/p), soluinst.factorserrors.Fix
Guard the
LinearAlgebra.LUrebuild: whenlu_instancereturns something that is not aLinearAlgebra.LU(e.g. aStaticArrays.LU), return it as-is — the pre-#1038 behavior, which already carried aVectorpivot for these containers. TheFixedSizeArraycase from #1038 (wherelu_instancedoes return aLinearAlgebra.LUbut with a container-typed pivot) still takes the rebuild path, so its fix is preserved.Verification (local, Julia 1.10 and 1.12)
init(LinearProblem(SizedMatrix{9,9}, b))throwstype LU has no field factorson 3.85.2.init(LinearProblem(SizedMatrix, b))succeeds; a normalMatrixsolvestill returns the correct result.src/factorization.jl.This is the root cause of SciML/OrdinaryDiffEq.jl's
InterfaceIVmaster 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