question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sub, rsub and isub

See original GitHub issue

I’d propose a behavior change of the __sub__ operator to align with how the other operators work. Right now v - w will do the equivalent of v + (-w) where the neg takes the inverse of w. I think it should align instead with what __add__ does and use v.eadd(w, add_op=MINUS). The old behavior can still be had by adding the negation. This makes all the binary operations consistent, and allows me to make a scalar construction like w - 5 which would become w.apply_second(MINUS, 5). Any thoughts @szarnyasg and @marci543 ? I made a PR #69.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
michelpcommented, Aug 13, 2020

And you know, the more I think about it, + and * maybe aren’t the best map to eWiseAdd and eWiseMult which are really much more like & (union) and | (intersection) operations that just happen to default to plus and times operations and the actual math operations are just nice shortcuts to eadd with fixed operations. Maybe I’m overthinking it.

0reactions
michelpcommented, Aug 20, 2020

As we discussed all math operators are now A.eadd(B) with the appropriate binary operator. I’ll address the possibility of union and intersection operators in another issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a typical instance of using '__rsub__' method in Python?
__rsub__(x) is called if x.__sub__(y) returns NotImplemented . I can't picture why the method is necessary and how exactly it is used in ......
Read more >
Python __isub__() Magic Method - Finxter
Syntax. object.__isub__(self, other). The Python __isub__() magic method implements in-place subtraction x -= y that subtracts the operands from each other ...
Read more >
9. Magic Methods | OOP | python-course.eu
There is a special (or a "magic") method for every operator sign. The magic method for the "+" sign is the __add__ method....
Read more >
Is the result of sub() and rsub() the same? Why/why not?
Ans: No the result of sub() and rsub() is not same because performing subtraction on two different operands in different order can produce...
Read more >
OperatorHook - Python Wiki
... += 1: __iadd__ op-1: __sub__ 1-op: __rsub__ op -= 1: __isub__ op*1: ... print '__rsub__', def __isub__(self, other): print '__isub__',; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found