-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Refines NDArray indexing and adds numpy ndarray indexing [READY FOR REVIEW] #15942
Conversation
@@ -2508,6 +2619,88 @@ def copy(self): | |||
""" | |||
return self.copyto(self.context) | |||
|
|||
def slice_assign_scalar(self, value, begin, end, step): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a wrapper on top of _internal._slice_assign_scalar
is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enable polymorphism and reuse code as much as possible. I reused NDArray's _set_nd_basic_indexing
function in ndarray class and wrapping slice_assign_scalar
and slice_assign
as class methods can let python automatically call NDArray operators in NDArray processing, and ndarray ones in ndarray processing. If you feel such handling confusing, I can also copy-paste the entire _set_nd_basic_indexing
function to multiarray.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for some other operators like _full
and scatter_set_nd
.
""" | ||
return _internal._slice_assign_scalar(self, value, begin=begin, end=end, step=step, out=self) | ||
|
||
def slice_assign(self, rhs, begin, end, step): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -2678,20 +2871,32 @@ def to_dlpack_for_write(self): | |||
""" | |||
return to_dlpack_for_write(self) | |||
|
|||
def _full(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
""" | ||
return _internal._full(self.shape, value=value, ctx=self.context, dtype=self.dtype, out=self) | ||
|
||
def _scatter_set_nd(self, value_nd, indices): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
1973c3a
to
e50c351
Compare
7f71f00
to
e17a563
Compare
Waiting for CI result. Still fixing style. |
2ab9211
to
40459bd
Compare
Fixed SliceAxisGrad_ and now supports subscription on zero-size shapes (eg. x = np.ones((3, 0))) |
5f29819
to
9ff4d57
Compare
9ff4d57
to
2052fb7
Compare
Description
https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments