Don't return ndarray with empty shape through named indexers.
NumPy arrays with an empty shape cannot be assigned via the usual syntax. Fixes: #238. Related: #237. PiperOrigin-RevId: 441265437 Change-Id: Ib0de22c83f9babe9a97682dc5a32660c198ad68c
This commit is contained in:
@@ -102,6 +102,11 @@ py::array_t<T> MakeArray(T* base_ptr, int index, std::vector<int>&& shape,
|
||||
offset = m.tuple_adr[index];
|
||||
shape.insert(shape.begin(), m.tuple_size[index]);
|
||||
} else {
|
||||
// Do not return a NumPy array with shape () since these aren't very nice
|
||||
// to work with. Instead, always return singleton arrays with shape (1,).
|
||||
if (shape.empty()) {
|
||||
shape.push_back(1);
|
||||
}
|
||||
int size = 1;
|
||||
for (int s : shape) {
|
||||
size *= s;
|
||||
|
||||
Reference in New Issue
Block a user