Skip to content

Commit 40a058c

Browse files
authored
Merge pull request #73 from pocketpy/fix-set_item
Fix set item for N-d vector assignment
2 parents b80cc71 + b37d8b5 commit 40a058c

File tree

2 files changed

+374
-18
lines changed

2 files changed

+374
-18
lines changed

numpy/include/numpy.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ class ndarray {
295295

296296
void set_item(int index, const ndarray<T>& value) { xt::view(_array, index, xt::all()) = value.get_array(); }
297297

298+
void set_item(int i1, int i2, const ndarray<T>& value) { xt::view(_array, i1, i2, xt::all()) = value.get_array(); }
299+
300+
void set_item(int i1, int i2, int i3, const ndarray<T>& value) { xt::view(_array, i1, i2, i3, xt::all()) = value.get_array(); }
301+
302+
void set_item(int i1, int i2, int i3, int i4, const ndarray<T>& value) { xt::view(_array, i1, i2, i3, i4, xt::all()) = value.get_array(); }
303+
304+
void set_item(int i1, int i2, int i3, int i4, int i5, const ndarray<T>& value) { xt::view(_array, i1, i2, i3, i4, i5, xt::all()) = value.get_array(); }
305+
298306
void set_item(const std::vector<int>& indices, const ndarray<T>& value) {
299307
xt::view(_array, xt::keep(indices)) = value.get_array();
300308
}
@@ -303,13 +311,13 @@ class ndarray {
303311
xt::view(_array, xt::range(std::get<0>(slice), std::get<1>(slice), std::get<2>(slice))) = value.get_array();
304312
}
305313

306-
void set_item_2d(int i1, int i2, T value) { xt::view(_array, i1, i2) = value; }
314+
void set_item(int i1, int i2, T value) { xt::view(_array, i1, i2) = value; }
307315

308-
void set_item_3d(int i1, int i2, int i3, T value) { xt::view(_array, i1, i2, i3) = value; }
316+
void set_item(int i1, int i2, int i3, T value) { xt::view(_array, i1, i2, i3) = value; }
309317

310-
void set_item_4d(int i1, int i2, int i3, int i4, T value) { xt::view(_array, i1, i2, i3, i4) = value; }
318+
void set_item(int i1, int i2, int i3, int i4, T value) { xt::view(_array, i1, i2, i3, i4) = value; }
311319

312-
void set_item_5d(int i1, int i2, int i3, int i4, int i5, T value) { xt::view(_array, i1, i2, i3, i4, i5) = value; }
320+
void set_item(int i1, int i2, int i3, int i4, int i5, T value) { xt::view(_array, i1, i2, i3, i4, i5) = value; }
313321

314322
// Boolean Functions
315323
bool all() const { return xt::all(_array); }

0 commit comments

Comments
 (0)