Skip to content

Commit 086add1

Browse files
committed
Don't enforce trailing shape on empty arrays
They need only be the same number of dimensions, as sometimes code does `np.atleast_3d(array)` on something empty, which inserts the 0-dimension in a spot that messes with the expected trailing shape.
1 parent 45ab00e commit 086add1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/mplutils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ inline bool check_trailing_shape(T array, char const* name, long d1)
7777
array.ndim());
7878
return false;
7979
}
80+
if (array.size() == 0) {
81+
// Sometimes things come through as atleast_2d, etc., but they're empty, so
82+
// don't bother enforcing the trailing shape.
83+
return true;
84+
}
8085
if (array.shape(1) != d1) {
8186
PyErr_Format(PyExc_ValueError,
8287
"%s must have shape (N, %ld), got (%ld, %ld)",
@@ -95,6 +100,11 @@ inline bool check_trailing_shape(T array, char const* name, long d1, long d2)
95100
array.ndim());
96101
return false;
97102
}
103+
if (array.size() == 0) {
104+
// Sometimes things come through as atleast_3d, etc., but they're empty, so
105+
// don't bother enforcing the trailing shape.
106+
return true;
107+
}
98108
if (array.shape(1) != d1 || array.shape(2) != d2) {
99109
PyErr_Format(PyExc_ValueError,
100110
"%s must have shape (N, %ld, %ld), got (%ld, %ld, %ld)",

0 commit comments

Comments
 (0)