6
6
# The complete license agreement can be obtained at:
7
7
# http://arrayfire.com/licenses/BSD-3-Clause
8
8
########################################################
9
+ """
10
+ classes required for indexing operations
11
+ """
12
+
9
13
from .library import *
10
14
from .util import *
11
15
from .base import *
12
16
from .bcast import *
13
17
import math
14
18
15
19
class Seq (ct .Structure ):
20
+ """
21
+ arrayfire equivalent of slice
22
+
23
+ Attributes
24
+ ----------
25
+
26
+ begin: number
27
+ Start of the sequence.
28
+
29
+ end : number
30
+ End of sequence.
31
+
32
+ step : number
33
+ Step size.
34
+
35
+ Parameters
36
+ ----------
37
+
38
+ S: slice or number.
39
+
40
+ """
16
41
_fields_ = [("begin" , ct .c_double ),
17
42
("end" , ct .c_double ),
18
43
("step" , ct .c_double )]
@@ -39,6 +64,57 @@ def __init__ (self, S):
39
64
40
65
class ParallelRange (Seq ):
41
66
67
+ """
68
+ Class used to parallelize for loop.
69
+
70
+ Inherits from Seq.
71
+
72
+ Attributes
73
+ ----------
74
+
75
+ S: slice
76
+
77
+ Parameters
78
+ ----------
79
+
80
+ start: number
81
+ Beginning of parallel range.
82
+
83
+ stop : number
84
+ End of parallel range.
85
+
86
+ step : number
87
+ Step size for parallel range.
88
+
89
+ Examples
90
+ --------
91
+
92
+ >>> import arrayfire as af
93
+ >>> a = af.randu(3, 3)
94
+ >>> b = af.randu(3, 1)
95
+ >>> c = af.constant(0, 3, 3)
96
+ >>> for ii in af.ParallelRange(3):
97
+ ... c[:, ii] = a[:, ii] + b
98
+ ...
99
+ >>> af.display(a)
100
+ [3 3 1 1]
101
+ 0.4107 0.1794 0.3775
102
+ 0.8224 0.4198 0.3027
103
+ 0.9518 0.0081 0.6456
104
+
105
+ >>> af.display(b)
106
+ [3 1 1 1]
107
+ 0.7269
108
+ 0.7104
109
+ 0.5201
110
+
111
+ >>> af.display(c)
112
+ [3 3 1 1]
113
+ 1.1377 0.9063 1.1045
114
+ 1.5328 1.1302 1.0131
115
+ 1.4719 0.5282 1.1657
116
+
117
+ """
42
118
def __init__ (self , start , stop = None , step = None ):
43
119
44
120
if (stop is None ):
@@ -52,6 +128,9 @@ def __iter__(self):
52
128
return self
53
129
54
130
def next (self ):
131
+ """
132
+ Function called by the iterator in Python 2
133
+ """
55
134
if bcast_var .get () is True :
56
135
bcast_var .toggle ()
57
136
raise StopIteration
@@ -74,6 +153,38 @@ class Index(ct.Structure):
74
153
("isSeq" , ct .c_bool ),
75
154
("isBatch" , ct .c_bool )]
76
155
156
+ """
157
+ Container for the index class in arrayfire C library
158
+
159
+ Attributes
160
+ ----------
161
+ idx.arr: ctypes.c_void_p
162
+ - Default 0
163
+
164
+ idx.seq: af.Seq
165
+ - Default af.Seq(0, -1, 1)
166
+
167
+ isSeq : bool
168
+ - Default True
169
+
170
+ isBatch : bool
171
+ - Default False
172
+
173
+ Parameters
174
+ -----------
175
+
176
+ idx: key
177
+ - If of type af.Array, self.idx.arr = idx, self.isSeq = False
178
+ - If of type af.ParallelRange, self.idx.seq = idx, self.isBatch = True
179
+ - Default:, self.idx.seq = af.Seq(idx)
180
+
181
+ Note
182
+ ----
183
+
184
+ Implemented for internal use only. Use with extreme caution.
185
+
186
+ """
187
+
77
188
def __init__ (self , idx ):
78
189
79
190
self .idx = _uidx ()
0 commit comments