Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
#ifndef _NPY_INCLUDE_NEIGHBORHOOD_IMP
|
|
2 |
#error You should not include this header directly
|
|
3 |
#endif
|
|
4 |
/*
|
|
5 |
* Private API (here for inline)
|
|
6 |
*/
|
|
7 |
static NPY_INLINE int |
|
8 |
_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter); |
|
9 |
|
|
10 |
/*
|
|
11 |
* Update to next item of the iterator
|
|
12 |
*
|
|
13 |
* Note: this simply increment the coordinates vector, last dimension
|
|
14 |
* incremented first , i.e, for dimension 3
|
|
15 |
* ...
|
|
16 |
* -1, -1, -1
|
|
17 |
* -1, -1, 0
|
|
18 |
* -1, -1, 1
|
|
19 |
* ....
|
|
20 |
* -1, 0, -1
|
|
21 |
* -1, 0, 0
|
|
22 |
* ....
|
|
23 |
* 0, -1, -1
|
|
24 |
* 0, -1, 0
|
|
25 |
* ....
|
|
26 |
*/
|
|
27 |
#define _UPDATE_COORD_ITER(c) \
|
|
28 |
wb = iter->coordinates[c] < iter->bounds[c][1]; \
|
|
29 |
if (wb) { \
|
|
30 |
iter->coordinates[c] += 1; \
|
|
31 |
return 0; \
|
|
32 |
} \
|
|
33 |
else { \
|
|
34 |
iter->coordinates[c] = iter->bounds[c][0]; \
|
|
35 |
}
|
|
36 |
|
|
37 |
static NPY_INLINE int |
|
38 |
_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter) |
|
39 |
{
|
|
40 |
npy_intp i, wb; |
|
41 |
|
|
42 | 1 |
for (i = iter->nd - 1; i >= 0; --i) { |
43 | 1 |
_UPDATE_COORD_ITER(i) |
44 |
}
|
|
45 |
|
|
46 |
return 0; |
|
47 |
}
|
|
48 |
|
|
49 |
/*
|
|
50 |
* Version optimized for 2d arrays, manual loop unrolling
|
|
51 |
*/
|
|
52 |
static NPY_INLINE int |
|
53 |
_PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter) |
|
54 |
{
|
|
55 |
npy_intp wb; |
|
56 |
|
|
57 |
_UPDATE_COORD_ITER(1) |
|
58 |
_UPDATE_COORD_ITER(0) |
|
59 |
|
|
60 |
return 0; |
|
61 |
}
|
|
62 |
#undef _UPDATE_COORD_ITER
|
|
63 |
|
|
64 |
/*
|
|
65 |
* Advance to the next neighbour
|
|
66 |
*/
|
|
67 |
static NPY_INLINE int |
|
68 | 1 |
PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter) |
69 |
{
|
|
70 | 1 |
_PyArrayNeighborhoodIter_IncrCoord (iter); |
71 | 1 |
iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates); |
72 |
|
|
73 | 1 |
return 0; |
74 |
}
|
|
75 |
|
|
76 |
/*
|
|
77 |
* Reset functions
|
|
78 |
*/
|
|
79 |
static NPY_INLINE int |
|
80 |
PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter) |
|
81 |
{
|
|
82 |
npy_intp i; |
|
83 |
|
|
84 | 1 |
for (i = 0; i < iter->nd; ++i) { |
85 | 1 |
iter->coordinates[i] = iter->bounds[i][0]; |
86 |
}
|
|
87 | 1 |
iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates); |
88 |
|
|
89 |
return 0; |
|
90 |
}
|
Read our documentation on viewing source code .