You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to motivate the case for method chaining for the "underscore" operations.
I noticed there are a whole set of operations that end with underscore. I think I have seen this in PyTorch, where convention means the object instance will get modified (a mutating func in swift term).
Consider this:
where v1, v2, and v3 are very large. It took 41.405 ms for 1st and 16.365 ms the 2nd. The diff is due to .new(...) being called twice. So depending on the computational context where you don't care about original v1 getting clobbered. You prefer the 2nd way. I found this is often the case if you need to customize or during post-processing of neural network (intermediate input/output) in Apple CoreML. This motivates writing this:
v1.sub_(v2).sub_(v3)
in one single line and sub_ should return self to allow this method chaining. Please let me know what you think, and if this makes sense. I will try this out locally, but just want to hear if you know any bad surprise.
The text was updated successfully, but these errors were encountered:
kechan
changed the title
Enhancement suggestion: chaining for add_, sub_, etc.
Enhancement suggestion: method chaining for add_, sub_, etc.
Jan 22, 2019
Trying to motivate the case for method chaining for the "underscore" operations.
I noticed there are a whole set of operations that end with underscore. I think I have seen this in PyTorch, where convention means the object instance will get modified (a mutating func in swift term).
Consider this:
where v1, v2, and v3 are very large. It took 41.405 ms for 1st and 16.365 ms the 2nd. The diff is due to .new(...) being called twice. So depending on the computational context where you don't care about original v1 getting clobbered. You prefer the 2nd way. I found this is often the case if you need to customize or during post-processing of neural network (intermediate input/output) in Apple CoreML. This motivates writing this:
in one single line and sub_ should return self to allow this method chaining. Please let me know what you think, and if this makes sense. I will try this out locally, but just want to hear if you know any bad surprise.
The text was updated successfully, but these errors were encountered: