Skip to content

Commit 72ca1ca

Browse files
committed
Cleaning up scan, scan_by_key and moments
- Use consistent naming scheme for enums - Fixed minor bugs when passing enum to the C function
1 parent 8aa165d commit 72ca1ca

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

arrayfire/algorithm.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def accum(a, dim=0):
299299
"""
300300
return _parallel_dim(a, dim, backend.get().af_accum)
301301

302-
def scan(a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
302+
def scan(a, dim=0, op=BINARYOP.ADD, inclusive_scan=True):
303303
"""
304304
Generalized scan of an array.
305305
@@ -311,8 +311,12 @@ def scan(a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
311311
dim : optional: int. default: 0
312312
Dimension along which the scan is performed.
313313
314-
op : optional: af.BINARYOP. default: af.BINARYOP.BINARY_ADD.
315-
- Interpolation method used for resizing.
314+
op : optional: af.BINARYOP. default: af.BINARYOP.ADD.
315+
Binary option the scan algorithm uses. Can be one of:
316+
- af.BINARYOP.ADD
317+
- af.BINARYOP.MUL
318+
- af.BINARYOP.MIN
319+
- af.BINARYOP.MAX
316320
317321
inclusive_scan: optional: bool. default: True
318322
Specifies if the scan is inclusive
@@ -323,10 +327,10 @@ def scan(a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
323327
- will contain scan of input.
324328
"""
325329
out = Array()
326-
safe_call(backend.get().af_scan(ct.pointer(out.arr), a.arr, dim, op, inclusive_scan))
330+
safe_call(backend.get().af_scan(ct.pointer(out.arr), a.arr, dim, op.value, inclusive_scan))
327331
return out
328332

329-
def scan_by_key(key, a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
333+
def scan_by_key(key, a, dim=0, op=BINARYOP.ADD, inclusive_scan=True):
330334
"""
331335
Generalized scan by key of an array.
332336
@@ -341,8 +345,12 @@ def scan_by_key(key, a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
341345
dim : optional: int. default: 0
342346
Dimension along which the scan is performed.
343347
344-
op : optional: af.BINARYOP. default: af.BINARYOP.BINARY_ADD.
345-
- Interpolation method used for resizing.
348+
op : optional: af.BINARYOP. default: af.BINARYOP.ADD.
349+
Binary option the scan algorithm uses. Can be one of:
350+
- af.BINARYOP.ADD
351+
- af.BINARYOP.MUL
352+
- af.BINARYOP.MIN
353+
- af.BINARYOP.MAX
346354
347355
inclusive_scan: optional: bool. default: True
348356
Specifies if the scan is inclusive
@@ -353,7 +361,7 @@ def scan_by_key(key, a, dim=0, op=BINARYOP.BINARY_ADD, inclusive_scan=True):
353361
- will contain scan of input.
354362
"""
355363
out = Array()
356-
safe_call(backend.get().af_scan_by_key(ct.pointer(out.arr), key.arr, a.arr, dim, op, inclusive_scan))
364+
safe_call(backend.get().af_scan_by_key(ct.pointer(out.arr), key.arr, a.arr, dim, op.value, inclusive_scan))
357365
return out
358366

359367
def where(a):

arrayfire/image.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ def rgb2ycbcr(image, standard=YCC_STD.BT_601):
11981198
safe_call(backend.get().af_rgb2ycbcr(ct.pointer(out.arr), image.arr, standard.value))
11991199
return out
12001200

1201-
def moments(image, moment = MOMENT.MOMENT_FIRST_ORDER):
1201+
def moments(image, moment = MOMENT.FIRST_ORDER):
12021202
"""
12031203
Calculate image moments.
12041204
@@ -1208,8 +1208,13 @@ def moments(image, moment = MOMENT.MOMENT_FIRST_ORDER):
12081208
- A 2 D arrayfire array representing an image, or
12091209
- A multi dimensional array representing batch of images.
12101210
1211-
moment : optional: af.MOMENT. default: af.MOMENT.MOMENT_FIRST_ORDER.
1212-
- Moment(s) to calculate
1211+
moment : optional: af.MOMENT. default: af.MOMENT.FIRST_ORDER.
1212+
Moment(s) to calculate. Can be one of:
1213+
- af.MOMENT.M00
1214+
- af.MOMENT.M01
1215+
- af.MOMENT.M10
1216+
- af.MOMENT.M11
1217+
- af.MOMENT.FIRST_ORDER
12131218
12141219
Returns
12151220
---------

arrayfire/library.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ class INTERP(_Enum):
113113
"""
114114
Interpolation method
115115
"""
116-
NEAREST = _Enum_Type(0)
117-
LINEAR = _Enum_Type(1)
118-
BILINEAR = _Enum_Type(2)
119-
CUBIC = _Enum_Type(3)
120-
LOWER = _Enum_Type(4)
116+
NEAREST = _Enum_Type(0)
117+
LINEAR = _Enum_Type(1)
118+
BILINEAR = _Enum_Type(2)
119+
CUBIC = _Enum_Type(3)
120+
LOWER = _Enum_Type(4)
121+
LINEAR_COSINE = _Enum_Type(5)
122+
BILINEAR_COSINE = _Enum_Type(6)
123+
BICUBIC = _Enum_Type(7)
124+
CUBIC_SPLINE = _Enum_Type(8)
125+
BICUBIC_SPLINE = _Enum_Type(9)
121126

122127
class PAD(_Enum):
123128
"""
@@ -351,22 +356,23 @@ class MARKER(_Enum):
351356

352357
class MOMENT(_Enum):
353358
"""
354-
Image Moments
359+
Image Moments types
355360
"""
356-
MOMENT_M00 = _Enum_Type(1)
357-
MOMENT_M01 = _Enum_Type(2)
358-
MOMENT_M10 = _Enum_Type(4)
359-
MOMENT_M11 = _Enum_Type(8)
360-
MOMENT_FIRST_ORDER = _Enum_Type(15)
361+
M00 = _Enum_Type(1)
362+
M01 = _Enum_Type(2)
363+
M10 = _Enum_Type(4)
364+
M11 = _Enum_Type(8)
365+
FIRST_ORDER = _Enum_Type(15)
361366

362367
class BINARYOP(_Enum):
363368
"""
364369
Binary Operators
365370
"""
366-
BINARY_ADD = _Enum_Type(0)
367-
BINARY_MUL = _Enum_Type(1)
368-
BINARY_MIN = _Enum_Type(2)
369-
BINARY_MAX = _Enum_Type(3)
371+
ADD = _Enum_Type(0)
372+
MUL = _Enum_Type(1)
373+
MIN = _Enum_Type(2)
374+
MAX = _Enum_Type(3)
375+
370376

371377
def _setup():
372378
import platform

0 commit comments

Comments
 (0)