A better syntax for using ufunc.at?
![](https://secure.gravatar.com/avatar/5139266e34ce75eac313a59f45be9fa1.jpg?s=120&d=mm&r=g)
I am aware that to do unbuffered addition operation, I can use `np.add.at` like this: ``` np.add.at(arr, idxs, vals) ``` I think this syntax looks a bit unnatural, and it is not obvious what it does at first glance. An idea I have is to use a custom accessor, like ``` arr.at[idxs] += vals # or arr.unbuffered[idxs] += vals ``` While I'm not fluent in Numpy's working mechanisms, this seems possible to implement by just having the method `.at`/`.unbuffered` return a reference to the original array with a special flag set, then make the `+=` operator, etc check this flag and use the unbuffered operation accordingly. Has this kind of feature been proposed at all? I did try to search Github and this mailing list for something similar, but I'm quite new to numpy development, so apologies in advance if this is not the right place to ask.
![](https://secure.gravatar.com/avatar/a2c1b891fe9dd5c60430e823bfe8c298.jpg?s=120&d=mm&r=g)
While not about exactly your proposed syntax, the discussion in https://github.com/data-apis/array-api/issues/609 is relevant. Cheers, Lucas
![](https://secure.gravatar.com/avatar/5139266e34ce75eac313a59f45be9fa1.jpg?s=120&d=mm&r=g)
This is interesting, thank you for pointing it out! Good to know this is not a Numpy-only problem, I guess lol. Though the proposed syntax looks similar to my idea, I believe they are talking about a different problem there relating to translating python code to an accelerated language. I simply want a `ndarray.at` to be a syntax sugar for accessing `ufunc.at` in a more readable way. But if that proposal goes through `at` probably won't be a good name anymore, haha.
![](https://secure.gravatar.com/avatar/5139266e34ce75eac313a59f45be9fa1.jpg?s=120&d=mm&r=g)
I can see that. I wanted to be more caught up with the discussions around this than anything else. Although I also have a lot of free time right now temporarily, and could make an attempt at implementing it. Is there any other channel I can get more feedback on this?
![](https://secure.gravatar.com/avatar/a2c1b891fe9dd5c60430e823bfe8c298.jpg?s=120&d=mm&r=g)
While not about exactly your proposed syntax, the discussion in https://github.com/data-apis/array-api/issues/609 is relevant. Cheers, Lucas
![](https://secure.gravatar.com/avatar/5139266e34ce75eac313a59f45be9fa1.jpg?s=120&d=mm&r=g)
This is interesting, thank you for pointing it out! Good to know this is not a Numpy-only problem, I guess lol. Though the proposed syntax looks similar to my idea, I believe they are talking about a different problem there relating to translating python code to an accelerated language. I simply want a `ndarray.at` to be a syntax sugar for accessing `ufunc.at` in a more readable way. But if that proposal goes through `at` probably won't be a good name anymore, haha.
![](https://secure.gravatar.com/avatar/5139266e34ce75eac313a59f45be9fa1.jpg?s=120&d=mm&r=g)
I can see that. I wanted to be more caught up with the discussions around this than anything else. Although I also have a lot of free time right now temporarily, and could make an attempt at implementing it. Is there any other channel I can get more feedback on this?
participants (3)
-
Dom Grigonis
-
Lucas Colley
-
Oras P.