diff options
author | David Cournapeau <cournape@gmail.com> | 2009-08-07 13:20:58 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-08-07 13:20:58 +0000 |
commit | 5d180c4550ef3b348e9ee947bbe2f69fbd1ac5d4 (patch) | |
tree | 3499cd2f8054a4f571b732a6e88d6b49490ac204 /numpy | |
parent | 7055fdb3c0c0b6b6f8bceaaa03b044ac00685f06 (diff) | |
download | numpy-5d180c4550ef3b348e9ee947bbe2f69fbd1ac5d4.tar.gz |
Add unit tests for stacked neighborhood iterators.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/multiarray_tests.c.src | 38 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 68 |
2 files changed, 72 insertions, 34 deletions
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src index 6b0887f3d..54870bbc5 100644 --- a/numpy/core/src/multiarray/multiarray_tests.c.src +++ b/numpy/core/src/multiarray/multiarray_tests.c.src @@ -395,7 +395,7 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx, PyArrayNeighborhoodIter_Reset(itx); _MAX = 1e100; for(i = 0; i < itx->size; ++i) { - //for(i = 0; i < 1; ++i) { +#if 0 npy_intp yo[10]; yo[0] = i; printf("====================\n"); @@ -423,7 +423,7 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx, // yo[0] = -1; // printf("(%f) \n", *((double*)niterx->translate(niterx, yo))); -#if 0 +#endif for(j = 0; j < itx->ao->nd; ++j) { odims[j] = bounds[2 * j + 1] - bounds[2 * j] + 1; } @@ -435,41 +435,21 @@ copy_double_double(PyArrayNeighborhoodIterObject *itx, ptr = (double*)aout->data; PyArrayNeighborhoodIter_Reset(niterx); - printf("===================\n"); - T0 = getticks(); + //T0 = getticks(); for(j = 0; j < niterx->size; ++j) { - npy_intp yo[10]; - yo[0] = 0; - printf("-------------------\n"); - niterx->_internal_iter->translate(niterx->_internal_iter, yo); - //ptr = (double*)niterx->dataptr; - //printf("%ld | %ld -> %p (%f) \n", niterx->coordinates[0], - //niterx->_internal_iter->coordinates[0], - //niterx->_internal_iter->translate(niterx->_internal_iter, yo), - //*((double*)niterx->translate(niterx, yo))); - //printf("%f\n", *((double*)niterx->dataptr)); *ptr = *((double*)niterx->dataptr); - //*ptr = *((double*)neigh_iter_get_ptr_const(niterx)); - - // coord[0] = -2; - // ptr = niterx->_internal_iter->translate(niterx->_internal_iter, coord); - // printf("%f \n", *ptr); - - // neigh_iter_next_fptr(niterx); - PyArrayNeighborhoodIter_Next(niterx); - // neigh_iter_incr_coord(niterx); 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); -#endif PyArrayNeighborhoodIter_Next(itx); } // printf("%f - %f\n", _MAX, _MAX / niterx->size); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 15422d341..0f9d6629f 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1231,9 +1231,10 @@ class TestNeighborhoodIter(TestCase): from decimal import Decimal self._test_circular(Decimal) -class TestNeighborhoodIter2(TestCase): - # Simple, 2d tests - def test(self): +# Test stacking neighborhood iterators +class TestStackedNeighborhoodIter(TestCase): + # Simple, 1d test: stacking 2 constant-padded neigh iterators + def test_simple_const(self): dt = np.float64 # Test zero and one padding for simple data type x = np.array([1, 2, 3], dtype=dt) @@ -1244,8 +1245,65 @@ class TestNeighborhoodIter2(TestCase): np.array([3], dtype=dt), np.array([0], dtype=dt), np.array([0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-2, 2], [0]) - print l, r + l = test_neighborhood_iterator_oob(x, [-2, 4], NEIGH_MODE['zero'], + [0, 0], NEIGH_MODE['zero']) + assert_array_equal(l, r) + + r = [np.array([1, 0, 1], dtype=dt), + np.array([0, 1, 2], dtype=dt), + np.array([1, 2, 3], dtype=dt), + np.array([2, 3, 0], dtype=dt), + np.array([3, 0, 1], dtype=dt)] + l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], + [-1, 1], NEIGH_MODE['one']) + assert_array_equal(l, r) + + # 2nd simple, 1d test: stacking 2 neigh iterators, mixing const padding and + # mirror padding + def test_simple_mirror(self): + dt = np.float64 + # Stacking zero on top of mirror + x = np.array([1, 2, 3], dtype=dt) + r = [np.array([0, 1, 1], dtype=dt), + np.array([1, 1, 2], dtype=dt), + np.array([1, 2, 3], dtype=dt), + np.array([2, 3, 3], dtype=dt), + np.array([3, 3, 0], dtype=dt)] + l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['mirror'], + [-1, 1], NEIGH_MODE['zero']) + assert_array_equal(l, r) + + # Stacking mirror on top of zero + x = np.array([1, 2, 3], dtype=dt) + r = [np.array([1, 0, 0], dtype=dt), + np.array([0, 0, 1], dtype=dt), + np.array([0, 1, 2], dtype=dt), + np.array([1, 2, 3], dtype=dt), + np.array([2, 3, 0], dtype=dt)] + l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], + [-2, 0], NEIGH_MODE['mirror']) + assert_array_equal(l, r) + + # Stacking mirror on top of zero: 2nd + x = np.array([1, 2, 3], dtype=dt) + r = [np.array([0, 1, 2], dtype=dt), + np.array([1, 2, 3], dtype=dt), + np.array([2, 3, 0], dtype=dt), + np.array([3, 0, 0], dtype=dt), + np.array([0, 0, 3], dtype=dt)] + l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], + [0, 2], NEIGH_MODE['mirror']) + assert_array_equal(l, r) + + # Stacking mirror on top of zero: 3rd + x = np.array([1, 2, 3], dtype=dt) + r = [np.array([1, 0, 0, 1, 2], dtype=dt), + np.array([0, 0, 1, 2, 3], dtype=dt), + np.array([0, 1, 2, 3, 0], dtype=dt), + np.array([1, 2, 3, 0, 0], dtype=dt), + np.array([2, 3, 0, 0, 3], dtype=dt)] + l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], + [-2, 2], NEIGH_MODE['mirror']) assert_array_equal(l, r) if __name__ == "__main__": |