-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[fix issue#9976] The assignment problem in NDArray #9981
[fix issue#9976] The assignment problem in NDArray #9981
Conversation
Hello, could you please add a test for this case? |
@marcoabreu Yes, I will add it soon :) |
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.
The last three test cases are not affected by the bug. But there is nothing wrong to add them here.
# assign directly | ||
a_np[0] = a_np[1] | ||
a_nd[0] = a_nd[1] | ||
assert np.allclose(a_np, a_nd.asnumpy()) |
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.
Use assert same(a_np, a_nd.asnumpy())
. Same for all others.
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.
Thank you! I will modify it.
a_np[0] = a_np[1] | ||
a_nd[0] = a_nd[1] | ||
assert np.allclose(a_np, a_nd.asnumpy()) | ||
assert id(a_nd) == a_nd_id |
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.
What's the purpose of this check? This seems always true.
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.
My mistake. I want to check the memory address of NDArray didn't change.
And assert np.allclose(a_np, a_nd.asnumpy())
means checking issue #9976.
@@ -1099,6 +1099,39 @@ def test_assign_float_value_to_ndarray(): | |||
b[0] = a[0] | |||
assert same(a, b.asnumpy()) | |||
|
|||
@with_seed() | |||
def test_ndarray_assignment(): |
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.
- Add issue link as code comment.
- Change the function name to a special one since this is only for testing special cases. General cases have been covered by
test_ndarray_indexing
.
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.
Okay. Thanks!
@@ -1128,7 +1128,7 @@ void CopyFromToImpl(const NDArray& from, const NDArray& to, | |||
} | |||
|
|||
void CopyFromTo(const NDArray& from, const NDArray& to, int priority) { | |||
if (from.var() == to.var()) { | |||
if (from.var() == to.var() && from.byte_offset() == to.byte_offset()) { |
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.
should we also check for size? @reminisce
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.
@piiswrong There is a shape equality check after this. For CopyFromTo
, I think the added condition is sufficient. Agree we should also check sizes if it is for a function of checking if two ndarrays are the same one.
@marcoabreu retrigger test? |
@piiswrong Thank you! I will change the code and then trigger test. |
…to fix_the_assignnment_problem_in_NDArray
…x the dtype in the test
@piiswrong you can always retrigger a test by logging in at http://jenkins.mxnet-ci.amazon-ml.com/ (committers only) |
* fix the assignment problem in NDArray * add ndarray assignment test * fix test_ndarray_assignment() * fix comparison precision for test_ndarray_assignment * rename test_ndarray_assignment to test_assign_a_row_to_ndarray and fix the dtype in the test
* fix the assignment problem in NDArray * add ndarray assignment test * fix test_ndarray_assignment() * fix comparison precision for test_ndarray_assignment * rename test_ndarray_assignment to test_assign_a_row_to_ndarray and fix the dtype in the test
* fix the assignment problem in NDArray * add ndarray assignment test * fix test_ndarray_assignment() * fix comparison precision for test_ndarray_assignment * rename test_ndarray_assignment to test_assign_a_row_to_ndarray and fix the dtype in the test
Description
Fix #9976 (#9976)
Checklist
Essentials
make lint
)Changes
byte_offset()
function for NDArrayComments
byte_offset()
function for NDArray?is_itself()
function for NDArray?