Skip to content

Commit 5b54f6d

Browse files
committed
Flake8
1 parent df16859 commit 5b54f6d

9 files changed

Lines changed: 115 additions & 102 deletions

File tree

pygpu/dtypes.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,20 @@ def register_dtype(dtype, c_names):
7171

7272

7373
def _fill_dtype_registry():
74-
from sys import platform
75-
7674
register_dtype(np.bool, ["ga_bool", "bool"])
7775
register_dtype(np.int8, ["ga_byte", "char", "signed char"])
7876
register_dtype(np.uint8, ["ga_ubyte", "unsigned char"])
79-
register_dtype(np.int16, ["ga_short", "short", "signed short", "signed short int", "short signed int"])
80-
register_dtype(np.uint16, ["ga_ushort", "unsigned short", "unsigned short int", "short unsigned int"])
77+
register_dtype(np.int16, ["ga_short", "short", "signed short",
78+
"signed short int", "short signed int"])
79+
register_dtype(np.uint16, ["ga_ushort", "unsigned short",
80+
"unsigned short int", "short unsigned int"])
8181
register_dtype(np.int32, ["ga_int", "int", "signed int"])
8282
register_dtype(np.uint32, ["ga_uint", "unsigned", "unsigned int"])
8383

84-
register_dtype(np.int64, ["ga_long", "long int", "signed long int", "long signed int"])
85-
register_dtype(np.uint64, ["ga_ulong", "unsigned long", "unsigned long int", "long unsigned int"])
84+
register_dtype(np.int64, ["ga_long", "long int", "signed long int",
85+
"long signed int"])
86+
register_dtype(np.uint64, ["ga_ulong", "unsigned long",
87+
"unsigned long int", "long unsigned int"])
8688

8789
register_dtype(np.intp, ["ga_ssize", "ssize_t"])
8890
register_dtype(np.uintp, ["ga_size", "size_t"])

pygpu/operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .gpuarray import _split, _concatenate, dtype_to_typecode
44
from .dtypes import upcast
5-
from . import array, asarray
5+
from . import asarray
66

77

88
def atleast_1d(*arys):
@@ -82,7 +82,8 @@ def array_split(ary, indices_or_sections, axis=0):
8282
# this madness is to support the numpy interface
8383
# it is supported by tests, but little else
8484
divs = (list(range(neach + 1, (neach + 1) * extra + 1, neach + 1)) +
85-
list(range((neach + 1) * extra + neach, ary.shape[axis], neach)))
85+
list(range((neach + 1) * extra + neach,
86+
ary.shape[axis], neach)))
8687
res = _split(ary, divs, axis)
8788
return res
8889

pygpu/reduction.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def _ceil_log2(x):
2929
else:
3030
return 0
3131

32+
3233
basic_kernel = Template("""
3334
${preamble}
3435
@@ -141,14 +142,16 @@ def __init__(self, context, dtype_out, neutral, reduce_expr, redux,
141142
if isinstance(arguments, str):
142143
self.arguments = parse_c_args(arguments)
143144
elif arguments is None:
144-
self.arguments = [ArrayArg(numpy.dtype(self.dtype_out), '_reduce_input')]
145+
self.arguments = [ArrayArg(numpy.dtype(self.dtype_out),
146+
'_reduce_input')]
145147
else:
146148
self.arguments = arguments
147149

148150
if (self.dtype_out == numpy.dtype('float16') or
149151
any(ar.dtype == numpy.dtype('float16')
150152
for ar in self.arguments)):
151-
raise NotImplementedError('float16 not supported for the reduction interface')
153+
raise NotImplementedError('float16 not supported for the '
154+
'reduction interface')
152155

153156
self.reduce_expr = reduce_expr
154157
if map_expr is None:

pygpu/tests/main.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import nose.plugins.builtin
32

43
from nose.config import Config
54
from nose.plugins.manager import PluginManager
@@ -29,25 +28,23 @@ def _test_argv(self, verbose, extra_argv):
2928
List with any extra arguments to pass to nosetests.
3029
3130
"""
32-
#self.package_path = os.path.abspath(self.package_path)
31+
# self.package_path = os.path.abspath(self.package_path)
3332
argv = [__file__, self.package_path]
3433
argv += ['--verbosity', str(verbose)]
3534
if extra_argv:
3635
argv += extra_argv
3736
return argv
3837

3938
def _show_system_info(self):
40-
nose = import_nose()
41-
4239
import pygpu
43-
#print ("pygpu version %s" % pygpu.__version__)
40+
# print ("pygpu version %s" % pygpu.__version__)
4441
pygpu_dir = os.path.dirname(pygpu.__file__)
45-
print ("pygpu is installed in %s" % pygpu_dir)
42+
print("pygpu is installed in %s" % pygpu_dir)
4643

4744
super(NoseTester, self)._show_system_info()
4845

4946
def prepare_test_args(self, verbose=1, extra_argv=None, coverage=False,
50-
capture=True, knownfailure=True):
47+
capture=True, knownfailure=True):
5148
"""
5249
Prepare arguments for the `test` method.
5350
@@ -61,8 +58,9 @@ def prepare_test_args(self, verbose=1, extra_argv=None, coverage=False,
6158

6259
# numpy way of doing coverage
6360
if coverage:
64-
argv += ['--cover-package=%s' % self.package_name, '--with-coverage',
65-
'--cover-tests', '--cover-inclusive', '--cover-erase']
61+
argv += ['--cover-package=%s' % self.package_name,
62+
'--with-coverage', '--cover-tests', '--cover-inclusive',
63+
'--cover-erase']
6664

6765
# Capture output only if needed
6866
if not capture:
@@ -77,7 +75,7 @@ def prepare_test_args(self, verbose=1, extra_argv=None, coverage=False,
7775
return argv, plugins
7876

7977
def test(self, verbose=1, extra_argv=None, coverage=False, capture=True,
80-
knownfailure=True):
78+
knownfailure=True):
8179
"""
8280
Run tests for module using nose.
8381
@@ -122,28 +120,11 @@ def test(self, verbose=1, extra_argv=None, coverage=False, capture=True,
122120
"launch pygpu.test()."))
123121

