Skip to content

Commit 131d0bc

Browse files
committed
Merge pull request #23 from pavanky/cleanup
Style clean up
2 parents b0429c7 + 9d6ab0b commit 131d0bc

18 files changed

+218
-218
lines changed

arrayfire/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
del os
3333

3434
#do not export internal classes
35-
del base_array
35+
del BaseArray
3636
del uidx
37-
del seq
38-
del index
39-
del cell
37+
del Seq
38+
del Index
39+
del Cell
4040
del bcast
4141

4242
#do not export internal functions

arrayfire/algorithm.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .array import *
1212

1313
def parallel_dim(a, dim, c_func):
14-
out = array()
14+
out = Array()
1515
safe_call(c_func(ct.pointer(out.arr), a.arr, ct.c_int(dim)))
1616
return out
1717

@@ -67,8 +67,8 @@ def count(a, dim=None):
6767

6868
def imin(a, dim=None):
6969
if dim is not None:
70-
out = array()
71-
idx = array()
70+
out = Array()
71+
idx = Array()
7272
safe_call(clib.af_imin(ct.pointer(out.arr), ct.pointer(idx.arr), a.arr, ct.c_int(dim)))
7373
return out,idx
7474
else:
@@ -83,8 +83,8 @@ def imin(a, dim=None):
8383

8484
def imax(a, dim=None):
8585
if dim is not None:
86-
out = array()
87-
idx = array()
86+
out = Array()
87+
idx = Array()
8888
safe_call(clib.af_imax(ct.pointer(out.arr), ct.pointer(idx.arr), a.arr, ct.c_int(dim)))
8989
return out,idx
9090
else:
@@ -102,7 +102,7 @@ def accum(a, dim=0):
102102
return parallel_dim(a, dim, clib.af_accum)
103103

104104
def where(a):
105-
out = array()
105+
out = Array()
106106
safe_call(clib.af_where(ct.pointer(out.arr), a.arr))
107107
return out
108108

@@ -113,35 +113,35 @@ def diff2(a, dim=0):
113113
return parallel_dim(a, dim, clib.af_diff2)
114114

115115
def sort(a, dim=0, is_ascending=True):
116-
out = array()
116+
out = Array()
117117
safe_call(clib.af_sort(ct.pointer(out.arr), a.arr, ct.c_uint(dim), ct.c_bool(is_ascending)))
118118
return out
119119

120120
def sort_index(a, dim=0, is_ascending=True):
121-
out = array()
122-
idx = array()
123-
safe_call(clib.af_sort_index(ct.pointer(out.arr), ct.pointer(idx.arr), a.arr, \
121+
out = Array()
122+
idx = Array()
123+
safe_call(clib.af_sort_index(ct.pointer(out.arr), ct.pointer(idx.arr), a.arr,
124124
ct.c_uint(dim), ct.c_bool(is_ascending)))
125125
return out,idx
126126

127127
def sort_by_key(iv, ik, dim=0, is_ascending=True):
128-
ov = array()
129-
ok = array()
130-
safe_call(clib.af_sort_by_key(ct.pointer(ov.arr), ct.pointer(ok.arr), \
128+
ov = Array()
129+
ok = Array()
130+
safe_call(clib.af_sort_by_key(ct.pointer(ov.arr), ct.pointer(ok.arr),
131131
iv.arr, ik.arr, ct.c_uint(dim), ct.c_bool(is_ascending)))
132132
return ov,ok
133133

134134
def set_unique(a, is_sorted=False):
135-
out = array()
135+
out = Array()
136136
safe_call(clib.af_set_unique(ct.pointer(out.arr), a.arr, ct.c_bool(is_sorted)))
137137
return out
138138

139139
def set_union(a, b, is_unique=False):
140-
out = array()
140+
out = Array()
141141
safe_call(clib.af_set_union(ct.pointer(out.arr), a.arr, b.arr, ct.c_bool(is_unique)))
142142
return out
143143

144144
def set_intersect(a, b, is_unique=False):
145-
out = array()
145+
out = Array()
146146
safe_call(clib.af_set_intersect(ct.pointer(out.arr), a.arr, b.arr, ct.c_bool(is_unique)))
147147
return out

arrayfire/arith.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from .broadcast import *
1313

1414
def arith_binary_func(lhs, rhs, c_func):
15-
out = array()
15+
out = Array()
1616

17-
is_left_array = isinstance(lhs, array)
18-
is_right_array = isinstance(rhs, array)
17+
is_left_array = isinstance(lhs, Array)
18+
is_right_array = isinstance(rhs, Array)
1919

2020
if not (is_left_array or is_right_array):
2121
raise TypeError("Atleast one input needs to be of type arrayfire.array")
@@ -26,26 +26,26 @@ def arith_binary_func(lhs, rhs, c_func):
2626
elif (is_number(rhs)):
2727
ldims = dim4_tuple(lhs.dims())
2828
rty = implicit_dtype(rhs, lhs.type())
29-
other = array()
29+
other = Array()
3030
other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], rty)
3131
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast.get()))
3232

