Skip to content

Commit 049e509

Browse files
committed
Adding documentation for device.py and features.py
1 parent 1b67466 commit 049e509

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

arrayfire/device.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@
66
# The complete license agreement can be obtained at:
77
# http://arrayfire.com/licenses/BSD-3-Clause
88
########################################################
9+
"""
10+
Functions to handle the available devices in the backend.
11+
"""
912

1013
from .library import *
1114
from .util import (safe_call, to_str)
1215

1316
def info():
17+
"""
18+
Displays the information about the following:
19+
- ArrayFire build and version number.
20+
- The number of devices available.
21+
- The names of the devices.
22+
- The current device being used.
23+
"""
1424
safe_call(backend.get().af_info())
1525

1626
def device_info():
27+
"""
28+
Returns a map with the following fields:
29+
- 'device': Name of the current device.
30+
- 'backend': The current backend being used.
31+
- 'toolkit': The toolkit version for the backend.
32+
- 'compute': The compute version of the device.
33+
"""
1734
c_char_256 = ct.c_char * 256
1835
device_name = c_char_256()
1936
backend_name = c_char_256()
@@ -31,29 +48,80 @@ def device_info():
3148
return dev_info
3249

3350
def get_device_count():
51+
"""
52+
Returns the number of devices available.
53+
"""
3454
c_num = ct.c_int(0)
3555
safe_call(backend.get().af_get_device_count(ct.pointer(c_num)))
3656
return c_num.value
3757

3858
def get_device():
59+
"""
60+
Returns the id of the current device.
61+
"""
3962
c_dev = ct.c_int(0)
4063
safe_call(backend.get().af_get_device(ct.pointer(c_dev)))
4164
return c_dev.value
4265

4366
def set_device(num):
67+
"""
68+
Change the active device to the specified id.
69+
70+
Parameters
71+
---------
72+
num: int.
73+
id of the desired device.
74+
"""
4475
safe_call(backend.get().af_set_device(num))
4576

4677
def is_dbl_supported(device=None):
78+
"""
79+
Check if double precision is supported on specified device.
80+
81+
Parameters
82+
---------
83+
device: optional: int. default: None.
84+
id of the desired device.
85+
86+
Returns
87+
--------
88+
- True if double precision supported.
89+
- False if double precision not supported.
90+
"""
4791
dev = device if device is not None else get_device()
4892
res = ct.c_bool(False)
4993
safe_call(backend.get().af_get_dbl_support(ct.pointer(res), dev))
5094
return res.value
5195

5296
def sync(device=None):
97+
"""
98+
Block until all the functions on the device have completed execution.
99+
100+
Parameters
101+
---------
102+
device: optional: int. default: None.
103+
id of the desired device.
104+
"""
53105
dev = device if device is not None else get_device()
54106
safe_call(backend.get().af_sync(dev))
55107

56108
def device_mem_info():
109+
"""
110+
Returns a map with the following fields:
111+
- 'alloc': Contains the map of the following
112+
- 'buffers' : Total number of buffers allocated by memory manager.
113+
- 'bytes' : Total number of bytes allocated by memory manager.
114+
- 'lock': Contains the map of the following
115+
- 'buffers' : Total number of buffers currently in scope.
116+
- 'bytes' : Total number of bytes currently in scope.
117+
118+
Note
119+
-----
120+
ArrayFire does not free memory when array goes out of scope. The memory is marked for reuse.
121+
- The difference between alloc buffers and lock buffers equals the number of free buffers.
122+
- The difference between alloc bytes and lock bytes equals the number of free bytes.
123+
124+
"""
57125
alloc_bytes = ct.c_size_t(0)
58126
alloc_buffers = ct.c_size_t(0)
59127
lock_bytes = ct.c_size_t(0)

arrayfire/features.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,74 @@
66
# The complete license agreement can be obtained at:
77
# http://arrayfire.com/licenses/BSD-3-Clause
88
########################################################
9+
"""
10+
arrayfire.Features class
11+
"""
912
from .library import *
1013
from .array import *
1114
import numbers
1215

1316
class Features(object):
17+
"""
18+
A container class used for various feature detectors.
1419
15-
def __init__(self, num=None):
20+
Parameters
21+
----------
22+
23+
num: optional: int. default: 0.
24+
Specifies the number of features.
25+
"""
26+
27+
def __init__(self, num=0):
1628
self.feat = ct.c_void_p(0)
1729
if num is not None:
1830
assert(isinstance(num, numbers.Number))
1931
safe_call(backend.get().af_create_features(ct.pointer(self.feat), ct.c_longlong(num)))
2032

2133
def num_features():
34+
"""
35+
Returns the number of features detected.
36+
"""
2237
num = ct.c_longlong(0)
2338
safe_call(backend.get().af_get_features_num(ct.pointer(num), self.feat))
2439
return num
2540

2641
def get_xpos():
42+
"""
43+
Returns the x-positions of the features detected.
44+
"""
2745
out = Array()
2846
safe_call(backend.get().af_get_features_xpos(ct.pointer(out.arr), self.feat))
2947
return out
3048

3149
def get_ypos():
50+
"""
51+
Returns the y-positions of the features detected.
52+
"""
3253
out = Array()
3354
safe_call(backend.get().af_get_features_ypos(ct.pointer(out.arr), self.feat))
3455
return out
3556

3657
def get_score():
58+
"""
59+
Returns the scores of the features detected.
60+
"""
3761
out = Array()
3862
safe_call(backend.get().af_get_features_score(ct.pointer(out.arr), self.feat))
3963
return out
4064

4165
def get_orientation():
66+
"""
67+
Returns the orientations of the features detected.
68+
"""
4269
out = Array()
4370
safe_call(backend.get().af_get_features_orientation(ct.pointer(out.arr), self.feat))
4471
return out
4572

4673
def get_size():
74+
"""
75+
Returns the sizes of the features detected.
76+
"""
4777
out = Array()
4878
safe_call(backend.get().af_get_features_size(ct.pointer(out.arr), self.feat))
4979
return out

0 commit comments

Comments
 (0)