Skip to content

Commit 07c4206

Browse files
committed
Add docstrings for other operators. Remove docstrings from mocks
1 parent 0231e27 commit 07c4206

File tree

4 files changed

+161
-198
lines changed

4 files changed

+161
-198
lines changed

arrayfire/array_api/array_object.py

Lines changed: 154 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def __and__(self, other: int | bool | Array, /) -> Array:
334334
----------
335335
self : Array
336336
Array instance. Should have a numeric data type.
337-
other: int | float | Array
337+
other: int | bool | Array
338338
Other array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
339339
340340
Returns
@@ -354,7 +354,7 @@ def __or__(self, other: int | bool | Array, /) -> Array:
354354
----------
355355
self : Array
356356
Array instance. Should have a numeric data type.
357-
other: int | float | Array
357+
other: int | bool | Array
358358
Other array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
359359
360360
Returns
@@ -374,7 +374,7 @@ def __xor__(self, other: int | bool | Array, /) -> Array:
374374
----------
375375
self : Array
376376
Array instance. Should have a numeric data type.
377-
other: int | float | Array
377+
other: int | bool | Array
378378
Other array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
379379
380380
Returns
@@ -394,7 +394,7 @@ def __lshift__(self, other: int | Array, /) -> Array:
394394
----------
395395
self : Array
396396
Array instance. Should have a numeric data type.
397-
other: int | float | Array
397+
other: int | Array
398398
Other array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
399399
Each element must be greater than or equal to 0.
400400
@@ -414,7 +414,7 @@ def __rshift__(self, other: int | Array, /) -> Array:
414414
----------
415415
self : Array
416416
Array instance. Should have a numeric data type.
417-
other: int | float | Array
417+
other: int | Array
418418
Other array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
419419
Each element must be greater than or equal to 0.
420420
@@ -429,44 +429,121 @@ def __rshift__(self, other: int | Array, /) -> Array:
429429

430430
def __lt__(self, other: int | float | Array, /) -> Array:
431431
"""
432-
Return self < other.
432+
Computes the truth value of self_i < other_i for each element of an array instance with the respective
433+
element of the array other.
434+
435+
Parameters
436+
----------
437+
self : Array
438+
Array instance. Should have a numeric data type.
439+
other: int | float | Array
440+
Other array. Must be compatible with self (see Broadcasting). Should have a real-valued data type.
441+
442+
Returns
443+
-------
444+
out : Array
445+
An array containing the element-wise results. The returned array must have a data type of bool.
433446
"""
434447
return _process_c_function(self, other, backend.get().af_lt)
435448

436449
def __le__(self, other: int | float | Array, /) -> Array:
437450
"""
438-
Return self <= other.
451+
Computes the truth value of self_i <= other_i for each element of an array instance with the respective
452+
element of the array other.
453+
454+
Parameters
455+
----------
456+
self : Array
457+
Array instance. Should have a numeric data type.
458+
other: int | float | Array
459+
Other array. Must be compatible with self (see Broadcasting). Should have a real-valued data type.
460+
461+
Returns
462+
-------
463+
out : Array
464+
An array containing the element-wise results. The returned array must have a data type of bool.
439465
"""
440466
return _process_c_function(self, other, backend.get().af_le)
441467

442468
def __gt__(self, other: int | float | Array, /) -> Array:
443469
"""
444-
Return self > other.
470+
Computes the truth value of self_i > other_i for each element of an array instance with the respective
471+
element of the array other.
472+
473+
Parameters
474+
----------
475+
self : Array
476+
Array instance. Should have a numeric data type.
477+
other: int | float | Array
478+
Other array. Must be compatible with self (see Broadcasting). Should have a real-valued data type.
479+
480+
Returns
481+
-------
482+
out : Array
483+
An array containing the element-wise results. The returned array must have a data type of bool.
445484
"""
446485
return _process_c_function(self, other, backend.get().af_gt)
447486

448487
def __ge__(self, other: int | float | Array, /) -> Array:
449488
"""
450-
Return self >= other.
489+
Computes the truth value of self_i >= other_i for each element of an array instance with the respective
490+
element of the array other.
491+
492+
Parameters
493+
----------
494+
self : Array
495+
Array instance. Should have a numeric data type.
496+
other: int | float | Array
497+
Other array. Must be compatible with self (see Broadcasting). Should have a real-valued data type.
498+
499+
Returns
500+
-------
501+
out : Array
502+
An array containing the element-wise results. The returned array must have a data type of bool.
451503
"""
452504
return _process_c_function(self, other, backend.get().af_ge)
453505

