Skip to content

Commit 303bea3

Browse files
committed
Removing unnecessary deletes
- Converted the variables to private variables
1 parent 1acd89c commit 303bea3

File tree

8 files changed

+43
-48
lines changed

8 files changed

+43
-48
lines changed

arrayfire/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,3 @@
5858
del inspect
5959
del numbers
6060
del os
61-
62-
#do not export internal functions
63-
del bcast_var
64-
del is_number
65-
del safe_call

arrayfire/arith.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from .library import *
1515
from .array import *
16-
from .bcast import *
16+
from .bcast import _bcast_var
17+
from .util import _is_number
1718

1819
def _arith_binary_func(lhs, rhs, c_func):
1920
out = Array()
@@ -25,21 +26,21 @@ def _arith_binary_func(lhs, rhs, c_func):
2526
raise TypeError("Atleast one input needs to be of type arrayfire.array")
2627

2728
elif (is_left_array and is_right_array):
28-
safe_call(c_func(ct.pointer(out.arr), lhs.arr, rhs.arr, bcast_var.get()))
29+
safe_call(c_func(ct.pointer(out.arr), lhs.arr, rhs.arr, _bcast_var.get()))
2930

30-
elif (is_number(rhs)):
31+
elif (_is_number(rhs)):
3132
ldims = dim4_to_tuple(lhs.dims())
3233
rty = implicit_dtype(rhs, lhs.type())
3334
other = Array()
3435
other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], rty)
35-
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast_var.get()))
36+
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, _bcast_var.get()))
3637

3738
else:
3839
rdims = dim4_to_tuple(rhs.dims())
3940
lty = implicit_dtype(lhs, rhs.type())
4041
other = Array()
4142
other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], lty)
42-
safe_call(c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast_var.get()))
43+
safe_call(c_func(ct.pointer(out.arr), other.arr, rhs.arr, _bcast_var.get()))
4344

4445
return out
4546

arrayfire/array.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import inspect
1515
from .library import *
1616
from .util import *
17-
from .bcast import *
17+
from .util import _is_number
18+
from .bcast import _bcast_var
1819
from .base import *
1920
from .index import *
2021
from .index import _Index4
@@ -75,31 +76,31 @@ def _binary_func(lhs, rhs, c_func):
7576
out = Array()
7677
other = rhs
7778

78-
if (is_number(rhs)):
79+
if (_is_number(rhs)):
7980
ldims = dim4_to_tuple(lhs.dims())
8081
rty = implicit_dtype(rhs, lhs.type())
8182
other = Array()
8283
other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], rty.value)
8384
elif not isinstance(rhs, Array):
8485
raise TypeError("Invalid parameter to binary function")
8586

86-
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast_var.get()))
87+
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, _bcast_var.get()))
8788

8889
return out
8990

9091
def _binary_funcr(lhs, rhs, c_func):
9192
out = Array()
9293
other = lhs
9394

94-
if (is_number(lhs)):
95+
if (_is_number(lhs)):
9596
rdims = dim4_to_tuple(rhs.dims())
9697
lty = implicit_dtype(lhs, rhs.type())
9798
other = Array()
9899
other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], lty.value)
99100
elif not isinstance(lhs, Array):
100101
raise TypeError("Invalid parameter to binary function")
101102

102-
c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast_var.get())
103+
c_func(ct.pointer(out.arr), other.arr, rhs.arr, _bcast_var.get())
103104

104105
return out
105106

@@ -172,7 +173,7 @@ def _get_assign_dims(key, idims):
172173
for n in range(len(idims)):
173174
dims[n] = idims[n]
174175

175-
if is_number(key):
176+
if _is_number(key):
176177
dims[0] = 1
177178
return dims
178179
elif isinstance(key, slice):
@@ -188,7 +189,7 @@ def _get_assign_dims(key, idims):
188189
n_inds = len(key)
189190

