66# The complete license agreement can be obtained at:
77# http://arrayfire.com/licenses/BSD-3-Clause
88########################################################
9+ """
10+ classes required for indexing operations
11+ """
12+
913from .library import *
1014from .util import *
1115from .base import *
1216from .bcast import *
1317import math
1418
1519class 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+ """
1641 _fields_ = [("begin" , ct .c_double ),
1742 ("end" , ct .c_double ),
1843 ("step" , ct .c_double )]
@@ -39,6 +64,57 @@ def __init__ (self, S):
3964
4065class ParallelRange (Seq ):
4166
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+ """
42118 def __init__ (self , start , stop = None , step = None ):
43119
44120 if (stop is None ):
@@ -52,6 +128,9 @@ def __iter__(self):
52128 return self
53129
54130 def next (self ):
131+ """
132+ Function called by the iterator in Python 2
133+ """
55134 if bcast_var .get () is True :
56135 bcast_var .toggle ()
57136 raise StopIteration
@@ -74,6 +153,38 @@ class Index(ct.Structure):
74153 ("isSeq" , ct .c_bool ),
75154 ("isBatch" , ct .c_bool )]
76155
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+
77188 def __init__ (self , idx ):
78189
79190 self .idx = _uidx ()
0 commit comments