@@ -22,54 +22,55 @@ ctypedef fused out_t:
22
22
def diff_2d(ndarray[diff_t, ndim=2] arr,
23
23
ndarray[out_t, ndim=2] out,
24
24
Py_ssize_t periods, int axis):
25
+ cdef:
26
+ Py_ssize_t i, j, sx, sy
25
27
26
28
# Disable for unsupported dtype combinations,
27
29
# see https://github.com/cython/cython/issues/2646
28
- if out_t is float32_t:
29
- if not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t):
30
- raise NotImplementedError
30
+ if (out_t is float32_t
31
+ and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
32
+ raise NotImplementedError
33
+ elif (out_t is float64_t
34
+ and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
35
+ raise NotImplementedError
31
36
else:
32
- if (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t):
33
- raise NotImplementedError
34
-
35
- cdef:
36
- Py_ssize_t i, j, sx, sy
37
-
38
- sx, sy = (<object>arr).shape
39
- if arr.flags.f_contiguous:
40
- if axis == 0:
41
- if periods >= 0:
42
- start, stop = periods, sx
37
+ # We put this inside an indented else block to avoid cython build
38
+ # warnings about unreachable code
39
+ sx, sy = (<object>arr).shape
40
+ if arr.flags.f_contiguous:
41
+ if axis == 0:
42
+ if periods >= 0:
43
+ start, stop = periods, sx
44
+ else:
45
+ start, stop = 0, sx + periods
46
+ for j in range(sy):
47
+ for i in range(start, stop):
48
+ out[i, j] = arr[i, j] - arr[i - periods, j]
43
49
else:
44
- start, stop = 0, sx + periods
45
- for j in range(sy):
46
- for i in range(start, stop):
47
- out[i, j] = arr[i, j] - arr[i - periods, j]
50
+ if periods >= 0:
51
+ start, stop = periods, sy
52
+ else:
53
+ start, stop = 0, sy + periods
54
+ for j in range(start, stop):
55
+ for i in range(sx):
56
+ out[i, j] = arr[i, j] - arr[i, j - periods]
48
57
else:
49
- if periods >= 0:
50
- start, stop = periods, sy
58
+ if axis == 0:
59
+ if periods >= 0:
60
+ start, stop = periods, sx
61
+ else:
62
+ start, stop = 0, sx + periods
63
+ for i in range(start, stop):
64
+ for j in range(sy):
65
+ out[i, j] = arr[i, j] - arr[i - periods, j]
51
66
else:
52
- start, stop = 0, sy + periods
53
- for j in range(start, stop):
67
+ if periods >= 0:
68
+ start, stop = periods, sy
69
+ else:
70
+ start, stop = 0, sy + periods
54
71
for i in range(sx):
55
- out[i, j] = arr[i, j] - arr[i, j - periods]
56
- else:
57
- if axis == 0:
58
- if periods >= 0:
59
- start, stop = periods, sx
60
- else:
61
- start, stop = 0, sx + periods
62
- for i in range(start, stop):
63
- for j in range(sy):
64
- out[i, j] = arr[i, j] - arr[i - periods, j]
65
- else:
66
- if periods >= 0:
67
- start, stop = periods, sy
68
- else:
69
- start, stop = 0, sy + periods
70
- for i in range(sx):
71
- for j in range(start, stop):
72
- out[i, j] = arr[i, j] - arr[i, j - periods]
72
+ for j in range(start, stop):
73
+ out[i, j] = arr[i, j] - arr[i, j - periods]
73
74
74
75
75
76
# ----------------------------------------------------------------------
0 commit comments