3333
else:
3434
rdims = dim4_tuple(rhs.dims())
3535
lty = implicit_dtype(lhs, rhs.type())
36-
other = array()
36+
other = Array()
3737
other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], lty)
3838
safe_call(c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast.get()))
3939

4040
return out
4141

4242
def arith_unary_func(a, c_func):
43-
out = array()
43+
out = Array()
4444
safe_call(c_func(ct.pointer(out.arr), a.arr))
4545
return out
4646

4747
def cast(a, dtype=f32):
48-
out=array()
48+
out=Array()
4949
safe_call(clib.af_cast(ct.pointer(out.arr), a.arr, dtype))
5050
return out
5151

arrayfire/array.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from .index import *
1616

1717
def create_array(buf, numdims, idims, dtype):
18-
out_arr = ct.c_longlong(0)
19-
ct.c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
20-
safe_call(clib.af_create_array(ct.pointer(out_arr), ct.c_longlong(buf),\
21-
numdims, ct.pointer(ct.c_dims), dtype))
18+
out_arr = ct.c_void_p(0)
19+
c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
20+
safe_call(clib.af_create_array(ct.pointer(out_arr), ct.c_void_p(buf),
21+
numdims, ct.pointer(c_dims), dtype))
2222
return out_arr
2323

2424
def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=f32):
@@ -29,7 +29,7 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=f32):
2929
else:
3030
raise TypeError("Invalid dtype")
3131

32-
out = ct.c_longlong(0)
32+
out = ct.c_void_p(0)
3333
dims = dim4(d0, d1, d2, d3)
3434

3535
if isinstance(val, complex):
@@ -39,7 +39,7 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=f32):
3939
if (dtype != c32 and dtype != c64):
4040
dtype = c32
4141

42-
safe_call(clib.af_constant_complex(ct.pointer(out), c_real, c_imag,\
42+
safe_call(clib.af_constant_complex(ct.pointer(out), c_real, c_imag,
4343
4, ct.pointer(dims), dtype))
4444
elif dtype == s64:
4545
c_val = ct.c_longlong(val.real)
@@ -55,39 +55,39 @@ def constant_array(val, d0, d1=None, d2=None, d3=None, dtype=f32):
5555

5656

5757
def binary_func(lhs, rhs, c_func):
58-
out = array()
58+
out = Array()
5959
other = rhs
6060

6161
if (is_number(rhs)):
6262
ldims = dim4_tuple(lhs.dims())
6363
rty = implicit_dtype(rhs, lhs.type())
64-
other = array()
64+
other = Array()
6565
other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], rty)
66-
elif not isinstance(rhs, array):
66+
elif not isinstance(rhs, Array):
6767
raise TypeError("Invalid parameter to binary function")
6868

6969
safe_call(c_func(ct.pointer(out.arr), lhs.arr, other.arr, bcast.get()))
7070

7171
return out
7272

7373
def binary_funcr(lhs, rhs, c_func):
74-
out = array()
74+
out = Array()
7575
other = lhs
7676

7777
if (is_number(lhs)):
7878
rdims = dim4_tuple(rhs.dims())
7979
lty = implicit_dtype(lhs, rhs.type())
80-
other = array()
80+
other = Array()
8181
other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], lty)
82-
elif not isinstance(lhs, array):
82+
elif not isinstance(lhs, Array):
8383
raise TypeError("Invalid parameter to binary function")
8484

8585
c_func(ct.pointer(out.arr), other.arr, rhs.arr, bcast.get())
8686

8787
return out
8888

8989
def transpose(a, conj=False):
90-
out = array()
90+
out = Array()
9191
safe_call(clib.af_transpose(ct.pointer(out.arr), a.arr, conj))
9292
return out
9393

@@ -124,11 +124,11 @@ def get_info(dims, buf_len):
124124
return numdims, idims
125125

126126

127-
class array(base_array):
127+
class Array(BaseArray):
128128

129129
def __init__(self, src=None, dims=(0,), type_char=None):
130130

131-
super(array, self).__init__()
131+
super(Array, self).__init__()
132132

133133
buf=None
134134
buf_len=0
@@ -137,7 +137,7 @@ def __init__(self, src=None, dims=(0,), type_char=None):
137137