454506
def __eq__(self, other: int | float | bool | Array, /) -> Array: # type: ignore[override] # FIXME
455507
"""
456-
Return self == other.
508+
Computes the truth value of self_i == other_i for each element of an array instance with the respective
509+
element of the array other.
510+
511+
Parameters
512+
----------
513+
self : Array
514+
Array instance. Should have a numeric data type.
515+
other: int | float | bool | Array
516+
Other array. Must be compatible with self (see Broadcasting). May have any data type.
517+
518+
Returns
519+
-------
520+
out : Array
521+
An array containing the element-wise results. The returned array must have a data type of bool.
457522
"""
458523
return _process_c_function(self, other, backend.get().af_eq)
459524

460525
def __ne__(self, other: int | float | bool | Array, /) -> Array: # type: ignore[override] # FIXME
461526
"""
462-
Return self != other.
527+
Computes the truth value of self_i != other_i for each element of an array instance with the respective
528+
element of the array other.
529+
530+
Parameters
531+
----------
532+
self : Array
533+
Array instance. Should have a numeric data type.
534+
other: int | float | bool | Array
535+
Other array. Must be compatible with self (see Broadcasting). May have any data type.
536+
537+
Returns
538+
-------
539+
out : Array
540+
An array containing the element-wise results. The returned array must have a data type of bool.
463541
"""
464542
return _process_c_function(self, other, backend.get().af_neq)
465543

466544
# Reflected Arithmetic Operators
467545

468546
def __radd__(self, other: Array, /) -> Array:
469-
# TODO discuss either we need to support complex and bool as other input type
470547
"""
471548
Return other + self.
472549
"""
@@ -656,8 +733,24 @@ def __float__(self) -> float:
656733
return NotImplemented
657734

658735
def __getitem__(self, key: int | slice | tuple[int | slice] | Array, /) -> Array:
659-
# TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array - consider using af.span
660-
# TODO: refactor
736+
"""
737+
Returns self[key].
738+
739+
Parameters
740+
----------
741+
self : Array
742+
Array instance.
743+
key : int | slice | tuple[int | slice] | Array
744+
Index key.
745+
746+
Returns
747+
-------
748+
out : Array
749+
An array containing the accessed value(s). The returned array must have the same data type as self.
750+
"""
751+
# TODO
752+
# API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array.
753+
# consider using af.span to replace ellipsis during refactoring
661754
out = Array()
662755
ndims = self.ndim
663756

@@ -706,6 +799,14 @@ def to_device(self, device: Any, /, *, stream: None | int | Any = None) -> Array
706799

707800
@property
708801
def dtype(self) -> Dtype:
802+
"""
803+
Data type of the array elements.
804+
805+
Returns
806+
-------
807+
out : Dtype
808+
Array data type.
809+
"""
709810
out = ctypes.c_int()
710811
safe_call(backend.get().af_get_type(ctypes.pointer(out), self.arr))
711812
return _c_api_value_to_dtype(out.value)
@@ -724,29 +825,66 @@ def mT(self) -> Array:
724825
def T(self) -> Array:
725826
"""
726827
Transpose of the array.
828+
829+
Returns
830+
-------
831+
out : Array
832+
Two-dimensional array whose first and last dimensions (axes) are permuted in reverse order relative to
833+
original array. The returned array must have the same data type as the original array.
834+
835+
Note
836+
----
837+
- The array instance must be two-dimensional. If the array instance is not two-dimensional, an error
838+
should be raised.
727839
"""
840+
if self.ndim < 2:
841+
raise TypeError(f"Array should be at least 2-dimensional. Got {self.ndim}-dimensional array")
842+
843+
# TODO add check if out.dtype == self.dtype
728844
out = Array()
729-
# NOTE conj support is removed because it is never used
730845
safe_call(backend.get().af_transpose(ctypes.pointer(out.arr), self.arr, False))
731846
return out
732847

733848
@property
734849
def size(self) -> int:
850+
"""
851+
Number of elements in an array.
852+
853+
Returns
854+
-------
855+
out : int
856+
Number of elements in an array
857+
858+
Note
859+
----
860+
- This must equal the product of the array's dimensions.
861+
"""
735862
# NOTE previously - elements()
736863
out = c_dim_t(0)
737864
safe_call(backend.get().af_get_elements(ctypes.pointer(out), self.arr))
738865
return out.value
739866

740867
@property
741868
def ndim(self) -> int:
869+
"""
870+
Number of array dimensions (axes).
871+
872+
out : int
873+
Number of array dimensions (axes).
874+
"""
742875
out = ctypes.c_uint(0)
743876
safe_call(backend.get().af_get_numdims(ctypes.pointer(out), self.arr))
744877
return out.value
745878

746879
@property
747880
def shape(self) -> ShapeType:
748881
"""
749-
Return the shape of the array as a tuple.
882+
Array dimensions.
883+
884+
Returns
885+
-------
886+
out : tuple[int, ...]
887+
Array dimensions.
750888
"""
751889
# TODO refactor
752890
d0 = c_dim_t(0)

0 commit comments

Comments
 (0)