-
Notifications
You must be signed in to change notification settings - Fork 962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed narrow to standardize negative length and negative offset beh… #1113
Conversation
…avior, modified documentation to reflect new behavior
I did not find any discussion as to why this change has been made, and it breaks backwards compatibility. So may I ask what the rationale behind this change is? |
Hi @sniklaus: Two separate things I changed:
I think selecting the last element with -1 makes intuitive sense to me. These two changes I made at the same time, but it is change 2 that produces the off by 1 error in backward compatibility. |
I think it is a bad idea to be silently breaking APIs without notice or a deprecation warning. It is not documented, and will cause silent failures. |
This is nevertheless breaking backwards compatibility. Existing code expects a different behavior when supplying a negative length.
I would not be surprised to see an issue report about this soon. I remember we had a discussion about the semantics of the negative length before, which I unfortunately cannot find anymore. It should however further be discussed as the semantics of the third parameter seem controversial. #917 |
The previous semantics were by the way neat when it comes to cropping an image. Want to crop 1 pixel left and right / top and bottom? |
First of all, i'm really sorry about merging this without a depreceated tag etc. negative offsets were introduced on December 12th, 2016: https://github.com/torch/nn/commits/master/Narrow.lua , the commit was from @huihuifan that i ported back into OSS. As soon as they were introduced, we wanted to make the changes in the current PR, and if we merged the changes within ~2 weeks ish, i thought the whole thing would've been acceptable. But pushing the diff through had delays, and more than a month later i merged this in. Looking back, not the best of judgements. We will figure out a way to keep backward compatibility (or) mark deprecation properly before pushing it through. |
Thank you for quick response @soumith! My response was mainly due to the change in semantics of the length parameter. The support for negative lengths was added on May 15 of last year. |
I'd consider the previous behavior (from May 2016) broken since you can't mix negative indices and negative length, and a negative I think one way to solve this would be to use |
@jgehring it's too much of an expectation that all users downstream will change their code referencing I dont see a good solution to this but here are a couple of not-so-good solutions:
|
There should also be a consideration for proper deprecation system and including breaking changes in a unified way rather than handling it individually for each module. I am not sure how feasible this is, but would it be possible to do something like this ?
If there were other modules considering breaking changes, they can just look at the list In the future, if a module is being deprecated for a new behavior, you can start displaying notices saying this will change on a xyz date. Once the date is passed, the new behavior is the default and the old behavior can be enabled through a new list, say This is a rather crude alternative to the lack of version numbers being used. If there's a proper way to include version numbers along side |
If solving just This way you can get both behaviors without adding additional parameters. |
…avior,
modified documentation to reflect new behavior