summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-07-21 12:24:29 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-07-21 12:24:29 +0000
commit32b71d5f6773d7f85f752bc252257ab32e62ca14 (patch)
tree881ba92155bd3bbef57f99cc46e317bc4852f528
parent3ab762705a35ad7ba9a726a4a80abeb741e4f8a3 (diff)
downloadnumpy-32b71d5f6773d7f85f752bc252257ab32e62ca14.tar.gz
BUG: discrepencies between 2d versions of nieghborhood iterators.
Make sure the 2D versions of the neighborhood iterator increments are implemented for every boundary mode, and that the default one supports every out of bound mode.
-rw-r--r--numpy/core/include/numpy/_neighborhood_iterator_imp.h91
1 files changed, 87 insertions, 4 deletions
diff --git a/numpy/core/include/numpy/_neighborhood_iterator_imp.h b/numpy/core/include/numpy/_neighborhood_iterator_imp.h
index 8e3e055ec..bd1ebd36d 100644
--- a/numpy/core/include/numpy/_neighborhood_iterator_imp.h
+++ b/numpy/core/include/numpy/_neighborhood_iterator_imp.h
@@ -13,6 +13,12 @@ _PyArrayNeighborhoodIter_SetPtrMirror(PyArrayNeighborhoodIterObject* iter);
static NPY_INLINE int
_PyArrayNeighborhoodIter_SetPtrCircular(PyArrayNeighborhoodIterObject* iter);
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtrConstant2D(PyArrayNeighborhoodIterObject* iter);
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtrMirror2D(PyArrayNeighborhoodIterObject* iter);
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtrCircular2D(PyArrayNeighborhoodIterObject* iter);
/*
* Update to next item of the iterator
*
@@ -81,10 +87,6 @@ _PyArrayNeighborhoodIter_SetPtrConstant(PyArrayNeighborhoodIterObject* iter)
int i;
npy_intp offset, bd;
- assert((iter->mode == NPY_NEIGHBORHOOD_ITER_ONE_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_ZERO_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING));
-
iter->dataptr = iter->_internal_iter->dataptr;
for(i = 0; i < iter->nd; ++i) {
@@ -106,6 +108,26 @@ _PyArrayNeighborhoodIter_SetPtrConstant2D(PyArrayNeighborhoodIterObject* iter)
return 0;
}
+
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtr2D(PyArrayNeighborhoodIterObject* iter)
+{
+ switch (iter->mode) {
+ case NPY_NEIGHBORHOOD_ITER_ZERO_PADDING:
+ case NPY_NEIGHBORHOOD_ITER_ONE_PADDING:
+ case NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING:
+ _PyArrayNeighborhoodIter_SetPtrConstant2D(iter);
+ break;
+ case NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING:
+ _PyArrayNeighborhoodIter_SetPtrMirror2D(iter);
+ break;
+ case NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING:
+ _PyArrayNeighborhoodIter_SetPtrCircular2D(iter);
+ break;
+ }
+
+ return 0;
+}
#undef _INF_SET_PTR
#define _NPY_IS_EVEN(x) ((x) % 2 == 0)
@@ -161,6 +183,19 @@ _PyArrayNeighborhoodIter_SetPtrMirror(PyArrayNeighborhoodIterObject* iter)
return 0;
}
+
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtrMirror2D(PyArrayNeighborhoodIterObject* iter)
+{
+ npy_intp offset, bd, truepos;
+
+ iter->dataptr = iter->_internal_iter->dataptr;
+
+ _INF_SET_PTR_MIRROR(0)
+ _INF_SET_PTR_MIRROR(1)
+
+ return 0;
+}
#undef _INF_SET_PTR_MIRROR
/* compute l such as i = k * n + l, 0 <= l < |k| */
@@ -195,6 +230,19 @@ _PyArrayNeighborhoodIter_SetPtrCircular(PyArrayNeighborhoodIterObject* iter)
return 0;
}
+
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_SetPtrCircular2D(PyArrayNeighborhoodIterObject* iter)
+{
+ npy_intp offset, bd, truepos;
+
+ iter->dataptr = iter->_internal_iter->dataptr;
+
+ _INF_SET_PTR_CIRCULAR(0)
+ _INF_SET_PTR_CIRCULAR(1)
+
+ return 0;
+}
#undef _INF_SET_PTR_CIRCULAR
/*
@@ -203,6 +251,17 @@ _PyArrayNeighborhoodIter_SetPtrCircular(PyArrayNeighborhoodIterObject* iter)
static NPY_INLINE int
PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter)
{
+ assert(iter->nd == 2);
+
+ _PyArrayNeighborhoodIter_IncrCoord2D(iter);
+ _PyArrayNeighborhoodIter_SetPtr2D(iter);
+
+ return 0;
+}
+
+static NPY_INLINE int
+PyArrayNeighborhoodIter_NextConstant2D(PyArrayNeighborhoodIterObject* iter)
+{
assert((iter->mode == NPY_NEIGHBORHOOD_ITER_ONE_PADDING)
| (iter->mode == NPY_NEIGHBORHOOD_ITER_ZERO_PADDING)
| (iter->mode == NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING));
@@ -214,6 +273,30 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter)
return 0;
}
+static NPY_INLINE
+int PyArrayNeighborhoodIter_NextMirror2D(PyArrayNeighborhoodIterObject* iter)
+{
+ assert(iter->mode == NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING);
+ assert(iter->nd == 2);
+
+ _PyArrayNeighborhoodIter_IncrCoord2D(iter);
+ _PyArrayNeighborhoodIter_SetPtrMirror2D(iter);
+
+ return 0;
+}
+
+static NPY_INLINE
+int PyArrayNeighborhoodIter_NextCircular2D(PyArrayNeighborhoodIterObject* iter)
+{
+ assert(iter->mode == NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING);
+ assert(iter->nd == 2);
+
+ _PyArrayNeighborhoodIter_IncrCoord2D(iter);
+ _PyArrayNeighborhoodIter_SetPtrCircular2D(iter);
+
+ return 0;
+}
+
static NPY_INLINE int
PyArrayNeighborhoodIter_NextConstant(PyArrayNeighborhoodIterObject* iter)
{