diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2017-08-30 10:59:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-30 10:59:10 -0500 |
| commit | 912a05b194816ec5c4b9ab775fefefa1388434b0 (patch) | |
| tree | 1705da57a5d107d944d0dc158b4bf502419ee502 /numpy | |
| parent | fe27b296aff1f0cd508927e70afedf662ca9708f (diff) | |
| parent | 53d322d83a53a2c93673336275fca2558e1c96e4 (diff) | |
| download | numpy-912a05b194816ec5c4b9ab775fefefa1388434b0.tar.gz | |
Merge pull request #9619 from nschloe/f2py-dimension-0
f2py: allow Fortran arrays of dimension 0
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/f2py/src/fortranobject.c | 8 | ||||
| -rw-r--r-- | numpy/f2py/tests/test_size.py | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index f2036c427..96b08ea18 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -595,11 +595,11 @@ static int check_and_fix_dimensions(const PyArrayObject* arr, npy_intp *dims); static int -count_nonpos(const int rank, - const npy_intp *dims) { +count_negative_dimensions(const int rank, + const npy_intp *dims) { int i=0,r=0; while (i<rank) { - if (dims[i] <= 0) ++r; + if (dims[i] < 0) ++r; ++i; } return r; @@ -678,7 +678,7 @@ PyArrayObject* array_from_pyobj(const int type_num, || ((intent & F2PY_OPTIONAL) && (obj==Py_None)) ) { /* intent(cache), optional, intent(hide) */ - if (count_nonpos(rank,dims)) { + if (count_negative_dimensions(rank,dims) > 0) { int i; strcpy(mess, "failed to create intent(cache|hide)|optional array" "-- must have defined dimensions but got ("); diff --git a/numpy/f2py/tests/test_size.py b/numpy/f2py/tests/test_size.py index ebf4acda5..1fcad05a5 100644 --- a/numpy/f2py/tests/test_size.py +++ b/numpy/f2py/tests/test_size.py @@ -15,6 +15,9 @@ class TestSizeSumExample(util.F2PyTest): @dec.slow def test_all(self): + r = self.module.foo([[]]) + assert_equal(r, [0], repr(r)) + r = self.module.foo([[1, 2]]) assert_equal(r, [3], repr(r)) @@ -26,6 +29,9 @@ class TestSizeSumExample(util.F2PyTest): @dec.slow def test_transpose(self): + r = self.module.trans([[]]) + assert_equal(r.T, [[]], repr(r)) + r = self.module.trans([[1, 2]]) assert_equal(r, [[1], [2]], repr(r)) @@ -34,6 +40,9 @@ class TestSizeSumExample(util.F2PyTest): @dec.slow def test_flatten(self): + r = self.module.flatten([[]]) + assert_equal(r, [], repr(r)) + r = self.module.flatten([[1, 2]]) assert_equal(r, [1, 2], repr(r)) |
