Skip to content

Commit 177bb37

Browse files
authored
Merge pull request #453 from abergeron/multi_kernel
Remove old unused stuff + flake8
2 parents d641fb5 + 2932294 commit 177bb37

17 files changed

Lines changed: 236 additions & 343 deletions

pygpu/_array.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def __divmod__(self, other):
143143
mod = self._empty_like_me(dtype=odtype)
144144

145145
if odtype.kind == 'f':
146-
tmpl = "div = floor((%(out_t)s)a / (%(out_t)s)b)," \
147-
"mod = fmod((%(out_t)s)a, (%(out_t)s)b)"
146+
tmpl = ("div = floor((%(out_t)s)a / (%(out_t)s)b),"
147+
"mod = fmod((%(out_t)s)a, (%(out_t)s)b)")
148148
else:
149-
tmpl = "div = (%(out_t)s)a / (%(out_t)s)b," \
150-
"mod = a %% b"
149+
tmpl = ("div = (%(out_t)s)a / (%(out_t)s)b,"
150+
"mod = a %% b")
151151

152152
ksrc = tmpl % {'out_t': dtype_to_ctype(odtype)}
153153

@@ -168,11 +168,11 @@ def __rdivmod__(self, other):
168168
mod = self._empty_like_me(dtype=odtype)
169169

170170
if odtype.kind == 'f':
171-
tmpl = "div = floor((%(out_t)s)a / (%(out_t)s)b)," \
172-
"mod = fmod((%(out_t)s)a, (%(out_t)s)b)"
171+
tmpl = ("div = floor((%(out_t)s)a / (%(out_t)s)b),"
172+
"mod = fmod((%(out_t)s)a, (%(out_t)s)b)")
173173
else:
174-
tmpl = "div = (%(out_t)s)a / (%(out_t)s)b," \
175-
"mod = a %% b"
174+
tmpl = ("div = (%(out_t)s)a / (%(out_t)s)b,"
175+
"mod = a %% b")
176176

177177
ksrc = tmpl % {'out_t': dtype_to_ctype(odtype)}
178178

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/gpuarray.pyx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,8 @@ cdef GpuArray pygpu_empty_like(GpuArray a, ga_order ord, int typecode):
13741374
cdef GpuArray res
13751375

13761376
if ord == GA_ANY_ORDER:
1377-
if py_CHKFLAGS(a, GA_F_CONTIGUOUS) and \
1378-
not py_CHKFLAGS(a, GA_C_CONTIGUOUS):
1377+
if (py_CHKFLAGS(a, GA_F_CONTIGUOUS) and
1378+
not py_CHKFLAGS(a, GA_C_CONTIGUOUS)):
13791379
ord = GA_F_ORDER
13801380
else:
13811381
ord = GA_C_ORDER
@@ -1691,8 +1691,10 @@ cdef class GpuArray:
16911691
"""
16921692
if not np.PyArray_ISBEHAVED(dst):
16931693
raise ValueError, "Destination Numpy array is not well behaved: aligned and writeable"
1694-
if not ((self.flags.c_contiguous and self.flags.aligned and dst.flags['C_CONTIGUOUS']) or \
1695-
(self.flags.f_contiguous and self.flags.aligned and dst.flags['F_CONTIGUOUS'])):
1694+
if (not ((self.flags.c_contiguous and self.flags.aligned and
1695+
dst.flags['C_CONTIGUOUS']) or
1696+
(self.flags.f_contiguous and self.flags.aligned and
1697+
dst.flags['F_CONTIGUOUS']))):
16961698
raise ValueError, "GpuArray and Numpy array do not match in contiguity or GpuArray is not aligned"
16971699
if self.dtype != dst.dtype:
16981700
raise ValueError, "GpuArray and Numpy array do not have matching data types"
@@ -2036,13 +2038,13 @@ cdef class GpuArray:
20362038
# is also required for numpy compat.
20372039
el = key.index(Ellipsis)
20382040
if isinstance(key, tuple):
2039-
key = key[:el] + \
2040-
(Ellipsis,)*(self.ga.nd - (len(key) - 1)) + \
2041-
key[el+1:]
2041+
key = (key[:el] +
2042+
(Ellipsis,)*(self.ga.nd - (len(key) - 1)) +
2043+
key[el+1:])
20422044
else:
2043-
key = key[:el] + \
2044-
[Ellipsis,]*(self.ga.nd - (len(key) - 1)) + \
2045-
key[el+1:]
2045+
key = (key[:el] +
2046+
[Ellipsis,]*(self.ga.nd - (len(key) - 1)) +
2047+
key[el+1:])
20462048
if len(key) > self.ga.nd:
20472049
raise IndexError, "too many indices"
20482050
for i in range(0, len(key)):

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import print_function
22

3-
import os, sys
3+
import os
4+
import sys
5+
46
import numpy
57
from nose.plugins.skip import SkipTest
68

@@ -22,11 +24,14 @@
2224
dtypes_no_complex_big = ["float32", "float64", "int16", "uint16",
2325
"int32", "int64", "uint32", "uint64"]
2426

27+
2528
def get_env_dev():
2629
for name in ['GPUARRAY_TEST_DEVICE', 'DEVICE']:
2730
if name in os.environ:
2831
return os.environ[name]
29-
raise RuntimeError("No test device specified. Specify one using the DEVICE or GPUARRAY_TEST_DEVICE environment variables.")
32+
raise RuntimeError(
33+
"No test device specified. Specify one using the DEVICE "
34+
"or GPUARRAY_TEST_DEVICE environment variables.")
3035

3136

3237
context = gpuarray.init(get_env_dev())

0 commit comments

Comments
 (0)