-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix AbstractArrayStyle dimension promotion rule #35948
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
base: master
Are you sure you want to change the base?
fix AbstractArrayStyle dimension promotion rule #35948
Conversation
Hmm reading over the broadcasting API again maybe you can't just delete this function, its what provides the API described in the last paragraph there that lets you just define a Gonna mark this as draft and think about if there's a way to just do something smarter than |
1602a4a
to
b87102f
Compare
I think I've got the right solution now, which fixes the test from my OP while simultaneously not breaking any Base or StaticArrays tests (any other packages I should check?), plus I think the logic makes a decent bit of sense. Basically, instead of using From what I can tell inference is fine and the entire logic is optimized away at compile time, so I don't think there's runtime performance concerns. Ready for review from my end. |
Ah, this looks great! It's a good solution and huge bonus points for removing the certainly-erroneous @nanosoldier |
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. cc @maleadt |
Let me know if there's anything else that needs doing (I'm not really familiar with how to interpret the output of PkgEval). |
Another friendly ping? |
8e95bd0
to
7350228
Compare
I think this PR is actually still basically up to date. the conflict is cosmetic |
7350228
to
c0a1728
Compare
Just did my bi-decadal rebase of this PR onto master, lmk if anything else is needed 😅 (but seriously, I appreciate this is a hard one since it touches sooo much, happy to help in whatever way I can) I also checked StaticArrays, StructArrays, and ForwardDiff as some representative broadcast overloaders and didn't spot any new failures related to this PR (altho hard bc of other failures tbh) |
@nanosoldier |
The package evaluation job you requested has completed - possible new issues were detected. Report summary❗ Packages that crashed1 packages crashed only on the current version.
2 packages crashed on the previous version too. ✖ Packages that failed25 packages failed only on the current version.
1387 packages failed on the previous version too. ✔ Packages that passed tests17 packages passed tests only on the current version.
5236 packages passed tests on the previous version too. ~ Packages that at least loaded11 packages successfully loaded only on the current version.
2956 packages successfully loaded on the previous version too. ➖ Packages that were skipped altogether2 packages were skipped only on the current version.
920 packages were skipped on the previous version too. |
pretty clean, I think the
|
I'd bet they're somehow relying on the old broken API. I can take a look. |
There was a bug in Julia broadcasting rules fixed by JuliaLang/julia#35948, but that fix breaks a test here, since this package was inadvertantly relying on the old incorrect logic. This fixes this package, basically correctly implements the API, and doesn't break it on current Julia versions either.
Ok, submitted a PR to fix that package, the problem was indeed they we're using the API incorrectly but the bug fixed here was hiding that. |
awesome! I think my initial summary was wrong, and it looks like these are also some sources, so they're not all only from Tensorial.jl#250 now these are of course not all necessarily your responsibility to fix, it would probably be polite to notify the authors before "breaking" code, so it would be reasonable give it a few days to see if any of the package authors bite on the issue. the original if you are feeling generous, it might also be nice to add also a bit more docs about how exactly the |
There was a bug in Julia broadcasting rules fixed by JuliaLang/julia#35948, but that fix breaks a test here, since this package was inadvertantly relying on the old incorrect logic. This fixes this package, basically correctly implements the API, and doesn't break it on current Julia versions either.
I'm the author of one of the packages mentioned above (Modulo2.jl). What about updating the Julia documentation as part of this PR? I believe the current documentation doesn't mention that style constructors have to accept argument, see the example in the docstring for In contrast, the code in Lines 98 to 99 in 18d5ccd
A clarification would be most helpful. |
The Val argument stuff is described in the AbstractArrayStyle docstring, those are the only kind of styles that assume this functionally is present, with some further clarification here: https://docs.julialang.org/en/v1/manual/interfaces/#writing-binary-broadcasting-rules I haven't looked at your package yet so not sure if that answers everything. In terms of the StrideArrays PR, I only did the trivial rule where the dimensionally is the same since that was all that was needed to fix the tests and I wasn't familiar enough with the package so just decided to be safe. |
I suppose this PR does add a requirement that the trivial rule is defined where previously there was no requirement. I wonder if all those packages can simply be fixed by that? I can look. It may make sense to just define that one generically. |
@marius311 Thanks for the pointer to the documentation! I'm going to fix my package. |
given
I think this PR now requires a constructor on the parameterized type
where some packages had been previously defining (note the lack of
This is at least what looks to be the case for |
Neither master nor this PR will ever call: MyStyle(::Val{N}) where {N} = MyStyle{N}() They would only call this one: MyStyle{N}(::Val{N}) where {N} = MyStyle{N}() If package authors had implemented the first one, I think it was just a misreading of the docs or maybe they were using it themselves explicilty elsewhere. This PR does require the second form to be defined in more cases than before, but at the benefit of making the logic correct. |
The docstring for
which includes the |
Yea I would support changing that docstring to: MyArrayStyleDim{M}(::Val{N}) where {N,M} = MyArrayStyleDim{N}() I think it makes the docs clearer and also mirrors how DefaultArrayStyle itself is defined: Line 99 in f03e9c3
Although confusingly DefaultArrayStyle also expclitily defines the non-concrete version just above that line, but that definition I don't see how is ever called, at the very least its confirmed not covered by Julia's test, as expected. |
so how to progress? should we try removing |
The simple test I added,
fails on current master because the function which I deleted in this PR is doing a bit of type piracy, especially since its using
Base.typename
which means its assuming if thetypename
s of your custom style are the same, they differ only in dimensions, for which I don't think there's justification. This then breaksBroadcastStyle
rule resolution for your custom style if this is not the case.In terms of Base, the offending part of the deleted function is not covered in the tests, and once you delete that, its equivalent to just deleting the whole thing.
I checked by hand if this impacts StaticArrays.jl as a representative user of this API, and it only breaks one test,
which now returns a
SizedArray
as opposed to previously anSArray
. I think that can be easily fixed in StaticArrays, and it probably shouldn't have been relying on this hackytypename
thing anyway. If you guys give the go ahead here, I can do the StaticArrays fix too (as well as any other comments you may have).