23
23
from .dtypes import uint64 as af_uint64
24
24
25
25
ShapeType = tuple [int , ...]
26
- _bcast_var = False # HACK, TODO replace for actual bcast_var after refactoring
26
+ # HACK, TODO replace for actual bcast_var after refactoring ~ https://github.com/arrayfire/arrayfire/pull/2871
27
+ _bcast_var = False
28
+
29
+ # TODO use int | float in operators -> remove bool | complex support
27
30
28
31
29
32
@dataclass
@@ -33,12 +36,6 @@ class _ArrayBuffer:
33
36
34
37
35
38
class Array :
36
- # Numpy checks this attribute to know which class handles binary builtin operations, such as __add__.
37
- # Setting to such a high value should make sure that arrayfire has priority over
38
- # other classes, ensuring that e.g. numpy.float32(1)*arrayfire.randu(3) is handled by
39
- # arrayfire's __radd__() instead of numpy's __add__()
40
- __array_priority__ = 30 # TODO discuss its purpose
41
-
42
39
def __init__ (
43
40
self , x : None | Array | py_array .array | int | ctypes .c_void_p | list = None ,
44
41
dtype : None | Dtype | str = None , shape : None | ShapeType = None ,
@@ -164,7 +161,6 @@ def __neg__(self) -> Array:
164
161
return 0 - self # type: ignore[no-any-return, operator] # FIXME
165
162
166
163
def __add__ (self , other : int | float | Array , / ) -> Array :
167
- # TODO discuss either we need to support complex and bool as other input type
168
164
"""
169
165
Calculates the sum for each element of an array instance with the respective element of the array other.
170
166
@@ -300,21 +296,13 @@ def __pow__(self, other: int | float | Array, /) -> Array:
300
296
out : Array
301
297
An array containing the element-wise results. The returned array must have a data type determined
302
298
by Type Promotion Rules.
303
-
304
- Note
305
- ----
306
- - If both self and other have integer data types, the result of __pow__ when other_i is negative
307
- (i.e., less than zero) is unspecified and thus implementation-dependent.
308
- If self has an integer data type and other has a floating-point data type, behavior is
309
- implementation-dependent, as type promotion between data type “kinds” (e.g., integer versus floating-point)
310
- is unspecified.
311
299
"""
312
300
return _process_c_function (self , other , backend .get ().af_pow )
313
301
314
302
# Array Operators
315
303
316
304
def __matmul__ (self , other : Array , / ) -> Array :
317
- # TODO
305
+ # TODO get from blas - make vanilla version and not copy af.matmul as is
318
306
return NotImplemented
319
307
320
308
# Bitwise Operators
@@ -508,7 +496,7 @@ def __rfloordiv__(self, other: Array, /) -> Array:
508
496
509
497
def __rmod__ (self , other : Array , / ) -> Array :
510
498
"""
511
- Return other / self.
499
+ Return other % self.
512
500
"""
513
501
return _process_c_function (other , self , backend .get ().af_mod )
514
502
@@ -534,7 +522,7 @@ def __rand__(self, other: Array, /) -> Array:
534
522
535
523
def __ror__ (self , other : Array , / ) -> Array :
536
524
"""
537
- Return other & self.
525
+ Return other | self.
538
526
"""
539
527
return _process_c_function (other , self , backend .get ().af_bitor )
540
528
@@ -648,7 +636,7 @@ def __array_namespace__(self, *, api_version: None | str = None) -> Any:
648
636
return NotImplemented
649
637
650
638
def __bool__ (self ) -> bool :
651
- # TODO
639
+ # TODO consider using scalar() and is_scalar()
652
640
return NotImplemented
653
641
654
642
def __complex__ (self ) -> complex :
@@ -668,7 +656,7 @@ def __float__(self) -> float:
668
656
return NotImplemented
669
657
670
658
def __getitem__ (self , key : int | slice | tuple [int | slice ] | Array , / ) -> Array :
671
- # TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array
659
+ # TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array - consider using af.span
672
660
# TODO: refactor
673
661
out = Array ()
674
662
ndims = self .ndim
0 commit comments