190191
for n in range(n_inds):
191-
if (is_number(key[n])):
192+
if (_is_number(key[n])):
192193
dims[n] = 1
193194
elif (isinstance(key[n], BaseArray)):
194195
dims[n] = key[n].elements()
@@ -891,7 +892,7 @@ def __setitem__(self, key, val):
891892
try:
892893
n_dims = self.numdims()
893894

894-
if (is_number(val)):
895+
if (_is_number(val)):
895896
tdims = _get_assign_dims(key, self.dims())
896897
other_arr = constant_array(val, tdims[0], tdims[1], tdims[2], tdims[3], self.type())
897898
del_other = True

arrayfire/bcast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def set(self, flag):
2222
def toggle(self):
2323
_bcast._flag ^= True
2424

25-
bcast_var = _bcast()
25+
_bcast_var = _bcast()
2626

2727
def broadcast(func, *args):
2828
"""
@@ -85,9 +85,9 @@ def broadcast(func, *args):
8585
"""
8686

8787
def wrapper(*func_args):
88-
bcast_var.toggle()
88+
_bcast_var.toggle()
8989
res = func(*func_args)
90-
bcast_var.toggle()
90+
_bcast_var.toggle()
9191
return res
9292

9393
if len(args) == 0:

arrayfire/graphics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from .library import *
1515
from .array import *
16+
from .util import _is_number
1617

