Repository navigation
Make updated chainable to write along several axes - #179
Conversation
d2a3378 to
5bdc3a9
Compare
So far, updated writes along one axis and directly returns the updated tensor, so writing along several axes at once, e.g. a single entry, needs a manual read, modify and write back. updated now returns a TensorUpdate. Applied to a value, it returns the updated tensor as before, so existing code is unchanged. Its updated method takes a further selector, which allows chaining updates like chained select: t.updated(Axis[A].at(1)).updated(Axis[B].at(2))(3f) updates the entry at (1, 2). Each step reads the selection and writes it back, reusing select and updated. In the future, TensorUpdate could support other operations besides setting the values, such as adding them or taking minimums, like JAX's x.at[...].
5bdc3a9 to
8bf6930
Compare
|
I don't like how it reads Another approach would be renaming, maybe |
I agree that it is not optimal. and have as a shorthand the idea could still work. It would then be a lens like structure. |
|
|
Instead of having chained update, this commit introduces the method focus, which, like a lens, focuses on some parts of the tensor and eventually makes it possible to update, read, modify, ... the parts on which the focus was set.
|
The latest commit renames update to focus and incorporates what has been discussed. Changing the verb from |
Make updated chainable to write along several axes
So far, updated writes along one axis and directly returns the updated tensor, so writing along several axes at once, e.g. a single entry, needs a manual read, modify and write back.
updated now returns a TensorUpdate. Applied to a value, it returns the updated tensor as before, so existing code is unchanged. Its updated method takes a further selector, which allows chaining updates like chained select:
updates the entry at (1, 2).
In the future, TensorUpdate could support other operations besides setting the values, such as adding them or taking minimums, like JAX's x.at[...].