-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-257] Do not copy when casting as same type #10347
Conversation
Numpy always copies. We should stay consistent with numpy
|
2530a39
to
d7687bd
Compare
@piiswrong should then we introduce a flag copy=True to follow the numpy API? |
4391889
to
6de3033
Compare
8e33814
to
1a7c619
Compare
Sure we can add copy flag |
copy : bool | ||
Default `True`. By default, astype always returns a newly | ||
allocated ndarray on the same context. If this is set to | ||
False, and the dtype requirement is satisfied, |
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.
It's unclear what the dtype requirement
here is from the doc. Please fix.
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.
I agree. However I used the exact same wording as the numpy docs: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.ndarray.astype.html
copy : bool, optional: By default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.
I suggest switching to:
If this is set to False, and the dtype requested is the same as the array's dtype,
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.
Looks good
* do not copy on same type when casting * update to have a copy flag * adding sparse array
* do not copy on same type when casting * update to have a copy flag * adding sparse array
* do not copy on same type when casting * update to have a copy flag * adding sparse array
* do not copy on same type when casting * update to have a copy flag * adding sparse array
MXNET-257
Description
Currently there is a copy even when the data has already the correct type when calling 'astype'.
I am not sure why, so if it's on purpose please enlighten me 😄
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Comments