1718
class _Cell(ct.Structure):
1819
_fields_ = [("row", ct.c_int),
@@ -219,7 +220,7 @@ def __getitem__(self, keys):
219220
raise IndexError("Window expects indexing along two dimensions")
220221
if len(keys) != 2:
221222
raise IndexError("Window expects indexing along two dimensions only")
222-
if not (is_number(keys[0]) and is_number(keys[1])):
223+
if not (_is_number(keys[0]) and _is_number(keys[1])):
223224
raise IndexError("Window expects the indices to be numbers")
224225
self._r = keys[0]
225226
self._c = keys[1]

arrayfire/index.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
from .library import *
1414
from .util import *
15+
from .util import _is_number
1516
from .base import *
16-
from .bcast import *
17+
from .bcast import _bcast_var
1718
import math
1819

1920
class Seq(ct.Structure):
@@ -47,7 +48,7 @@ def __init__ (self, S):
4748
self.end = ct.c_double(-1)
4849
self.step = ct.c_double( 1)
4950

50-
if is_number(S):
51+
if _is_number(S):
5152
self.begin = ct.c_double(S)
5253
self.end = ct.c_double(S)
5354
elif isinstance(S, slice):
@@ -131,11 +132,11 @@ def next(self):
131132
"""
132133
Function called by the iterator in Python 2
133134
"""
134-
if bcast_var.get() is True:
135-
bcast_var.toggle()
135+
if _bcast_var.get() is True:
136+
_bcast_var.toggle()
136137
raise StopIteration
137138
else:
138-
bcast_var.toggle()
139+
_bcast_var.toggle()
139140
return self
140141

141142
def __next__(self):

arrayfire/library.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import ctypes as ct
1616

1717
try:
18-
from enum import Enum
18+
from enum import Enum as _Enum
1919
def _Enum_Type(v):
2020
return v
2121
except:
22-
class Enum(object):
22+
class _Enum(object):
2323
pass
2424

2525
class _Enum_Type(object):
@@ -84,10 +84,8 @@ def lock(self):
8484
self.__lock = True
8585

8686
backend = _clibrary()
87-
del _clibrary
8887

89-
90-
class ERR(Enum):
88+
class ERR(_Enum):
9189
"""
9290
Error values. For internal use only.
9391
"""
@@ -119,7 +117,7 @@ class ERR(Enum):
119117
INTERNAL = _Enum_Type(998)
120118
UNKNOWN = _Enum_Type(999)
121119

122-
class Dtype(Enum):
120+
class Dtype(_Enum):
123121
"""
124122
Error values. For internal use only.
125123
"""
@@ -134,14 +132,14 @@ class Dtype(Enum):
134132
s64 = _Enum_Type(8)
135133
u64 = _Enum_Type(9)
136134

137-
class Source(Enum):
135+
class Source(_Enum):
138136
"""
139137
Source of the pointer
140138
"""
141139
device = _Enum_Type(0)
142140
host = _Enum_Type(1)
143141

144-
class INTERP(Enum):
142+
class INTERP(_Enum):
145143
"""
146144
Interpolation method
147145
"""
@@ -150,36 +148,36 @@ class INTERP(Enum):
150148
BILINEAR = _Enum_Type(2)
151149
CUBIC = _Enum_Type(3)
152150

153-
class PAD(Enum):
151+
class PAD(_Enum):
154152
"""
155153
Edge padding types
156154
"""
157155
ZERO = _Enum_Type(0)
158156
SYM = _Enum_Type(1)
159157

160-
class CONNECTIVITY(Enum):
158+
class CONNECTIVITY(_Enum):
161159
"""
162160
Neighborhood connectivity
163161
"""
164162
FOUR = _Enum_Type(4)
165163
EIGHT = _Enum_Type(8)
166164

167-
class CONV_MODE(Enum):
165+
class CONV_MODE(_Enum):
168166
"""
169167
Convolution mode
170168
"""
171169
DEFAULT = _Enum_Type(0)
172170
EXPAND = _Enum_Type(1)
173171

174-
class CONV_DOMAIN(Enum):
172+
class CONV_DOMAIN(_Enum):
175173
"""
176174
Convolution domain
177175
"""
178176
AUTO = _Enum_Type(0)
179177
SPATIAL = _Enum_Type(1)
180178
FREQ = _Enum_Type(2)
181179

182-
class MATCH(Enum):
180+
class MATCH(_Enum):
183181
"""
184182
Match type
185183
"""
@@ -229,15 +227,15 @@ class MATCH(Enum):
229227
"""
230228
SHD = _Enum_Type(8)
231229

232-
class CSPACE(Enum):
230+
class CSPACE(_Enum):
233231
"""
234232
Colorspace formats
235233
"""
236234
GRAY = _Enum_Type(0)
237235
RGB = _Enum_Type(1)
238236
HSV = _Enum_Type(2)
239237

240-
class MATPROP(Enum):
238+
class MATPROP(_Enum):
241239
"""
242240
Matrix properties
243241
"""
@@ -297,7 +295,7 @@ class MATPROP(Enum):
297295
"""
298296
BLOCK_DIAG = _Enum_Type(8192)
299297

300-
class NORM(Enum):
298+
class NORM(_Enum):
301299
"""
302300
Norm types
303301
"""
@@ -311,7 +309,7 @@ class NORM(Enum):
311309
MATRIX_L_PQ = _Enum_Type(7)
312310
EUCLID = VECTOR_2
313311

314-
class COLORMAP(Enum):
312+
class COLORMAP(_Enum):
315313
"""
316314
Colormaps
317315
"""
@@ -322,5 +320,3 @@ class COLORMAP(Enum):
322320
MOOD = _Enum_Type(4)
323321
HEAT = _Enum_Type(5)
324322
BLUE = _Enum_Type(6)
325-
326-
del Enum

arrayfire/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def dim4(d0=1, d1=1, d2=1, d3=1):
1919

2020
return out
2121

22-
def is_number(a):
22+
def _is_number(a):
2323
return isinstance(a, numbers.Number)
2424

2525
def number_dtype(a):
@@ -55,7 +55,7 @@ def dim4_to_tuple(dims, default=1):
5555
assert(isinstance(dims, tuple))
5656

5757
if (default is not None):
58-
assert(is_number(default))
58+
assert(_is_number(default))
5959

6060
out = [default]*4
6161

0 commit comments

Comments
 (0)