Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
75c1d43
Refactoring of basic functionality to create an empty Array
Jan 24, 2023
b14aa91
Replace dim4 with CShape
roaffix Jan 24, 2023
eadbe9b
Add tests. Minor fixes. Update CI
roaffix Jan 24, 2023
c13a59f
Fix CI
roaffix Jan 24, 2023
f0f57e8
Add arithmetic operators w/o tests
roaffix Jan 26, 2023
8cef774
Fix array init bug. Add __getitem__. Change pytest for active debug mode
roaffix Jan 27, 2023
a4c7ac9
Add reflected arithmetic and array operators
roaffix Jan 27, 2023
4140527
Place TODO for repr
roaffix Jan 28, 2023
4374d93
Add bitwise operators. Add in-place operators. Add missing reflected …
roaffix Jan 28, 2023
5a29ffa
Fix tests
roaffix Jan 28, 2023
4187b27
Add tests for arithmetic operators
roaffix Jan 28, 2023
cdb7a92
Added to_list and to_ctypes_array
roaffix Jan 28, 2023
9c0435a
Fix bug when scalar is empty returns None
roaffix Jan 28, 2023
769c16c
Fix typing in array object. Add tests
roaffix Jan 29, 2023
fb27e46
Change tests and found bug with reflected operators
roaffix Jan 29, 2023
0afb92e
Fix reflected operators bug. Add test coverage for the rest of the ar…
roaffix Jan 29, 2023
1d071be
Add required by specification methods
roaffix Jan 30, 2023
04fbb1b
Change file names
roaffix Jan 30, 2023
2d91b04
Change utils. Add docstrings
roaffix Jan 30, 2023
5939388
Add docstrings for operators
roaffix Jan 30, 2023
0231e27
Change TODOs
roaffix Jan 30, 2023
07c4206
Add docstrings for other operators. Remove docstrings from mocks
roaffix Jan 30, 2023
908447b
Change tags and typings
roaffix Feb 4, 2023
fa3ad06
Change typings from python 3.10 to python 3.8
roaffix Feb 4, 2023
0de9955
Add readme with reference to run tests
roaffix Feb 4, 2023
ae6be05
Revert changes accidentally made in original array
roaffix Feb 5, 2023
cfa9114
Add initial refactoring with backend mock
roaffix Feb 8, 2023
5de8694
Add c library methods for operators
roaffix Feb 9, 2023
b9ac1c5
Remove dependency on default backend
roaffix Feb 10, 2023
171ec88
Refactor backend and project structure
roaffix Feb 10, 2023
e984caa
Refactor backend library operators
roaffix Feb 11, 2023
0b164d4
Refactor used in array_object backend methods
roaffix Feb 11, 2023
282f860
Minor test fix
roaffix Feb 11, 2023
54f7ada
Refactor tests
roaffix Feb 13, 2023
51f6efd
Add comparison operators tests
roaffix Feb 13, 2023
23e2635
Minor fixes for tests
roaffix Feb 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change TODOs
  • Loading branch information
roaffix committed Jan 30, 2023
commit 0231e2774002c093f58fd381b533455953408a60
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ jobs:
- name: Test with pytest
run: pytest

- name: Install AF
run: apt install arrayfire

- name: Test array_api
run: python -m pytest arrayfire/array_api
30 changes: 9 additions & 21 deletions arrayfire/array_api/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
from .dtypes import uint64 as af_uint64

ShapeType = tuple[int, ...]
_bcast_var = False # HACK, TODO replace for actual bcast_var after refactoring
# HACK, TODO replace for actual bcast_var after refactoring ~ https://github.com/arrayfire/arrayfire/pull/2871
_bcast_var = False

# TODO use int | float in operators -> remove bool | complex support


@dataclass
Expand All @@ -33,12 +36,6 @@ class _ArrayBuffer:


class Array:
# Numpy checks this attribute to know which class handles binary builtin operations, such as __add__.
# Setting to such a high value should make sure that arrayfire has priority over
# other classes, ensuring that e.g. numpy.float32(1)*arrayfire.randu(3) is handled by
# arrayfire's __radd__() instead of numpy's __add__()
__array_priority__ = 30 # TODO discuss its purpose

def __init__(
self, x: None | Array | py_array.array | int | ctypes.c_void_p | list = None,
dtype: None | Dtype | str = None, shape: None | ShapeType = None,
Expand Down Expand Up @@ -164,7 +161,6 @@ def __neg__(self) -> Array:
return 0 - self # type: ignore[no-any-return, operator] # FIXME

def __add__(self, other: int | float | Array, /) -> Array:
# TODO discuss either we need to support complex and bool as other input type
"""
Calculates the sum for each element of an array instance with the respective element of the array other.

Expand Down Expand Up @@ -300,21 +296,13 @@ def __pow__(self, other: int | float | Array, /) -> Array:
out : Array
An array containing the element-wise results. The returned array must have a data type determined
by Type Promotion Rules.

Note
----
- If both self and other have integer data types, the result of __pow__ when other_i is negative
(i.e., less than zero) is unspecified and thus implementation-dependent.
If self has an integer data type and other has a floating-point data type, behavior is
implementation-dependent, as type promotion between data type “kinds” (e.g., integer versus floating-point)
is unspecified.
"""
return _process_c_function(self, other, backend.get().af_pow)

# Array Operators

def __matmul__(self, other: Array, /) -> Array:
# TODO
# TODO get from blas - make vanilla version and not copy af.matmul as is
return NotImplemented

# Bitwise Operators
Expand Down Expand Up @@ -508,7 +496,7 @@ def __rfloordiv__(self, other: Array, /) -> Array:

def __rmod__(self, other: Array, /) -> Array:
"""
Return other / self.
Return other % self.
"""
return _process_c_function(other, self, backend.get().af_mod)

Expand All @@ -534,7 +522,7 @@ def __rand__(self, other: Array, /) -> Array:

def __ror__(self, other: Array, /) -> Array:
"""
Return other & self.
Return other | self.
"""
return _process_c_function(other, self, backend.get().af_bitor)

Expand Down Expand Up @@ -648,7 +636,7 @@ def __array_namespace__(self, *, api_version: None | str = None) -> Any:
return NotImplemented

def __bool__(self) -> bool:
# TODO
# TODO consider using scalar() and is_scalar()
return NotImplemented

def __complex__(self) -> complex:
Expand All @@ -668,7 +656,7 @@ def __float__(self) -> float:
return NotImplemented

def __getitem__(self, key: int | slice | tuple[int | slice] | Array, /) -> Array:
# TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array
# TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array - consider using af.span
# TODO: refactor
out = Array()
ndims = self.ndim
Expand Down
1 change: 1 addition & 0 deletions arrayfire/array_api/tests/test_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# TODO change separated methods with setup and teardown to avoid code duplication
# TODO add tests for array arguments: device, offset, strides
# TODO add tests for all supported dtypes on initialisation
# TODO check if e.g. abs(x1-x2) < 1e-6 ~ https://davidamos.dev/the-right-way-to-compare-floats-in-python/


def test_create_empty_array() -> None:
Expand Down