summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/include/numpy/_neighborhood_iterator_imp.h382
-rw-r--r--numpy/core/include/numpy/ndarrayobject.h23
-rw-r--r--numpy/core/src/multiarray/iterators.c11
-rw-r--r--numpy/core/src/multiarray/multiarray_tests.c.src238
4 files changed, 24 insertions, 630 deletions
diff --git a/numpy/core/include/numpy/_neighborhood_iterator_imp.h b/numpy/core/include/numpy/_neighborhood_iterator_imp.h
index 9eeb71eda..5a73784c1 100644
--- a/numpy/core/include/numpy/_neighborhood_iterator_imp.h
+++ b/numpy/core/include/numpy/_neighborhood_iterator_imp.h
@@ -6,19 +6,7 @@
*/
static NPY_INLINE int
_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-_PyArrayNeighborhoodIter_SetPtrConstant(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-_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
*
@@ -46,7 +34,8 @@ _PyArrayNeighborhoodIter_SetPtrCircular2D(PyArrayNeighborhoodIterObject* iter);
iter->coordinates[c] = iter->bounds[c][0]; \
}
-static NPY_INLINE int _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter)
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter)
{
int i, wb;
@@ -60,7 +49,8 @@ static NPY_INLINE int _PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIter
/*
* Version optimized for 2d arrays, manual loop unrolling
*/
-static NPY_INLINE int _PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter)
+static NPY_INLINE int
+_PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter)
{
int wb;
@@ -71,310 +61,14 @@ static NPY_INLINE int _PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIt
}
#undef _UPDATE_COORD_ITER
-#define _INF_SET_PTR(c) \
- bd = iter->coordinates[c] + iter->_internal_iter->coordinates[c]; \
- if (bd < 0 || bd >= iter->dimensions[c]) { \
- iter->dataptr = iter->constant; \
- return 1; \
- } \
- offset = iter->coordinates[c] * iter->strides[c]; \
- iter->dataptr += offset;
-
-/* set the dataptr from its current coordinates */
-static NPY_INLINE int
-_PyArrayNeighborhoodIter_SetPtrConstant(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
- npy_intp offset, bd;
-
- iter->dataptr = iter->_internal_iter->dataptr;
-
- for(i = 0; i < iter->nd; ++i) {
- _INF_SET_PTR(i)
- }
-
- return 0;
-}
-
-static NPY_INLINE int
-_PyArrayNeighborhoodIter_SetPtrConstant2D(PyArrayNeighborhoodIterObject* iter)
-{
- npy_intp offset, bd;
-
- iter->dataptr = iter->_internal_iter->dataptr;
-
- _INF_SET_PTR(0)
- _INF_SET_PTR(1)
-
- 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)
-
-/* For an array x of dimension n, and given index i, returns j, 0 <= j < n
- * such as x[i] = x[j], with x assumed to be mirrored. For example, for x =
- * {1, 2, 3} (n = 3)
- *
- * index -5 -4 -3 -2 -1 0 1 2 3 4 5 6
- * value 2 3 3 2 1 1 2 3 3 2 1 1
- *
- * _npy_pos_index_mirror(4, 3) will return 1, because x[4] = x[1]*/
-static NPY_INLINE npy_intp _npy_pos_remainder(npy_intp i, npy_intp n)
-{
- npy_intp k, l, j;
-
- /* Mirror i such as it is guaranteed to be positive */
- if (i < 0) {
- i = - i - 1;
- }
-
- /* compute k and l such as i = k * n + l, 0 <= l < k */
- k = i / n;
- l = i - k * n;
-
- if (_NPY_IS_EVEN(k)) {
- j = l;
- } else {
- j = n - 1 - l;
- }
- return j;
-}
-#undef _NPY_IS_EVEN
-
-#define _INF_SET_PTR_MIRROR(c) \
- bd = iter->coordinates[c] + iter->_internal_iter->coordinates[c]; \
- truepos = _npy_pos_remainder(bd, iter->dimensions[c]); \
- offset = (truepos - iter->_internal_iter->coordinates[c]) * iter->strides[c]; \
- iter->dataptr += offset;
-
-/* set the dataptr from its current coordinates */
-static NPY_INLINE int
-_PyArrayNeighborhoodIter_SetPtrMirror(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
- npy_intp offset, bd, truepos;
-
- iter->dataptr = iter->_internal_iter->dataptr;
-
- for(i = 0; i < iter->nd; ++i) {
- _INF_SET_PTR_MIRROR(i)
- }
-
- 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| */
-static NPY_INLINE npy_intp _npy_euclidean_division(npy_intp i, npy_intp n)
-{
- npy_intp l;
-
- l = i % n;
- if (l < 0) {
- l += n;
- }
- return l;
-}
-#define _INF_SET_PTR_CIRCULAR(c) \
- bd = iter->coordinates[c] + iter->_internal_iter->coordinates[c]; \
- truepos = _npy_euclidean_division(bd, iter->dimensions[c]); \
- offset = (truepos - iter->_internal_iter->coordinates[c]) * iter->strides[c]; \
- iter->dataptr += offset;
-
-/* set the dataptr from its current coordinates */
-static NPY_INLINE int
-_PyArrayNeighborhoodIter_SetPtrCircular(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
- npy_intp offset, bd, truepos;
-
- iter->dataptr = iter->_internal_iter->dataptr;
-
- for(i = 0; i < iter->nd; ++i) {
- _INF_SET_PTR_CIRCULAR(i)
- }
-
- 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
-
/*
* Advance to the next neighbour
*/
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));
- assert(iter->nd == 2);
-
- _PyArrayNeighborhoodIter_IncrCoord2D(iter);
- _PyArrayNeighborhoodIter_SetPtrConstant2D(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)
-{
- assert((iter->mode == NPY_NEIGHBORHOOD_ITER_ONE_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_ZERO_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING));
-
- _PyArrayNeighborhoodIter_IncrCoord(iter);
- _PyArrayNeighborhoodIter_SetPtrConstant(iter);
-
- return 0;
-}
-
-static NPY_INLINE
-int PyArrayNeighborhoodIter_NextMirror(PyArrayNeighborhoodIterObject* iter)
-{
- assert(iter->mode == NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING);
-
- _PyArrayNeighborhoodIter_IncrCoord(iter);
- _PyArrayNeighborhoodIter_SetPtrMirror(iter);
-
- return 0;
-}
-
-static NPY_INLINE
-int PyArrayNeighborhoodIter_NextCircular(PyArrayNeighborhoodIterObject* iter)
-{
- assert(iter->mode == NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING);
-
- _PyArrayNeighborhoodIter_IncrCoord(iter);
- _PyArrayNeighborhoodIter_SetPtrCircular(iter);
-
- return 0;
-}
-
-#define _INF_SET_PTR(c) \
- bd = niter->coordinates[c] + p->coordinates[c]; \
- if (bd < p->bounds[c][0] || bd > p->bounds[c][1]) { \
- return niter->constant; \
- } \
- _coordinates[c] = bd;
-
-static inline char*
-_neigh_iter_get_ptr_const(PyArrayNeighborhoodIterObject* niter)
-{
- int i;
- npy_intp bd;
- PyArrayIterObject *p = niter->_internal_iter;
- npy_intp _coordinates[NPY_MAXDIMS];
-
- for(i = 0; i < niter->nd; ++i) {
- _INF_SET_PTR(i)
- }
-
- return p->translate(p, _coordinates);
-}
-#undef _INF_SET_PTR
-
-static NPY_INLINE int
PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter)
{
_PyArrayNeighborhoodIter_IncrCoord (iter);
- switch (iter->mode) {
- case NPY_NEIGHBORHOOD_ITER_ZERO_PADDING:
- case NPY_NEIGHBORHOOD_ITER_ONE_PADDING:
- case NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING:
- //iter->dataptr = _neigh_iter_get_ptr_const(iter);
- iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
- break;
- case NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING:
- //_PyArrayNeighborhoodIter_SetPtrMirror(iter);
- iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
- break;
- case NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING:
- //_PyArrayNeighborhoodIter_SetPtrCircular(iter);
- iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
- break;
- }
+ iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
return 0;
}
@@ -383,53 +77,6 @@ PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter)
* Reset functions
*/
static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetConstant(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
-
- assert((iter->mode == NPY_NEIGHBORHOOD_ITER_ONE_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_ZERO_PADDING)
- | (iter->mode == NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING));
-
- for (i = 0; i < iter->nd; ++i) {
- iter->coordinates[i] = iter->bounds[i][0];
- }
- _PyArrayNeighborhoodIter_SetPtrConstant(iter);
-
- return 0;
-}
-
-static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetMirror(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
-
- assert(iter->mode == NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING);
-
- for (i = 0; i < iter->nd; ++i) {
- iter->coordinates[i] = iter->bounds[i][0];
- }
- _PyArrayNeighborhoodIter_SetPtrMirror(iter);
-
- return 0;
-}
-
-static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetCircular(PyArrayNeighborhoodIterObject* iter)
-{
- int i;
-
- assert(iter->mode == NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING);
-
- for (i = 0; i < iter->nd; ++i) {
- iter->coordinates[i] = iter->bounds[i][0];
- }
- _PyArrayNeighborhoodIter_SetPtrCircular(iter);
-
- return 0;
-}
-
-static NPY_INLINE int
PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter)
{
int i;
@@ -439,24 +86,5 @@ PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter)
}
iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
-#if 0
- switch (iter->mode) {
- case NPY_NEIGHBORHOOD_ITER_ZERO_PADDING:
- case NPY_NEIGHBORHOOD_ITER_ONE_PADDING:
- case NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING:
- iter->dataptr = _neigh_iter_get_ptr_const(iter);
- break;
- case NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING:
- _PyArrayNeighborhoodIter_SetPtrMirror(iter);
- break;
- case NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING:
- _PyArrayNeighborhoodIter_SetPtrCircular(iter);
- break;
- default:
- printf("oups\n");
- exit(-1);
- }
-#endif
-
return 0;
}
diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h
index c3c5e7cb7..c91e79446 100644
--- a/numpy/core/include/numpy/ndarrayobject.h
+++ b/numpy/core/include/numpy/ndarrayobject.h
@@ -698,6 +698,7 @@ struct PyArrayIterObject_tag {
npy_bool contiguous;
npy_intp bounds[NPY_MAXDIMS][2];
+ npy_intp bounds_size[NPY_MAXDIMS];
npy_iter_get_dataptr_t translate;
} ;
@@ -949,6 +950,7 @@ typedef struct {
npy_bool contiguous;
npy_intp bounds[NPY_MAXDIMS][2];
+ npy_intp bounds_size[NPY_MAXDIMS];
npy_iter_get_dataptr_t translate;
/*
@@ -978,25 +980,8 @@ static NPY_INLINE int
PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter);
static NPY_INLINE int
PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
-
-/* Mode specific: those are faster, but have undefined behavior if the mode
- * does not match. Sanity checks are enabled in debug mode. */
-static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetConstant(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-PyArrayNeighborhoodIter_NextConstant(PyArrayNeighborhoodIterObject* iter);
-
-static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetMirror(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-PyArrayNeighborhoodIter_NextMirror(PyArrayNeighborhoodIterObject* iter);
-
-static NPY_INLINE int
-PyArrayNeighborhoodIter_ResetCircular(PyArrayNeighborhoodIterObject* iter);
-static NPY_INLINE int
-PyArrayNeighborhoodIter_NextCircular(PyArrayNeighborhoodIterObject* iter);
+// static NPY_INLINE int
+// PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
/* Include inline implementations - functions defined there are not considered
* public API */
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index a44c3f387..2c48c8657 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -315,6 +315,7 @@ array_iter_base_init(PyArrayIterObject *it, PyArrayObject *ao)
}
it->bounds[i][0] = 0;
it->bounds[i][1] = ao->dimensions[i] - 1;
+ it->bounds_size[i] = ao->dimensions[i];
}
it->translate = &get_ptr_simple;
@@ -1854,7 +1855,7 @@ __npy_pos_remainder(npy_intp i, npy_intp n)
#define _INF_SET_PTR_MIRROR(c) \
lb = p->bounds[c][0]; \
bd = coordinates[c] + p->coordinates[c] - lb; \
- _coordinates[c] = lb + __npy_pos_remainder(bd, p->bounds[c][1] + 1 - lb);
+ _coordinates[c] = lb + __npy_pos_remainder(bd, p->bounds_size[c]);
/* set the dataptr from its current coordinates */
static char*
@@ -1889,13 +1890,12 @@ __npy_euclidean_division(npy_intp i, npy_intp n)
#define _INF_SET_PTR_CIRCULAR(c) \
lb = p->bounds[c][0]; \
bd = coordinates[c] + p->coordinates[c] - lb; \
- _coordinates[c] = lb + _npy_euclidean_division(bd, p->bounds[c][1] + 1 - lb);
+ _coordinates[c] = lb + __npy_euclidean_division(bd, p->bounds_size[c]);
static char*
get_ptr_circular(PyArrayIterObject* _iter, npy_intp *coordinates)
{
int i;
- //npy_intp offset, bd, truepos;
npy_intp bd, _coordinates[NPY_MAXDIMS], lb;
PyArrayNeighborhoodIterObject *niter = (PyArrayNeighborhoodIterObject*)_iter;
PyArrayIterObject *p = niter->_internal_iter;
@@ -1903,9 +1903,9 @@ get_ptr_circular(PyArrayIterObject* _iter, npy_intp *coordinates)
for(i = 0; i < niter->nd; ++i) {
_INF_SET_PTR_CIRCULAR(i)
}
-
return p->translate(p, _coordinates);
}
+
#undef _INF_SET_PTR_CIRCULAR
/*
@@ -1936,7 +1936,8 @@ PyArray_NeighborhoodIterNew(PyArrayIterObject *x, intp *bounds,
for (i = 0; i < ret->nd; ++i) {
ret->bounds[i][0] = bounds[2 * i];
ret->bounds[i][1] = bounds[2 * i + 1];
- ret->size *= (bounds[2*i+1] - bounds[2*i]) + 1;
+ ret->bounds_size[i] = (bounds[2*i+1] - bounds[2*i]) + 1;
+ ret->size *= ret->bounds_size[i];
}
for (i = 0; i < ret->nd; ++i) {
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src
index 54870bbc5..28f3f1b86 100644
--- a/numpy/core/src/multiarray/multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/multiarray_tests.c.src
@@ -26,19 +26,6 @@ static int copy_@type@(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
npy_intp coord[10];
PyArrayNeighborhoodIter_Reset(niterx);
-#if 0
- printf("+++++++++++++++++++++++++++++++\n");
- coord[0] = -2;
- printf("%f\n", *((double*)niterx->translate(niterx, coord)));
- coord[0] = -1;
- printf("%f\n", *((double*)niterx->translate(niterx, coord)));
- coord[0] = 0;
- printf("%f\n", *((double*)niterx->translate(niterx, coord)));
- coord[0] = 1;
- printf("%f\n", *((double*)niterx->translate(niterx, coord)));
- coord[0] = 2;
- printf("%f\n", *((double*)niterx->translate(niterx, coord)));
-#endif
for(j = 0; j < itx->ao->nd; ++j) {
odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1;
}
@@ -213,171 +200,12 @@ clean_ax:
return NULL;
}
-/*
- * Update to next item of the iterator
- *
- * Note: this simply increment the coordinates vector, last dimension
- * incremented first , i.e, for dimension 3
- * ...
- * -1, -1, -1
- * -1, -1, 0
- * -1, -1, 1
- * ....
- * -1, 0, -1
- * -1, 0, 0
- * ....
- * 0, -1, -1
- * 0, -1, 0
- * ....
- */
-#define _UPDATE_COORD_ITER(c) \
- wb = iter->coordinates[c] < iter->bounds[c][1]; \
- if (wb) { \
- iter->coordinates[c] += 1; \
- return 0; \
- } \
- else { \
- iter->coordinates[c] = iter->bounds[c][0]; \
- }
-
-static inline int
-neigh_iter_incr_coord(PyArrayNeighborhoodIterObject* iter)
-{
- int i, wb;
-
- for (i = iter->nd - 1; i >= 0; --i) {
- _UPDATE_COORD_ITER(i)
- }
-
- return 0;
-}
-#undef _UPDATE_COORD_ITER
-
-#if 0
-#define _INF_SET_PTR(c) \
- bd = niter->coordinates[c] + niter->_internal_iter->coordinates[c]; \
- printf("%d|%d - %d|%d,\n", niter->coordinates[c], \
- niter->_internal_iter->coordinates[c], \
- niter->_internal_iter->bounds[c][0], \
- niter->_internal_iter->bounds[c][1]); \
- if (bd < niter->_internal_iter->bounds[c][0] || \
- bd > niter->_internal_iter->bounds[c][1]) { \
- printf("OOB\n"); \
- return niter->constant; \
- } \
- coordinates[c] = bd; \
- printf("coord is %d\n", coordinates[c]);
-#endif
-
-#define _INF_SET_PTR(c) \
- bd = niter->coordinates[c] + p->coordinates[c]; \
- if (bd < p->bounds[c][0] || \
- bd > p->bounds[c][1]) { \
- return niter->constant; \
- } \
- _coordinates[c] = bd;
-
-static inline char*
-neigh_iter_get_ptr_const(PyArrayNeighborhoodIterObject* niter)
-{
- int i;
- npy_intp offset, bd;
- char *ret;
- PyArrayIterObject *p = niter->_internal_iter;
- npy_intp _coordinates[2*NPY_MAXDIMS];
-
- for(i = 0; i < niter->nd; ++i) {
- _INF_SET_PTR(i)
- }
-
- return niter->_internal_iter->translate(niter->_internal_iter, _coordinates);
-}
-
-static inline int
-neigh_iter_next_fptr(PyArrayNeighborhoodIterObject *iter)
-{
- neigh_iter_incr_coord(iter);
- iter->dataptr = neigh_iter_get_ptr_const(iter);
- return 0;
-}
-
-static inline int
-neigh_iter_reset(PyArrayNeighborhoodIterObject *iter)
-{
- npy_intp i;
-
- for(i = 0; i < iter->nd; ++i) {
- iter->coordinates[i] = iter->bounds[i][0];
- }
- iter->dataptr = neigh_iter_get_ptr_const(iter);
- return 0;
-}
-
-//#include "cycle.h"
+#include "cycle.h"
-//ticks T0, T1;
+ticks T0, T1;
double RES;
double _MAX;
-#define _NPY_IS_EVEN(x) ((x) % 2 == 0)
-
-/* For an array x of dimension n, and given index i, returns j, 0 <= j < n
- * such as x[i] = x[j], with x assumed to be mirrored. For example, for x =
- * {1, 2, 3} (n = 3)
- *
- * index -5 -4 -3 -2 -1 0 1 2 3 4 5 6
- * value 2 3 3 2 1 1 2 3 3 2 1 1
- *
- * _npy_pos_index_mirror(4, 3) will return 1, because x[4] = x[1]*/
-static inline npy_intp
-__npy_pos_remainder(npy_intp i, npy_intp n)
-{
- npy_intp k, l, j;
-
- /* Mirror i such as it is guaranteed to be positive */
- if (i < 0) {
- i = - i - 1;
- }
-
- /* compute k and l such as i = k * n + l, 0 <= l < k */
- k = i / n;
- l = i - k * n;
-
- if (_NPY_IS_EVEN(k)) {
- j = l;
- } else {
- j = n - 1 - l;
- }
- return j;
-}
-#undef _NPY_IS_EVEN
-
-#define _INF_SET_PTR_MIRROR(c) \
- bd = coordinates[c] + p->coordinates[c]; \
- bd -= p->bounds[c][0]; \
- truepos = __npy_pos_remainder(bd, niter->dimensions[c] - p->bounds[c][0]); \
- _coordinates[c] = (truepos - p->coordinates[c] + p->bounds[c][0]);
-
-/* set the dataptr from its current coordinates */
-static char*
-get_ptr_mirror(PyArrayIterObject* _iter, npy_intp *coordinates)
-{
- int i;
- npy_intp bd, _coordinates[NPY_MAXDIMS];
- npy_intp truepos;
- PyArrayNeighborhoodIterObject *niter = (PyArrayNeighborhoodIterObject*)_iter;
- PyArrayIterObject *p = niter->_internal_iter;
-
- printf("%s\n", __func__);
- for(i = 0; i < niter->nd; ++i) {
- _INF_SET_PTR_MIRROR(i)
- }
-
- printf("%s:%s: coordinates is %ld, ptr is %f\n", __FILE__, __func__, _coordinates[0], *((double*)p->translate(p, _coordinates)));
- return p->translate(p, _coordinates);
-}
-#undef _INF_SET_PTR_MIRROR
-
static int
copy_double_double(PyArrayNeighborhoodIterObject *itx,
PyArrayNeighborhoodIterObject *niterx,
@@ -391,39 +219,9 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx,
/* For each point in itx, copy the current neighborhood into an array which
* is appended at the output list */
- // itx->translate = &get_ptr_mirror;
PyArrayNeighborhoodIter_Reset(itx);
_MAX = 1e100;
for(i = 0; i < itx->size; ++i) {
-#if 0
- npy_intp yo[10];
- yo[0] = i;
- printf("====================\n");
- printf("(%f) \n", *((double*)itx->translate(itx, yo)));
- // printf("(%f) \n", *((double*)itx->dataptr));
-
- PyArrayNeighborhoodIter_Reset(niterx);
- printf("------ begin --------------\n");
- //T0 = getticks();
- for(j = 0; j < niterx->size; ++j) {
- printf("(%f) \n", *((double*)niterx->translate(niterx, niterx->coordinates)));
- // printf("(%f) \n", *((double*)niterx->dataptr));
- PyArrayNeighborhoodIter_Next(niterx);
- }
- printf("------ end -------------\n");
-
- // yo[0] = 1;
- // printf("(%f) \n", *((double*)itx->translate(itx, yo)));
- // yo[0] = 2;
- // printf("(%f) \n", *((double*)itx->translate(itx, yo)));
- // yo[0] = 3;
- // printf("(%f) \n", *((double*)itx->translate(itx, yo)));
- // yo[0] = 4;
- // printf("(%f) \n", *((double*)itx->translate(itx, yo)));
-
- // yo[0] = -1;
- // printf("(%f) \n", *((double*)niterx->translate(niterx, yo)));
-#endif
for(j = 0; j < itx->ao->nd; ++j) {
odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1;
}
@@ -435,42 +233,24 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx,
ptr = (double*)aout->data;
PyArrayNeighborhoodIter_Reset(niterx);
- //T0 = getticks();
+ T0 = getticks();
for(j = 0; j < niterx->size; ++j) {
*ptr = *((double*)niterx->dataptr);
ptr += 1;
PyArrayNeighborhoodIter_Next(niterx);
}
- //T1 = getticks();
- //RES = elapsed(T1, T0);
- //if (RES < _MAX) {
- // _MAX = RES;
- //}
+ T1 = getticks();
+ RES = elapsed(T1, T0);
+ if (RES < _MAX) {
+ _MAX = RES;
+ }
Py_INCREF(aout);
PyList_Append(*out, (PyObject*)aout);
Py_DECREF(aout);
PyArrayNeighborhoodIter_Next(itx);
}
- // printf("%f - %f\n", _MAX, _MAX / niterx->size);
-
-#if 0
- {
- npy_intp coord[10];
- coord[0] = 0;
- coord[1] = 0;
- *ptr = *((double*)niterx->translate(niterx, coord));
- printf("%f\n", *ptr);
- coord[0] = 1;
- coord[1] = 0;
- *ptr = *((double*)niterx->translate(niterx, coord));
- printf("%f\n", *ptr);
- coord[0] = 2;
- coord[1] = 0;
- *ptr = *((double*)niterx->translate(niterx, coord));
- printf("%f\n", *ptr);
- }
-#endif
+ printf("%f - %f\n", _MAX, _MAX / niterx->size);
return 0;
}