-
Notifications
You must be signed in to change notification settings - Fork 310
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
and_broadcast_mut for Zip #478
Comments
Broadcasting isn't compatible with mutable access in general. We can use a Vec or 1D array as a model for this. We assume throughout the code that if the element index is different, two mutable references to elements are not aliasing, so we can modify though both paths. This breaks if we have mutable broadcasting. It could only be allowed if we imposed something like the access pattern of a Which brings a "solution": If an |
In short: .and_broadcast_cell ? Or General ArrayViewMut -> ArrayView of Cells? One cool fact is that the non-parallelization should work itself out automatically by the Send/Sync traits; when the Zip contains a Cell, the compiler will disallow thread parallelism. |
I think |
We should be able to start with just an I guess there is a chance these methods are being held back for technical or "unsafe code guidelines/formalization" reasons upstream. I can't spot any discussion along those lines though. The |
. o O ( So what if there's an arithmetic compatible transparent wrapper type around Cell ) |
I think the |
I wonder, after we start supporting Cell there will be a want for supporting something that wraps Cell (with the same features) that also supports arithmetic. So that it can participate in operations like |
Currently Zip has no mutable equivalent for the
and_broadcast
method, which is presumably to allow it to safely besplit()
and parallelized. However this makes some calculations difficult. The examples below are for backprop through a broadcast-able element-wise multiplication, but the problem appears as a pattern often.Currently I'm looking at using this:
which works correctly, but also has UB written all over it depending on how Zip is implemented internally (I realize Zip owes me nothing here).
The safe alternative I've found is:
which is catastrophically (over 30x) slower for some cases.
So my questions are:
and_broadcast_mut()
method which would set a flag or something which makessplit()
panic?The text was updated successfully, but these errors were encountered: