Skip to content

DArray: Fix \ returning a dense array on Julia 1.14+ - #787

Open
SwayamBorateIIT wants to merge 1 commit into
JuliaParallel:masterfrom
SwayamBorateIIT:fix-zeros-factorization-signature
Open

SwayamBorateIIT wants to merge 1 commit into
JuliaParallel:masterfrom
SwayamBorateIIT:fix-zeros-factorization-signature

Conversation

@SwayamBorateIIT

@SwayamBorateIIT SwayamBorateIIT commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

\ on a DMatrix factorization returns a dense Array on Julia 1.14 and
nightly, instead of a DArray. This is the cause of the nightly and pre
CI failures listed in #786.

What happens

src/array/alloc.jl overloads LinearAlgebra._zeros so that the generic
ldiv(F, B) behind \ stages its right-hand side into a DArray instead of
a dense buffer. Upstream changed that function's third argument:

# <= 1.13
_zeros(::Type{T}, b::AbstractVector, n::Integer)
# >= 1.14, via JuliaLang/LinearAlgebra.jl#1746
_zeros(::Type{T}, B::AbstractVecOrMat, F::Factorization)

Both Dagger overloads take n::Integer, so on 1.14+ neither matches any
longer. Nothing errors and nothing warns -- \ just falls through to the
generic method, allocates with zeros(...), and returns an Array. The
result is numerically correct but no longer distributed, so it does not answer
to wait, which is how CI finds it:

Steady-state allocations: Error During Test at test/allocations.jl:173
  MethodError: no method matching wait(::Vector{Float64})
  @ Main test/allocations.jl:214        # wait(cholesky(A) \ b)

The change

Four lines: the new signature defined beside the old one, forwarding to it.
Upstream's _ret_size(F, B) computes exactly what the existing methods
compute from size(F, 2), so forwarding avoids duplicating that arithmetic
and avoids hooking a second internal that could move the same way. Whichever
signature the running Julia does not use is never called, so one source serves
1.10 through nightly with no version check.

Plus a regression test. Every existing test in test/array/linalg/solve.jl
calls ldiv! directly and so never reaches _zeros -- which is why this
shipped unnoticed. The new assertions go through \ itself, with both vector
and matrix right-hand sides.

Only the factorizations that use the generic ldiv are affected, so in
practice Cholesky here (and QR, SVD, BunchKaufman, LQ). LU is not:
LinearAlgebra.ldiv(F::LU{T,<:DMatrix}, B) in src/array/linalg.jl stages
its own buffer and never calls _zeros. The lu assertions are included
anyway, so that removing that override cannot silently reintroduce this.

Verification

All on one Linux x86_64 machine, Julia 1.13.0 and 1.15.0-DEV (juliaup
nightly):

run Julia patch result
array/linalg/solve 1.13.0 applied 48 pass / 48
array/linalg/solve 1.15.0-DEV applied 48 pass / 48
array/linalg/solve 1.15.0-DEV reverted 36 pass, 8 fail, 4 error / 48
allocations 1.13.0 applied 25 pass / 25
allocations 1.15.0-DEV applied 25 pass / 25

Each version was run against a freshly instantiated test/ environment;
alternating two Julia versions against one test/Manifest.toml re-resolves the
stdlibs mid-sequence and produces spurious failures.

The third row is the negative control: with the test present and the fix
backed out, it fails, so the test does catch the bug rather than passing
vacuously.

cholesky + solve stays well inside its allocation bounds on both, and the
two versions agree closely:

            1.13.0   107251 allocs / 5.14 MiB      (bound 320000 / 14.31 MiB)
        1.15.0-DEV   105252 allocs / 5.04 MiB

Two things I did not verify

  • I did not read 1.14's LinearAlgebra source directly. The evidence that
    1.14 is affected is CI: the pre jobs report julia version 1.14.0-alpha2
    and fail with the identical MethodError. The source I compared was 1.13.0
    against 1.15.0-DEV.
  • The negative control's 12 failures break down as two failures and one error
    per loop iteration over four iterations. I confirmed X isa DMatrix{T} and
    x isa DVector{T} fail and wait(x) errors; I did not enumerate each one
    from the log individually.

