Repository navigation
DArray: Fix \ returning a dense array on Julia 1.14+ - #787
SwayamBorateIIT wants to merge 1 commit into
Conversation
`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
|
CI's The What's blocking those jobs now is the next failure along.
So the suite now gets as far as That's an ambiguity between The other failures here ( |
\on aDMatrixfactorization returns a denseArrayon Julia 1.14 andnightly, instead of a
DArray. This is the cause of thenightlyandpreCI failures listed in #786.
What happens
src/array/alloc.jloverloadsLinearAlgebra._zerosso that the genericldiv(F, B)behind\stages its right-hand side into aDArrayinstead ofa dense buffer. Upstream changed that function's third argument:
Both Dagger overloads take
n::Integer, so on 1.14+ neither matches anylonger. Nothing errors and nothing warns --
\just falls through to thegeneric method, allocates with
zeros(...), and returns anArray. Theresult is numerically correct but no longer distributed, so it does not answer
to
wait, which is how CI finds it: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 methodscompute from
size(F, 2), so forwarding avoids duplicating that arithmeticand 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.jlcalls
ldiv!directly and so never reaches_zeros-- which is why thisshipped unnoticed. The new assertions go through
\itself, with both vectorand matrix right-hand sides.
Only the factorizations that use the generic
ldivare affected, so inpractice
Choleskyhere (andQR,SVD,BunchKaufman,LQ).LUis not:LinearAlgebra.ldiv(F::LU{T,<:DMatrix}, B)insrc/array/linalg.jlstagesits own buffer and never calls
_zeros. Theluassertions are includedanyway, 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 (
juliaupnightly):
array/linalg/solvearray/linalg/solvearray/linalg/solveallocationsallocationsEach version was run against a freshly instantiated
test/environment;alternating two Julia versions against one
test/Manifest.tomlre-resolves thestdlibs 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 + solvestays well inside its allocation bounds on both, and thetwo versions agree closely:
Two things I did not verify
LinearAlgebrasource directly. The evidence that1.14 is affected is CI: the
prejobs reportjulia version 1.14.0-alpha2and fail with the identical
MethodError. The source I compared was 1.13.0against 1.15.0-DEV.
per loop iteration over four iterations. I confirmed
X isa DMatrix{T}andx isa DVector{T}fail andwait(x)errors; I did not enumerate each onefrom the log individually.
One deliberate limitation: the staged buffer is still built with
auto_blocks, whose block size generally will not matchF.factors, so there-blocking cost that the
LUoverride exists to avoid still applies to aCholeskysolve. GivingCholeskythe sameldivoverride asLUwould fixboth that and this bug more durably, and would drop one
_zerosdependency.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.