Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP. Bug fixes related to PR with Array API implementation #46

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion arrayfire_wrapper/_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["BackendType"]
__all__ = ["BackendType", "get_backend", "set_backend"]

import ctypes
import enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def pad(arr: AFArray, begin_shape: tuple[int, ...], end_shape: tuple[int, ...],
ctypes.pointer(out),
arr,
4,
begin_c_shape.c_array,
ctypes.pointer(begin_c_shape.c_array),
4,
end_c_shape.c_array,
ctypes.pointer(end_c_shape.c_array),
border_type.value,
)
return out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def alloc_host(num_bytes: int, /) -> int:

Allocate a buffer on the host with specified number of bytes.
"""
# TODO
# Avoid using AFArray and use ctypes.c_void_p to avoid misunderstanding 'coz its not actually an array
out = AFArray.create_null_pointer()
call_from_clib(alloc_host.__name__, ctypes.pointer(out), CDimT(num_bytes))
return out.value # type: ignore[return-value]
Expand Down
18 changes: 12 additions & 6 deletions arrayfire_wrapper/lib/create_and_modify_array/move_and_reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,31 @@ def replace_scalar(lhs: AFArray, cond_arr: AFArray, rhs: int | float, /) -> None
call_from_clib(replace.__name__, lhs, cond_arr, ctypes.c_double(rhs))


def select(lhs: AFArray, cond_arr: AFArray, rhs: AFArray, /) -> None:
def select(lhs: AFArray, cond_arr: AFArray, rhs: AFArray, /) -> AFArray:
"""
source: https://arrayfire.org/docs/group__data__func__select.htm#gac4af16e31ddd5ddcf09b670f676fd093
"""
call_from_clib(select.__name__, cond_arr, lhs, rhs)
out = AFArray.create_null_pointer()
call_from_clib(select.__name__, ctypes.pointer(out), cond_arr, lhs, rhs)
return out


def select_scalar_l(lhs: int | float, cond_arr: AFArray, rhs: AFArray, /) -> None:
def select_scalar_l(lhs: int | float, cond_arr: AFArray, rhs: AFArray, /) -> AFArray:
"""
source: https://arrayfire.org/docs/group__data__func__select.htm#gac4af16e31ddd5ddcf09b670f676fd093
"""
call_from_clib(select_scalar_l.__name__, cond_arr, ctypes.c_double(lhs), rhs)
out = AFArray.create_null_pointer()
call_from_clib(select_scalar_l.__name__, ctypes.pointer(out), cond_arr, ctypes.c_double(lhs), rhs)
return out


def select_scalar_r(lhs: AFArray, cond_arr: AFArray, rhs: int | float, /) -> None:
def select_scalar_r(lhs: AFArray, cond_arr: AFArray, rhs: int | float, /) -> AFArray:
"""
source: https://arrayfire.org/docs/group__data__func__select.htm#gac4af16e31ddd5ddcf09b670f676fd093
"""
call_from_clib(select_scalar_l.__name__, cond_arr, lhs, ctypes.c_double(rhs))
out = AFArray.create_null_pointer()
call_from_clib(select_scalar_l.__name__, ctypes.pointer(out), cond_arr, lhs, ctypes.c_double(rhs))
return out


def shift(arr: AFArray, /, d0: int, d1: int = 0, d2: int = 0, d3: int = 0) -> AFArray:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ def max_ragged(arr: AFArray, ragged_len: AFArray, dim: int, /) -> tuple[AFArray,
"""
out_values = AFArray.create_null_pointer()
out_idx = AFArray.create_null_pointer()
call_from_clib(
max_ragged.__name__, ctypes.pointer(out_values), ctypes.pointer(out_idx), arr, ragged_len, ctypes.c_int(dim)
)
call_from_clib(max_ragged.__name__, ctypes.pointer(out_values), ctypes.pointer(out_idx), arr, ragged_len, dim)
return (out_values, out_idx)


Expand All @@ -156,9 +154,7 @@ def max_by_key(keys: AFArray, values: AFArray, dim: int, /) -> tuple[AFArray, AF
"""
out_keys = AFArray.create_null_pointer()
out_values = AFArray.create_null_pointer()
call_from_clib(
max_by_key.__name__, ctypes.pointer(out_keys), ctypes.pointer(out_values), keys, values, ctypes.c_int(dim)
)
call_from_clib(max_by_key.__name__, ctypes.pointer(out_keys), ctypes.pointer(out_values), keys, values, dim)
return (out_keys, out_values)


Expand Down
2 changes: 1 addition & 1 deletion arrayfire_wrapper/lib/vector_algorithms/set_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def set_unique(arr: AFArray, is_sorted: bool, /) -> AFArray:
source: https://arrayfire.org/docs/group__set__func__unique.htm#ga6afa1de48cbbc4b2df530c2530087943
"""
out = AFArray.create_null_pointer()
call_from_clib(set_intersect.__name__, ctypes.pointer(out), ctypes.c_bool(is_sorted))
call_from_clib(set_unique.__name__, ctypes.pointer(out), arr, ctypes.c_bool(is_sorted))
return out
2 changes: 1 addition & 1 deletion arrayfire_wrapper/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

_MAJOR = "0"
_MINOR = "6"
_MINOR = "7"
# On main and in a nightly release the patch should be one ahead of the last
# released build.
_PATCH = "0"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "arrayfire-binary-python-wrapper"
version = "0.6.0+AF3.9.0"
version = "0.7.0+AF3.9.0"
requires-python = ">=3.10"
authors = [
{ name = "ArrayFire", email = "[email protected]"},
Expand Down
Loading