One deliberate limitation: the staged buffer is still built with
auto_blocks, whose block size generally will not match F.factors, so the
re-blocking cost that the LU override exists to avoid still applies to a
Cholesky solve. Giving Cholesky the same ldiv override as LU would fix
both that and this bug more durably, and would drop one _zeros dependency.
I kept this change minimal because its purpose is to unbreak 1.14 and nightly;
happy to follow up with the override if you'd prefer it that way.


Written with Claude Code. I have read and understood the diff and ran every
row of the table above myself, including the negative control.

`src/array/alloc.jl` overloads `LinearAlgebra._zeros` so that the generic
`ldiv(F, B)` behind `\` stages its right-hand side into a `DArray` rather than
the dense `zeros(...)` buffer it would otherwise allocate.
JuliaLang/LinearAlgebra.jl#1746, shipped in Julia 1.14, changed that function's
third argument from the factorization's width to the factorization itself, so
both overloads stopped matching. Nothing errors and nothing warns: `\` falls
through to the generic method and silently returns an `Array`, so a solve
against a `DMatrix` loses its distribution and the result no longer answers to
`wait`.

Define the new signature alongside the old one, forwarding to it so the size
arithmetic is not duplicated -- upstream's `_ret_size(F, B)` computes exactly
what the existing methods compute from `size(F, 2)`. Whichever signature the
running Julia does not use is simply never called, so one source serves the
whole supported range from 1.10 up.

The existing solve tests all call `ldiv!` directly and so never reach
`_zeros`, which is why this went unnoticed; the failure surfaced two
testsuites away, as `MethodError: no method matching wait(::Vector{Float64})`
at `test/allocations.jl:214`. Assert on `\` itself instead, for `cholesky` and
`lu` with both vector and matrix right-hand sides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XsjCQbwr3mFza8CTCW9f7Q
@SwayamBorateIIT

Copy link
Copy Markdown
Contributor Author

CI's nightly and pre jobs are still red here, but for a different reason
than on master, so it's worth spelling out.

The MethodError: no method matching wait(::Vector{Float64}) this PR targets
is gone — zero occurrences in the nightly log, and allocations now reports
25 pass / 25.

What's blocking those jobs now is the next failure along. test/runtests.jl
wraps its loop in try ... catch; rethrow(), so the first failing file aborts
the whole run, and ("Allocations", "allocations.jl") is the first entry in
that list. On master's nightly that meant one test file ran and 40-odd never
did:

nightly run test files completed allocations
master (d74b4c53) 1 error at allocations.jl:173
this PR 17 25 pass / 25

So the suite now gets as far as array/allocation, which was unreachable
before, and fails there:

distribute: Error During Test at test/array/allocation.jl:134
  MethodError: getindex(::SparseMatrixCSC{Float64, Int64}, ::ArrayDomain{2,...}) is ambiguous.
  Candidates:
    getindex(A::AbstractSparseMatrixCSC{Tv, Ti}, I...)  @ SparseArrays .../v1.15/SparseArrays/src/indexing.jl:38
    getindex(arr::AbstractArray, d::ArrayDomain)        @ Dagger src/array/darray.jl:35

That's an ambiguity between SparseArrays and src/array/darray.jl:35, on
the distribute(::SparseMatrixCSC) path — nothing this PR touches. It just
wasn't reachable while allocations was dying first. Julia prints the fix it
wants in the error itself, so it looks like a small separate change; happy to
open one if you'd like, rather than widening this PR.

The other failures here (custom_actions, DaggerWebDash, 1.11 (Finch),
1.11 - ubuntu, the macOS multithreaded job, the GPU backends and one
benchmark metric) are the ones already written up in #786. custom_actions is
new since that issue though — Julia 1.9.4 stopped loading libopenlibm.so on
current runners, and it fails on #777 and #782 as well.

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.

1 participant