Skip to content

Disambiguate *(::AbstractMatrix, ::AbstractNoTimeSolution) against LinearAlgebra/StaticArrays - #1365

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-staticarrays-mul-ambiguity
May 26, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-staticarrays-mul-ambiguity

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented May 26, 2026 •

Copy link
Copy Markdown
Member

Note

Please ignore this PR until reviewed by @ChrisRackauckas.

Summary

The broad

Base.:*(A::AbstractMatrix, sol::AbstractNoTimeSolution) = A * sol.u

method introduced in #1363 has ambiguities with LinearAlgebra's specialized * methods (Diagonal, AbstractTriangular, Adjoint/Transpose-of-vector) and with StaticArrays' *(::StaticMatrix, ::AbstractVecOrMat). These surface as:

  • Aqua detect_ambiguities(SciMLBase) failures on master (Tests / QA, both Julia 1.10 lts and 1.12)
  • MethodError: ... is ambiguous in LinearSolve.jl's test/nopre/static_arrays.jl

Per discussion, we want to keep the broad overload (the AbstractArray fallback is slow because every getindex goes through the solution wrapper) and just disambiguate.

Approach

In src/solutions/solution_interface.jl, add per-conflict disambiguators that all forward to A * sol.u, preserving the LinearAlgebra fast paths:

Base.:*(A::Diagonal, sol::AbstractNoTimeSolution) = A * sol.u
Base.:*(A::AbstractTriangular, sol::AbstractNoTimeSolution) = A * sol.u

# covector * matrix-shape sol
Base.:*(A::Adjoint{<:Any, <:AbstractVector},   sol::AbstractNoTimeSolution{<:Any, 2}) = A * sol.u
Base.:*(A::Transpose{<:Any, <:AbstractVector}, sol::AbstractNoTimeSolution{<:Any, 2}) = A * sol.u

# covector * vector-shape sol (dot product); Union form covers lib's Union method 9
Base.:*(A::Union{Adjoint{<:Any, <:AbstractVector}, Transpose{<:Any, <:AbstractVector}},
        sol::AbstractNoTimeSolution{<:Any, 1}) = A * sol.u

# tighter element-type variants for lib's Number / Real specializations
Base.:*(A::Adjoint{<:Number, <:AbstractVector},  sol::AbstractNoTimeSolution{<:Number, 1}) = A * sol.u
Base.:*(A::Transpose{T, <:AbstractVector},       sol::AbstractNoTimeSolution{T, 1}) where {T<:Real} = A * sol.u

And a new SciMLBaseStaticArraysExt extension that adds:

Base.:*(A::StaticMatrix, sol::AbstractNoTimeSolution) = A * sol.u

The extension only loads when StaticArrays is loaded, so users not using static arrays pay nothing.

Verification

Local, both Julia 1.10 (LTS) and 1.12:

julia> using SciMLBase, Test
julia> Test.detect_ambiguities(SciMLBase)
0-element Vector{Tuple{Method, Method}}

Local include("test/solution_interface.jl") — all testsets pass, including the new 8-test "A * sol for AbstractNoTimeSolution" testset that exercises:

  • dense Matrix * sol
  • Diagonal * sol, LowerTriangular * sol, UpperTriangular * sol
  • v' * sol, transpose(v) * sol
  • SMatrix * sol (LinearSolve regression)

Files changed

  • src/solutions/solution_interface.jl — 7 LinearAlgebra disambiguators
  • ext/SciMLBaseStaticArraysExt.jl (new) — 1-method StaticMatrix disambiguator
  • Project.toml — StaticArrays weakdep + extension entry; version 3.15.0 → 3.15.1
  • test/solution_interface.jl — regression testset

Test plan

  • Wait for CI
  • Confirm LinearSolve.jl test/nopre/static_arrays.jl passes against this branch

…tractNoTimeSolution)`

After SciML#1363 added `Base.:*(A::AbstractMatrix, sol::AbstractNoTimeSolution) = A * sol.u`,
LinearSolve's `test/nopre/static_arrays.jl` started failing with a MethodError ambiguity
between that method and StaticArrays' `*(::StaticMatrix, ::AbstractVector)`. This adds
a weakdep extension on StaticArrays that defines the disambiguating method
`*(::StaticMatrix, ::AbstractNoTimeSolution{<:Any, 1})`, which Julia's dispatcher
selects unambiguously.

Co-Authored-By: Chris Rackauckas <[email protected]>
…oTimeSolution)`

The broad `*(A::AbstractMatrix, sol::AbstractNoTimeSolution) = A * sol.u`
method introduced in SciML#1363 had unresolved ambiguities with LinearAlgebra's
specialized methods (Diagonal, AbstractTriangular, Adjoint/Transpose-of-vector)
that surfaced as Aqua `detect_ambiguities` failures and a MethodError in
LinearSolve.jl's static_arrays test.

Add disambiguators in solution_interface.jl that forward each conflicting
signature to `A * sol.u`, preserving the LinearAlgebra fast paths. Also
broaden the StaticArrays extension to cover both N=1 and N=2 sol shapes
(StaticMatrix * AbstractMatrix exists in StaticArrays too).

Verified locally: `Test.detect_ambiguities(SciMLBase)` returns empty on both
Julia 1.10 and 1.12 with these methods.

Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title Add SciMLBaseStaticArraysExt to fix StaticMatrix * AbstractNoTimeSolution ambiguity Disambiguate *(::AbstractMatrix, ::AbstractNoTimeSolution) against LinearAlgebra/StaticArrays May 26, 2026
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review May 26, 2026 21:53
@ChrisRackauckas
ChrisRackauckas merged commit 3bb591a into SciML:master May 26, 2026
43 of 60 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request May 26, 2026
Empty commit to nudge GitHub to refresh PR SciML#1365 head — webhook didn't fire
for the previous runic-fix push.

Co-Authored-By: Chris Rackauckas <[email protected]>
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