-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make array isapprox
more generic by avoiding zip/explicit iteration
#44893
Conversation
(There's been some discussion of a short-circuiting |
ae0e9be
to
53874b0
Compare
Thanks, that's what I figured as well. I rolled back the unrelated |
Floating-point exceptions are slow. |
Can you double-check that we have test coverage for this case? |
What confuses me is that I'll take a closer look at the tests. |
If I understand the tools correctly, this branch was hit by 150 tests in the last coveralls build: https://coveralls.io/builds/45390050/source?filename=stdlib%2FLinearAlgebra%2Fsrc%2Fgeneric.jl#L1680. It's specifically targeted by the following test: https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/test/generic.jl#L407-L409 (I now realize that this line has been up for debate before: #17658) |
Bump to maybe get this in by the 1.9 feature freeze? I don't know what's causing the test failure, I can't seem to be able to read the log. Rebasing to re-trigger CI and see what happens. |
This is more generic and works for, e.g., gpu arrays
Co-authored-by: Steven G. Johnson <[email protected]>
10f5927
to
1e30a85
Compare
The buildbot log says |
Since @stevengj approved and tests passes I'll merge this. |
Hi all, I was going to raise an issue but figured I might as well frame it in terms of a proposed solution.
I stumbled upon a case where I couldn't
isapprox
two GPU arrays because they hit thiszip
trying to pull elements one by one. Usingmapreduce
instead should fix the problem for these and any other array types that don't like sequential iteration.The drawback is that this hurts performance for regular CPU arrays (#38558). The slowdown is worse in cases that admit an early short-circuit:
However, note that:
So maybe a temporary slowdown (until
mapreduce
is improved) in this exceptional branch is an acceptable price to pay for more generic code? That way GPUArrays.jl won't have to duplicate the entire method just to change one line.Bonus: somemapreduce
calls ingeneric_norm
are really just straightforward applications ofminimum/maximum/sum
, so I rewrote them as such for improved clarity. The behavior should be unchanged. Since this change also concerns reductions in generic linear algebra routines I thought a single PR might suffice even if this is really a separate issue.About tests
isapprox
isn't explicitly tested on arrays. On the other hand, it's the foundation for almost every other test, so in that sense, it's very thoroughly tested.Thegeneric_norm
rewrites shouldn't change behavior, so existing tests should suffice.EDIT: rolled back the mapreduce simplifications in
norm
since they trigger #44906 and are unrelated to the main issue here.