Comments (6)
ha, yes, sorry PEBKAC on my end, i definitely though that it was other.__add__(self)
, and you properly used NotImplemented in other method, I just came across the reddit thread and tried to do have a quick look, should have spent more time. Definitely hopping to see high quality contributions like yours on project in the scientific community like numpy.
from matrix.
Thanks for this suggestion again 🙏🏾 ...
... but I think that's how it should be.
A Row
or Column
object supports inter-operations with any iterable of real numbers, can be a tuple, list, generator, etc...
The purpose of reflected binary operations (i.e __r*__
methods) is to implement support for operations with other types which do not, by themselves, support operations with the type in question.
For instance:
list() + Row()
-> Here, Row.__radd__
is the only possible reason for a successful operation...
list.__add__
is called first (because Row
is not a subclass of list
), it will definitely return NotImplemented
because list
only supports addition with list
, then the operation will fallback to Row.__radd__
which should take care of the operation. If Row.__radd__
returns NotImplemented
, it'll result in the failure of the entire operation.
See here (the explanation with the Note under) for details on the fallback chain for arithmetic and bitwise binary operations.
Also, I don't see how recursion can occur here 🤔... __add__
doesn't call __radd__
. 😃
from matrix.
and Python will take care of calling the add method of the other object.
Umm... after reading this again, seems to me like you thought it was other.__add__
being called.
No, it's self.__add__
(i.e RowColumn.__add__
) 🤗
What it does is to simply take the operation as if it were self + other
, since addition is commutative.
You'll see __rsub__
doesn't behave like that, since subtraction isn't commutative.
from matrix.
Disclaimer:
I see you're definitely not a novice at Python and I guess it was just a mistake or an oversight, I do not mean to "lecture" you in any way. 🙌🏾
We all make mistakes every now and then.
I might even be the one in error here 🤔... Please feel free to correct me and explain if it be so.
Thanks
from matrix.
And let's close as I was dumb :-)
from matrix.
ha, yes, sorry PEBKAC on my end, i definitely though that it was
other.__add__(self)
, and you properly used
NotImplemented in other method, I just came across the reddit thread and tried to do have a quick look, should have spent more time.
No problem at all. I appreciate the fact that you even took time out to go through my code.
Definitely hopping to see high quality contributions like yours on project in the scientific community like numpy.
Thanks so much for the compliments 🥺... I'll make sure to contribute to major projects as I progress. 😃
from matrix.
Related Issues (2)
- Grammatical Error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matrix.