124122
argv, plugins = self.prepare_test_args(verbose, extra_argv, coverage,
125-
capture, knownfailure)
123+
capture, knownfailure)
126124

127125
# The "plugins" keyword of NumpyTestProgram gets ignored if config is
128126
# specified. Moreover, using "addplugins" instead can lead to strange
129127
# errors. So, we specify the plugins in the Config as well.
130128
cfg = Config(includeExe=True, plugins=PluginManager(plugins=plugins))
131129
t = NumpyTestProgram(argv=argv, exit=False, config=cfg)
132130
return t.result
133-
134-
135-
def main(modulename):
136-
debug = False
137-
138-
if 0:
139-
unittest.main()
140-
elif len(sys.argv)==2 and sys.argv[1]=="--debug":
141-
module = __import__(modulename)
142-
tests = unittest.TestLoader().loadTestsFromModule(module)
143-
tests.debug()
144-
elif len(sys.argv)==1:
145-
module = __import__(modulename)
146-
tests = unittest.TestLoader().loadTestsFromModule(module)
147-
unittest.TextTestRunner(verbosity=2).run(tests)
148-
else:
149-
print ("options: [--debug]")

pygpu/tests/support.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22

3-
import os, sys
3+
import os
4+
import sys
45
import numpy
56
from nose.plugins.skip import SkipTest
67

@@ -22,11 +23,14 @@
2223
dtypes_no_complex_big = ["float32", "float64", "int16", "uint16",
2324
"int32", "int64", "uint32", "uint64"]
2425

26+
2527
def get_env_dev():
2628
for name in ['GPUARRAY_TEST_DEVICE', 'DEVICE']:
2729
if name in os.environ:
2830
return os.environ[name]
29-
raise RuntimeError("No test device specified. Specify one using the DEVICE or GPUARRAY_TEST_DEVICE environment variables.")
31+
raise RuntimeError(
32+
"No test device specified. Specify one using the DEVICE "
33+
"or GPUARRAY_TEST_DEVICE environment variables.")
3034

3135

3236
context = gpuarray.init(get_env_dev())

pygpu/tests/test_blas.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,27 @@
1515

1616
import pygpu.blas as gblas
1717

18+
1819
def test_dot():
1920
bools = [True, False]
2021
for N, dtype, offseted_i, sliced in product(
21-
[1, 256, 1337], ['float32', 'float64'], bools, bools):
22+
[1, 256, 1337], ['float32', 'float64'], bools, bools):
2223
yield dot, N, dtype, offseted_i, sliced, True, False
2324
for overwrite, init_z in product(bools, bools):
2425
yield dot, 666, 'float32', False, False, overwrite, init_z
2526

27+
2628
@guard_devsup
2729
def dot(N, dtype, offseted_i, sliced, overwrite, init_z):
2830
cX, gX = gen_gpuarray((N,), dtype, offseted_inner=offseted_i,
2931
sliced=sliced, ctx=context)
3032
cY, gY = gen_gpuarray((N,), dtype, offseted_inner=offseted_i,
3133
sliced=sliced, ctx=context)
3234
if init_z:
33-
_, gZ = gen_gpuarray((), dtype, offseted_inner=offseted_i,
34-
sliced=sliced, ctx=context)
35+
gZ = gen_gpuarray((), dtype, offseted_inner=offseted_i,
36+
sliced=sliced, ctx=context)[1]
3537
else:
36-
_, gZ = None, None
38+
gZ = None
3739

