Skip to content

Respect strong zero in axpby - #55

Merged
kshyatt merged 9 commits into
mainfrom
ksh/zero
Sep 21, 2026
Merged

kshyatt merged 9 commits into
mainfrom
ksh/zero

Conversation

@kshyatt

@kshyatt kshyatt commented Sep 19, 2026

Copy link
Copy Markdown
Member

This turned out to be the origin of a crazy NaN related bug in PEPSKit. The issue is that 0.0 * NaN = NaN, so when VI's strong zero Zero() is converted to 0.0 for the GPU-based axpby call, it actually gets turned into a weak zero. Not what you want! Adding a special path for this here avoids this problem. The NaNs can occur in the first place by initializing an array with undefs.

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/abstractarray.jl 98.41% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread test/complicated.jl
Comment thread test/simple.jl

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, the only thing I was wondering is if it would make sense to just remove these BLAS fallback definitions altogether. I don't know if there is any performance difference between axpy! and simple broadcasting?

As a sidenote, probably best to get this in before #54 and have a patch release before, in which case we can bump the version number in this PR already?

Comment thread src/abstractarray.jl
) where {T <: BlasFloat}
if β === One()
LinearAlgebra.axpy!(convert(T, α), x, y)
elseif β === Zero() || β === false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly confused you also added the === false branch here, does that effectively mean that we want to interpret false as a strong zero as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Julia false is always strong zero, I thought?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> 0.0 * NaN
NaN

julia> false * NaN
0.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know this 😆 I thought that was a BLAS-specific thing... In that case, ignore my comments :p

A different thing that just popped in my brain is whether it would make sense to replace these checks everywhere with isstrongzero and isstrongone, to enforce that this is handled consistently?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the strong zero check is only made here, so I don't know if it makes sense to create a whole new function for it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I was thinking about this is because we also use this downstream every now and again, e.g. https://github.com/QuantumKitHub/TensorOperations.jl/blob/ef937adcfa4e6bc4476f8197a62a2da45cf3b1d9/src/implementation/strided.jl#L142 where we actually turn every zero into a strong one, and I do like the idea of having this a bit more formalized/consistent. Does not have to be in this PR though!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might just merge this and tag then to keep stuff moving for the other PR

@kshyatt
kshyatt enabled auto-merge (squash) September 21, 2026 14:12
@lkdvos lkdvos mentioned this pull request Sep 21, 2026
@kshyatt
kshyatt merged commit bc15948 into main Sep 21, 2026
10 checks passed
@kshyatt
kshyatt deleted the ksh/zero branch September 21, 2026 14:19
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.

3 participants