Skip to content

[WIP] New additions for v3.4 #87

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

Closed
wants to merge 1 commit into from
Closed
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
57 changes: 57 additions & 0 deletions arrayfire/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,63 @@ def accum(a, dim=0):
"""
return _parallel_dim(a, dim, backend.get().af_accum)

def scan(a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
"""
Generalized scan of an array.

Parameters
----------
a : af.Array
Multi dimensional arrayfire array.

dim : optional: int. default: 0
Dimension along which the scan is performed.

op : optional: af.BINARYOP. default: af.BINARYOP.BINARY_ADD.
- Interpolation method used for resizing.

inclusive_scan: optional: bool. default: True
Specifies if the scan is inclusive

Returns
---------
out : af.Array
- will contain scan of input.
"""
out = Array()
safe_call(backend.get().af_scan(ct.pointer(out.arr), a.arr, dim, op, inclusive_scan))
return out

def scan_by_key(key, a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
"""
Generalized scan by key of an array.

Parameters
----------
key : af.Array
key array.

a : af.Array
Multi dimensional arrayfire array.

dim : optional: int. default: 0
Dimension along which the scan is performed.

op : optional: af.BINARYOP. default: af.BINARYOP.BINARY_ADD.
- Interpolation method used for resizing.

inclusive_scan: optional: bool. default: True
Specifies if the scan is inclusive

Returns
---------
out : af.Array
- will contain scan of input.
"""
out = Array()
safe_call(backend.get().af_scan_by_key(ct.pointer(out.arr), key.arr, a.arr, dim, op, inclusive_scan))
return out

def where(a):
"""
Find the indices of non zero elements
Expand Down
22 changes: 22 additions & 0 deletions arrayfire/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,28 @@ def rgb2ycbcr(image, standard=YCC_STD.BT_601):
safe_call(backend.get().af_rgb2ycbcr(ct.pointer(out.arr), image.arr, standard.value))
return out

def moments(image, moment = MOMENT.MOMENT_FIRST_ORDER):
"""
Calculate image moments.

Parameters
----------
image : af.Array
- A 2 D arrayfire array representing an image, or
- A multi dimensional array representing batch of images.

moment : optional: af.MOMENT. default: af.MOMENT.MOMENT_FIRST_ORDER.
- Moment(s) to calculate

Returns
---------
out : af.Array
- array containing requested moment(s) of each image
"""
output = Array()
safe_call(backend.get().af_moments(ct.pointer(output.arr), image.arr, moment.value))
return output

def is_image_io_available():
"""
Function to check if the arrayfire library was built with Image IO support.
Expand Down
19 changes: 19 additions & 0 deletions arrayfire/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,25 @@ class MARKER(_Enum):
PLUS = _Enum_Type(6)
STAR = _Enum_Type(7)

class MOMENT(_Enum):
"""
Image Moments
"""
MOMENT_M00 = _Enum_Type(1)
MOMENT_M01 = _Enum_Type(2)
MOMENT_M10 = _Enum_Type(4)
MOMENT_M11 = _Enum_Type(8)
MOMENT_FIRST_ORDER = _Enum_Type(15)

class BINARYOP(_Enum):
"""
Binary Operators
"""
BINARY_ADD = _Enum_Type(0)
BINARY_MUL = _Enum_Type(1)
BINARY_MIN = _Enum_Type(2)
BINARY_MAX = _Enum_Type(3)

def _setup():
import platform
import os
Expand Down
12 changes: 12 additions & 0 deletions arrayfire/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,3 +1264,15 @@ def iir(B, A, X):
Y = Array()
safe_call(backend.get().af_iir(ct.pointer(Y.arr), B.arr, A.arr, X.arr))
return Y

def set_fft_plan_cache_size(cache_size):
"""
Sets plan cache size.

Parameters
----------

cache_size : scalar
the number of plans that shall be cached
"""
safe_call(backend.get().af_set_fft_plan_cache_size(ct.c_size_t(cache_size)))