numpy
2.0.0
|
00001 #ifndef _NPY_INCLUDE_NEIGHBORHOOD_IMP 00002 #error You should not include this header directly 00003 #endif 00004 /* 00005 * Private API (here for inline) 00006 */ 00007 static NPY_INLINE int 00008 _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter); 00009 00010 /* 00011 * Update to next item of the iterator 00012 * 00013 * Note: this simply increment the coordinates vector, last dimension 00014 * incremented first , i.e, for dimension 3 00015 * ... 00016 * -1, -1, -1 00017 * -1, -1, 0 00018 * -1, -1, 1 00019 * .... 00020 * -1, 0, -1 00021 * -1, 0, 0 00022 * .... 00023 * 0, -1, -1 00024 * 0, -1, 0 00025 * .... 00026 */ 00027 #define _UPDATE_COORD_ITER(c) \ 00028 wb = iter->coordinates[c] < iter->bounds[c][1]; \ 00029 if (wb) { \ 00030 iter->coordinates[c] += 1; \ 00031 return 0; \ 00032 } \ 00033 else { \ 00034 iter->coordinates[c] = iter->bounds[c][0]; \ 00035 } 00036 00037 static NPY_INLINE int 00038 _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter) 00039 { 00040 npy_intp i, wb; 00041 00042 for (i = iter->nd - 1; i >= 0; --i) { 00043 _UPDATE_COORD_ITER(i) 00044 } 00045 00046 return 0; 00047 } 00048 00049 /* 00050 * Version optimized for 2d arrays, manual loop unrolling 00051 */ 00052 static NPY_INLINE int 00053 _PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter) 00054 { 00055 npy_intp wb; 00056 00057 _UPDATE_COORD_ITER(1) 00058 _UPDATE_COORD_ITER(0) 00059 00060 return 0; 00061 } 00062 #undef _UPDATE_COORD_ITER 00063 00064 /* 00065 * Advance to the next neighbour 00066 */ 00067 static NPY_INLINE int 00068 PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter) 00069 { 00070 _PyArrayNeighborhoodIter_IncrCoord (iter); 00071 iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates); 00072 00073 return 0; 00074 } 00075 00076 /* 00077 * Reset functions 00078 */ 00079 static NPY_INLINE int 00080 PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter) 00081 { 00082 npy_intp i; 00083 00084 for (i = 0; i < iter->nd; ++i) { 00085 iter->coordinates[i] = iter->bounds[i][0]; 00086 } 00087 iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates); 00088 00089 return 0; 00090 }