138138
if src is not None:
139139

140-
if (isinstance(src, array)):
140+
if (isinstance(src, Array)):
141141
safe_call(clib.af_retain_array(ct.pointer(self.arr), src.arr))
142142
return
143143

@@ -178,7 +178,7 @@ def __init__(self, src=None, dims=(0,), type_char=None):
178178
self.arr = create_array(buf, numdims, idims, to_dtype[_type_char])
179179

180180
def copy(self):
181-
out = array()
181+
out = Array()
182182
safe_call(clib.af_copy_array(ct.pointer(out.arr), self.arr))
183183
return out
184184

@@ -187,7 +187,7 @@ def __del__(self):
187187
clib.af_release_array(self.arr)
188188

189189
def device_ptr(self):
190-
ptr = ctypes.c_void_p(0)
190+
ptr = ct.c_void_p(0)
191191
clib.af_get_device_ptr(ct.pointer(ptr), self.arr)
192192
return ptr.value
193193

@@ -206,7 +206,7 @@ def dims(self):
206206
d1 = ct.c_longlong(0)
207207
d2 = ct.c_longlong(0)
208208
d3 = ct.c_longlong(0)
209-
safe_call(clib.af_get_dims(ct.pointer(d0), ct.pointer(d1),\
209+
safe_call(clib.af_get_dims(ct.pointer(d0), ct.pointer(d1),
210210
ct.pointer(d2), ct.pointer(d3), self.arr))
211211
dims = (d0.value,d1.value,d2.value,d3.value)
212212
return dims[:self.numdims()]
@@ -424,11 +424,11 @@ def __nonzero__(self):
424424

425425
def __getitem__(self, key):
426426
try:
427-
out = array()
427+
out = Array()
428428
n_dims = self.numdims()
429429
inds = get_indices(key, n_dims)
430430

431-
safe_call(clib.af_index_gen(ct.pointer(out.arr),\
431+
safe_call(clib.af_index_gen(ct.pointer(out.arr),
432432
self.arr, ct.c_longlong(n_dims), ct.pointer(inds)))
433433
return out
434434
except RuntimeError as e:
@@ -445,11 +445,11 @@ def __setitem__(self, key, val):
445445
else:
446446
other_arr = val.arr
447447

448-
out_arr = ct.c_longlong(0)
448+
out_arr = ct.c_void_p(0)
449449
inds = get_indices(key, n_dims)
450450

451-
safe_call(clib.af_assign_gen(ct.pointer(out_arr),\
452-
self.arr, ct.c_longlong(n_dims), ct.pointer(inds),\
451+
safe_call(clib.af_assign_gen(ct.pointer(out_arr),
452+
self.arr, ct.c_longlong(n_dims), ct.pointer(inds),
453453
other_arr))
454454
safe_call(clib.af_release_array(self.arr))
455455
self.arr = out_arr

arrayfire/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
from .library import *
1010
from .util import *
1111

12-
class base_array(object):
12+
class BaseArray(object):
1313
def __init__(self):
14-
self.arr = ct.c_longlong(0)
14+
self.arr = ct.c_void_p(0)

arrayfire/blas.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@
1111
from .array import *
1212

1313
def matmul(lhs, rhs, lhs_opts=AF_MAT_NONE, rhs_opts=AF_MAT_NONE):
14-
out = array()
15-
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,\
14+
out = Array()
15+
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
1616
lhs_opts, rhs_opts))
1717
return out
1818

1919
def matmulTN(lhs, rhs):
20-
out = array()
21-
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,\
20+
out = Array()
21+
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
2222
AF_MAT_TRANS, AF_MAT_NONE))
2323
return out
2424

2525
def matmulNT(lhs, rhs):
26-
out = array()
27-
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,\
26+
out = Array()
27+
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
2828
AF_MAT_NONE, AF_MAT_TRANS))
2929
return out
3030

3131
def matmulTT(lhs, rhs):
32-
out = array()
33-
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,\
32+
out = Array()
33+
safe_call(clib.af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
3434
AF_MAT_TRANS, AF_MAT_TRANS))
3535
return out
3636

3737
def dot(lhs, rhs, lhs_opts=AF_MAT_NONE, rhs_opts=AF_MAT_NONE):
38-
out = array()
39-
safe_call(clib.af_dot(ct.pointer(out.arr), lhs.arr, rhs.arr,\
38+
out = Array()
39+
safe_call(clib.af_dot(ct.pointer(out.arr), lhs.arr, rhs.arr,
4040
lhs_opts, rhs_opts))
4141
return out

0 commit comments

Comments
 (0)