Allow squeeze to use negative index#1430
Conversation
Body: BUG * squeeze() can now take negative index where -1 refers to the index (length - 1) thus extending the range of axis parameter from [0, length) to [-length, length) making it consistent with the python version of tensorflow. * Added tests for the same in util_tests and tensor_tests
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
squeeze() will now throw an exception if the index of axis that needs to be squeezed goes out of bound
Seeking Clarification on following issue:
Tests Ran:
|
caisq
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 1 approvals obtained (waiting on @VisibleMarkov)
src/tensor_test.ts, line 1361 at r2 (raw file):
[-1]
Can you also test squeeze([-2, -1])?
src/util.ts, line 282 at r2 (raw file):
`Can't squeeze axis ${axis[i]} since its not in [-${shape.length}, ${shape.length}) for shape ${shape}`); // tslint:disable-line
You can break this into two lines by using the string + operator and remove the tslint disable comment.
caisq
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 1 approvals obtained (waiting on @VisibleMarkov)
|
Thanks for the green flag (^_^) |
|
@VisibleMarkov PR is merged. Thank you for your contribution! |
Issue in focus: tensorflow/tfjs#940
Description
squeeze()didn't support the use of negative index which is supported in tensorflow for Python. Added tests for the same inutil_testandtensor_test.The previous implementation didn't allow for random arrangement of values of axis. For example if axes is set to
[2, 3], it would remove them both but if you pass it as[3, 2]it would only remove 3 and ignore 2 entirely. I tried the same with tensorflow for python in this Google Colab Notebook and this too was inconsistent with tfjs as tensorflow python allows for removal of axis irrespective of order of input if it's allowed. This inconsistency was removed when adding the support for negative index ( it was totally unintentional but resulted from my implementation to allow negative index ).Clarification required for following topics:
[-1, -2]was intuitively much better for a programmer but if we just replaced it with the positive index of same, it would have been[5, 4]which due to it's lack of ascending order would have ignored 4 completely. If this needs to changed, please let me know and I'll come up with another implementation to change this behavior.Tests Ran:
BUG
For repository owners only:
Please remember to apply all applicable tags to your pull request.
Tags: BUG
For more info see: https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md
This change is