Skip to content

Commit 637783a

Browse files
committed
Get rid of most of the cython C code build warnings.
1 parent 1732459 commit 637783a

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

pygpu/gpuarray.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cdef extern from "numpy/arrayobject.h":
1616
cdef object PyArray_Empty(int a, np.npy_intp *b, np.dtype c, int d)
1717

1818
cdef extern from "Python.h":
19-
int PySlice_GetIndicesEx(slice_object slice, Py_ssize_t length,
19+
int PySlice_GetIndicesEx(object slice, Py_ssize_t length,
2020
Py_ssize_t *start, Py_ssize_t *stop,
2121
Py_ssize_t *step,
2222
Py_ssize_t *slicelength) except -1

pygpu/gpuarray.pyx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ cdef int strides_ok(GpuArray a, strides):
235235
return 0
236236
upper += max_axis_offset
237237
else:
238-
if lower < -max_axis_offset:
238+
if lower < <size_t>(-max_axis_offset):
239239
return 0
240240
lower += max_axis_offset
241241
return (upper + itemsize) <= size
@@ -874,7 +874,7 @@ def from_gpudata(size_t data, offset, dtype, shape, GpuContext context=None,
874874
free(cdims)
875875
free(cstrides)
876876

877-
def array(proto, dtype=None, copy=True, order=None, int ndmin=0,
877+
def array(proto, dtype=None, copy=True, order=None, unsigned int ndmin=0,
878878
GpuContext context=None, cls=None):
879879
"""
880880
array(obj, dtype='float64', copy=True, order=None, ndmin=0, context=None, cls=None)
@@ -890,7 +890,7 @@ def array(proto, dtype=None, copy=True, order=None, int ndmin=0,
890890
:param order: memory layout of the result
891891
:type order: string
892892
:param ndmin: minimum number of result dimensions
893-
:type ndmin: int
893+
:type ndmin: unsigned int
894894
:param context: allocation context
895895
:type context: GpuContext
896896
:param cls: result class (must inherit from GpuArray)
@@ -1384,21 +1384,24 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
13841384
if compute_axis < 0:
13851385
array_reshape(res, a, nd, newdims, ord, nocopy)
13861386
return res
1387-
if compute_axis >= nd:
1387+
cdef unsigned int caxis = <unsigned int>compute_axis
1388+
if caxis >= nd:
13881389
raise ValueError("You wanted us to compute the shape of a dimensions that don't exist")
13891390

13901391
cdef size_t *cdims
13911392
cdef size_t tot = 1
1393+
cdef unsigned int i
13921394
for i in range(nd):
1393-
if i != compute_axis:
1395+
if i != caxis:
13941396
tot *= newdims[i]
13951397
cdims = <size_t *>calloc(nd, sizeof(size_t))
13961398
if cdims == NULL:
13971399
raise MemoryError, "could not allocate cdims"
13981400

1401+
cdef size_t d
13991402
for i in range(nd):
14001403
d = newdims[i]
1401-
if i == compute_axis:
1404+
if i == caxis:
14021405
d = a.size // tot
14031406

14041407
if d * tot != a.size:
@@ -1537,7 +1540,7 @@ cdef class GpuArray:
15371540
k = PyNumber_Index(key)
15381541
if k < 0:
15391542
k += self.ga.dimensions[i]
1540-
if k < 0 or k >= self.ga.dimensions[i]:
1543+
if k < 0 or (<size_t>k) >= self.ga.dimensions[i]:
15411544
raise IndexError, "index %d out of bounds" % (i,)
15421545
start[0] = k
15431546
step[0] = 0
@@ -1546,9 +1549,7 @@ cdef class GpuArray:
15461549
pass
15471550

15481551
if isinstance(key, slice):
1549-
# C compiler complains about argument 1 (key) because it's
1550-
# declared as a PyObject. But we know it's a slice so it's ok.
1551-
PySlice_GetIndicesEx(<slice_object>key, self.ga.dimensions[i],
1552+
PySlice_GetIndicesEx(key, self.ga.dimensions[i],
15521553
start, stop, step, &dummy)
15531554
if stop[0] < start[0] and step[0] > 0:
15541555
stop[0] = start[0]

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,41 @@ def __init__(self, *args, **kwargs):
9797
fullversion = "%s"
9898
""" % (MAJOR, MINOR, PATCH, SUFFIX, FULLVERSION))
9999

100+
ea = []
101+
if sys.platform in ('darwin', 'linux'):
102+
# Silence unused stuff warnings
103+
ea = ["-Wno-unused-variable", "-Wno-unused-function"]
104+
100105
exts = [Extension('pygpu.gpuarray',
101106
sources=['pygpu/gpuarray.pyx'],
102107
include_dirs=include_dirs,
103108
libraries=['gpuarray'],
104109
library_dirs=library_dirs,
110+
extra_compile_args=ea,
105111
define_macros=[('GPUARRAY_SHARED', None)]
106112
),
107113
Extension('pygpu.blas',
108114
sources=['pygpu/blas.pyx'],
109115
include_dirs=include_dirs,
110116
libraries=['gpuarray'],
111117
library_dirs=library_dirs,
118+
extra_compile_args=ea,
112119
define_macros=[('GPUARRAY_SHARED', None)]
113120
),
114121
Extension('pygpu._elemwise',
115122
sources=['pygpu/_elemwise.pyx'],
116123
include_dirs=include_dirs,
117124
libraries=['gpuarray'],
118125
library_dirs=library_dirs,
126+
extra_compile_args=ea,
119127
define_macros=[('GPUARRAY_SHARED', None)]
120128
),
121129
Extension('pygpu.collectives',
122130
sources=['pygpu/collectives.pyx'],
123131
include_dirs=include_dirs,
124132
libraries=['gpuarray'],
125133
library_dirs=library_dirs,
134+
extra_compile_args=ea,
126135
define_macros=[('GPUARRAY_SHARED', None)]
127136
)]
128137

0 commit comments

Comments
 (0)