Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cae71f6

Browse files
committed
Make array_view.size return 0 for empty arrays
1 parent aa38c5b commit cae71f6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/numpy_cpp.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,17 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
539539

540540
size_t size() const
541541
{
542-
return (size_t)dim(0);
542+
bool empty = (ND == 0);
543+
for (size_t i = 0; i < ND; i++) {
544+
if (m_shape[i] == 0) {
545+
empty = true;
546+
}
547+
}
548+
if (empty) {
549+
return 0;
550+
} else {
551+
return (size_t)dim(0);
552+
}
543553
}
544554

545555
bool empty() const

0 commit comments

Comments
 (0)