3840
if dtype == 'float32':
3941
cr = fblas.sdot(cX, cY)
@@ -46,21 +48,22 @@ def dot(N, dtype, offseted_i, sliced, overwrite, init_z):
4648
def test_gemv():
4749
bools = [False, True]
4850
for shape, order, trans, offseted_i, sliced in product(
49-
[(100, 128), (128, 50)], 'fc', bools, bools, [1, 2, -1, -2]):
51+
[(100, 128), (128, 50)], 'fc', bools, bools, [1, 2, -1, -2]):
5052
yield gemv, shape, 'float32', order, trans, \
5153
offseted_i, sliced, True, False
5254
for overwrite, init_y in product(bools, bools):
5355
yield gemv, (4, 3), 'float32', 'f', False, False, 1, \
5456
overwrite, init_y
5557
yield gemv, (32, 32), 'float64', 'f', False, False, 1, True, False
5658
for alpha, beta, overwrite in product(
57-
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
59+
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
5860
yield gemv, (32, 32), 'float32', 'f', False, False, 1, \
5961
overwrite, True, alpha, beta
6062

63+
6164
@guard_devsup
6265
def gemv(shp, dtype, order, trans, offseted_i, sliced,
63-
overwrite, init_y, alpha=1.0, beta=0.0):
66+
overwrite, init_y, alpha=1.0, beta=0.0):
6467
cA, gA = gen_gpuarray(shp, dtype, order=order, offseted_inner=offseted_i,
6568
sliced=sliced, ctx=context)
6669
if trans:
@@ -92,31 +95,31 @@ def test_gemm():
9295
bools = [False, True]
9396
for (m, n, k), order, trans, offseted_o in product(
9497
[(48, 15, 32), (15, 32, 48)], list(product(*['fc']*3)),
95-
list(product(bools, bools)), bools):
98+
list(product(bools, bools)), bools):
9699
yield gemm, m, n, k, 'float32', order, trans, \
97100
offseted_o, 1, False, False
98-
for sliced, overwrite, init_res in product(
99-
[1, 2, -1, -2], bools, bools):
101+
for sliced, overwrite, init_res in product([1, 2, -1, -2], bools, bools):
100102
yield gemm, 4, 3, 2, 'float32', ('f', 'f', 'f'), \
101103
(False, False), False, sliced, overwrite, init_res
102104
yield gemm, 32, 32, 32, 'float64', ('f', 'f', 'f'), (False, False), \
103105
False, 1, False, False
104106
for alpha, beta, overwrite in product(
105-
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
107+
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
106108
yield gemm, 32, 23, 32, 'float32', ('f', 'f', 'f'), \
107109
(False, False), False, 1, overwrite, True, alpha, beta
108110

111+
109112
@guard_devsup
110113
def gemm(m, n, k, dtype, order, trans, offseted_o, sliced, overwrite,
111114
init_res, alpha=1.0, beta=0.0):
112115
if trans[0]:
113-
shpA = (k,m)
116+
shpA = (k, m)
114117
else:
115-
shpA = (m,k)
118+
shpA = (m, k)
116119
if trans[1]:
117-
shpB = (n,k)
120+
shpB = (n, k)
118121
else:
119-
shpB = (k,n)
122+
shpB = (k, n)
120123

121124
cA, gA = gen_gpuarray(shpA, dtype, order=order[0],
122125
offseted_outer=offseted_o,
@@ -125,7 +128,7 @@ def gemm(m, n, k, dtype, order, trans, offseted_o, sliced, overwrite,
125128
offseted_outer=offseted_o,
126129
sliced=sliced, ctx=context)
127130
if init_res:
128-
cC, gC = gen_gpuarray((m,n), dtype, order=order[2], ctx=context)
131+
cC, gC = gen_gpuarray((m, n), dtype, order=order[2], ctx=context)
129132
else:
130133
cC, gC = None, None
131134

@@ -143,13 +146,14 @@ def gemm(m, n, k, dtype, order, trans, offseted_o, sliced, overwrite,
143146

144147
def test_ger():
145148
bools = [False, True]
146-
for (m,n), order, sliced_x, sliced_y in product(
147-
[(4,5)], 'fc', [1, 2, -2, -1], [1, 2, -2, -1]):
149+
for (m, n), order, sliced_x, sliced_y in product(
150+
[(4, 5)], 'fc', [1, 2, -2, -1], [1, 2, -2, -1]):
148151
yield ger, m, n, 'float32', order, sliced_x, sliced_y, False
149152
yield ger, 4, 5, 'float64', 'f', 1, 1, False
150153
for init_res, overwrite in product(bools, bools):
151154
yield ger, 4, 5, 'float32', 'f', 1, 1, init_res, overwrite
152155

156+
153157
def ger(m, n, dtype, order, sliced_x, sliced_y, init_res, overwrite=False):
154158
cX, gX = gen_gpuarray((m,), dtype, order, sliced=sliced_x, ctx=context)
155159
cY, gY = gen_gpuarray((n,), dtype, order, sliced=sliced_y, ctx=context)
@@ -168,35 +172,37 @@ def ger(m, n, dtype, order, sliced_x, sliced_y, init_res, overwrite=False):
168172

169173
numpy.testing.assert_allclose(cr, numpy.asarray(gr), rtol=1e-6)
170174

175+
171176
def test_rgemmBatch_3d():
172177
bools = [False, True]
173178
for b, (m, n, k), order, trans, offseted_o in product(
174-
[1, 17, 31], [(24, 7, 16), (7, 16, 24)], list(product('fc', 'fc', 'c')),
175-
list(product(bools, bools)), bools):
179+
[1, 17, 31], [(24, 7, 16), (7, 16, 24)],
180+
list(product('fc', 'fc', 'c')),
181+
list(product(bools, bools)), bools):
176182
yield rgemmBatch_3d, b, m, n, k, 'float32', order, trans, \
177183
offseted_o, 1, False, False
178-
for sliced, overwrite, init_res in product(
179-
[1, 2, -1, -2], bools, bools):
184+
for sliced, overwrite, init_res in product([1, 2, -1, -2], bools, bools):
180185
yield rgemmBatch_3d, 5, 4, 3, 2, 'float32', ('f', 'f', 'c'), \
181186
(False, False), False, sliced, overwrite, init_res
182-
yield rgemmBatch_3d, 16, 16, 16, 16, 'float64', ('f', 'f', 'c'), (False, False), \
183-
False, 1, False, False
187+
yield rgemmBatch_3d, 16, 16, 16, 16, 'float64', ('f', 'f', 'c'), \
188+
(False, False), False, 1, False, False
184189
for alpha, beta, overwrite in product(
185-
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
190+
[0, 1, -1, 0.6], [0, 1, -1, 0.6], bools):
186191
yield rgemmBatch_3d, 16, 16, 9, 16, 'float32', ('f', 'f', 'c'), \
187192
(False, False), False, 1, overwrite, True, alpha, beta
188193

194+
189195
@guard_devsup
190-
def rgemmBatch_3d(b, m, n, k, dtype, order, trans, offseted_o, sliced, overwrite,
191-
init_res, alpha=1.0, beta=0.0):
196+
def rgemmBatch_3d(b, m, n, k, dtype, order, trans, offseted_o, sliced,
197+
overwrite, init_res, alpha=1.0, beta=0.0):
192198
if trans[0]:
193-
shpA = (b,k,m)
199+
shpA = (b, k, m)
194200
else:
195-
shpA = (b,m,k)
201+
shpA = (b, m, k)
196202
if trans[1]:
197-
shpB = (b,n,k)
203+
shpB = (b, n, k)
198204
else:
199-
shpB = (b,k,n)
205+
shpB = (b, k, n)
200206

201207
cA, gA = gen_gpuarray(shpA, dtype, order=order[0],
202208
offseted_outer=offseted_o,
@@ -205,21 +211,21 @@ def rgemmBatch_3d(b, m, n, k, dtype, order, trans, offseted_o, sliced, overwrite
205211
offseted_outer=offseted_o,
206212
sliced=sliced, ctx=context)
207213
if init_res:
208-
cC, gC = gen_gpuarray((b,m,n), dtype, order=order[2], ctx=context)
214+
cC, gC = gen_gpuarray((b, m, n), dtype, order=order[2], ctx=context)
209215
else:
210216
cC, gC = None, None
211217

212-
cr = numpy.empty((b,m,n), dtype=dtype)
218+
cr = numpy.empty((b, m, n), dtype=dtype)
213219
if dtype == 'float32':
214220
fn_gemm_c = fblas.sgemm
215221
else:
216222
fn_gemm_c = fblas.dgemm
217223
for i in range(b):
218224
cCi = cC if cC is None else cC[i]
219225
cr[i] = fn_gemm_c(alpha, cA[i], cB[i], beta, cCi, trans_a=trans[0],
220-
trans_b=trans[1], overwrite_c=overwrite)
226+
trans_b=trans[1], overwrite_c=overwrite)
221227

222228
gr = gblas.gemmBatch_3d(alpha, gA, gB, beta, gC, trans_a=trans[0],
223-
trans_b=trans[1], overwrite_c=overwrite)
229+
trans_b=trans[1], overwrite_c=overwrite)
224230

225231
numpy.testing.assert_allclose(cr, numpy.asarray(gr), rtol=1e-5)

0 commit comments

Comments
 (0)