Skip to content

Ensure no sharing of data in LQ gauge fixing#219

Merged
lkdvos merged 1 commit intomainfrom
fixes
Apr 27, 2026
Merged

Ensure no sharing of data in LQ gauge fixing#219
lkdvos merged 1 commit intomainfrom
fixes

Conversation

@lkdvos
Copy link
Copy Markdown
Member

@lkdvos lkdvos commented Apr 26, 2026

This fixes #218.

Somehow this slipped through the cracks, as I already addressed this issue for QR (

# we need to first copy then gaugefix - avoiding aliasing between R and Rd for broadcast
Rd = diagview(A)
Rf = pivoted ? view(R, :, jpvt) : R
copyto!(Rf, uppertriangular!(view(A, axes(R)...)))
positive && gaugefix!(qr_householder!, Q, Rf, Rd)
) but forgot to also add it in LQ.
The issue being that L .*= sign_safe.(diagview(L)) does not give correct results since L and diagview(L) share data in a non-trivial way.

Interestingly, broadcasting Base Array and views thereof detect this and make preventive copies, while JLArray does not have this behavior.
(I'm guessing there is some dataids overload missing or something for that to work):

julia> A = -jl(ones(3, 3))
3×3 JLArray{Float64, 2}:
 -1.0  -1.0  -1.0
 -1.0  -1.0  -1.0
 -1.0  -1.0  -1.0

julia> A .*= sign.(view(A, 1:4:9))
3×3 JLArray{Float64, 2}:
 1.0  -1.0  -1.0
 1.0   1.0  -1.0
 1.0   1.0   1.0

julia> B = -ones(3, 3)
3×3 Matrix{Float64}:
 -1.0  -1.0  -1.0
 -1.0  -1.0  -1.0
 -1.0  -1.0  -1.0

julia> B .*= sign.(view(B, 1:4:9))
3×3 Matrix{Float64}:
 1.0  1.0  1.0
 1.0  1.0  1.0
 1.0  1.0  1.0

In any case, this fix should now ensure correct results for JLArray's and one fewer allocation for regular Arrays.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/implementations/lq.jl 93.61% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos lkdvos changed the title ensure no sharing of data in LQ gauge fixing Ensure no sharing of data in LQ gauge fixing Apr 26, 2026
mtfishman added a commit to ITensor/BlockSparseArrays.jl that referenced this pull request Apr 26, 2026
Convert the rest of the `@test_broken` calls in `test_basics.jl` and
`test_map.jl` to the `broken = ...` keyword form, fold the surviving
`if arrayt === Array; ...; else; @test_broken ...; end` pair in
`test_map.jl` into a single `@test ... broken = arrayt ≢ Array`, and
drop the now-unused `@test_broken` import from `test_genericblockindex.jl`
and `test_tensoralgebraext.jl`.

Also gate the LQ regression broken marker in `test_abstract_blocktype.jl`
on `pkgversion(MatrixAlgebraKit) < v"0.6.7"` so the marker auto-disables
once the upstream LQ gauge-fixing fix lands in MatrixAlgebraKit 0.6.7
(QuantumKitHub/MatrixAlgebraKit.jl#219).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lkdvos lkdvos requested a review from Jutho April 27, 2026 00:35
@lkdvos lkdvos enabled auto-merge (squash) April 27, 2026 00:35
@lkdvos lkdvos merged commit 5ffd58e into main Apr 27, 2026
10 checks passed
@lkdvos lkdvos deleted the fixes branch April 27, 2026 05:00
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.

Issue with LQ decomposition of JLMatrix in MatrixAlgebraKit v0.6.6

2 participants