Skip to content

Commit a4c7ac9

Browse files
committed
Add reflected arithmetic and array operators
1 parent 8cef774 commit a4c7ac9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

arrayfire/array_api/_array_object.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,51 @@ def __matmul__(self, other: Array, /) -> Array:
193193
# TODO
194194
return NotImplemented
195195

196+
def __radd__(self, other: Array, /) -> Array:
197+
# TODO discuss either we need to support complex and bool as other input type
198+
"""
199+
Return other + self.
200+
"""
201+
return _process_c_function(other, self, backend.get().af_add)
202+
203+
def __rsub__(self, other: Array, /) -> Array:
204+
"""
205+
Return other - self.
206+
"""
207+
return _process_c_function(other, self, backend.get().af_sub)
208+
209+
def __rmul__(self, other: Array, /) -> Array:
210+
"""
211+
Return other * self.
212+
"""
213+
return _process_c_function(other, self, backend.get().af_mul)
214+
215+
def __rtruediv__(self, other: Array, /) -> Array:
216+
"""
217+
Return other / self.
218+
"""
219+
return _process_c_function(other, self, backend.get().af_div)
220+
221+
def __rfloordiv__(self, other: Array, /) -> Array:
222+
# TODO
223+
return NotImplemented
224+
225+
def __rmod__(self, other: Array, /) -> Array:
226+
"""
227+
Return other / self.
228+
"""
229+
return _process_c_function(other, self, backend.get().af_mod)
230+
231+
def __rpow__(self, other: Array, /) -> Array:
232+
"""
233+
Return other ** self.
234+
"""
235+
return _process_c_function(other, self, backend.get().af_pow)
236+
237+
def __rmatmul__(self, other: Array, /) -> Array:
238+
# TODO
239+
return NotImplemented
240+
196241
def __getitem__(self, key: int | slice | tuple[int | slice] | Array, /) -> Array:
197242
# TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array
198243
# TODO: refactor

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy