Giter VIP home page Giter VIP logo

Comments (6)

Carreau avatar Carreau commented on June 12, 2024 1

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.

AnonymouX47 avatar AnonymouX47 commented on June 12, 2024

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.

AnonymouX47 avatar AnonymouX47 commented on June 12, 2024

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.

AnonymouX47 avatar AnonymouX47 commented on June 12, 2024

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.

Carreau avatar Carreau commented on June 12, 2024

And let's close as I was dumb :-)

from matrix.

AnonymouX47 avatar AnonymouX47 commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.