Good use of __dunder__ methods in numpy

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Good use of __dunder__ methods in numpy

Abdur-Rahmaan Janhangeer
Greetings list,

I have a talk about dunder methods in Python 


and it would be nice to include Numpy in the mix. Can someone point me to one or two use cases / file link where dunder methods help numpy? 

Thanks

fun info: i am a tiny numpy contributor with a one line merge.

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Sebastian Berg
Hi,

On Thu, 2020-03-05 at 11:14 +0400, Abdur-Rahmaan Janhangeer wrote:

> Greetings list,
>
> I have a talk about dunder methods in Python
>
> (
> https://conference.mscc.mu/speaker/67604187-57c3-4be6-987c-ea4bef388ad3
> )
>
> and it would be nice to include Numpy in the mix. Can someone point
> me to one or two use cases / file link where dunder methods help
> numpy?
>
I am not sure in what sense you are looking for. NumPy has its own set
of dunder methods (some of which should not be used super much
probably), like `__array__`, `__array_interface__`, `__array_ufunc__`,
`__array_function__`, `__array_finalize__`, ...
So we are using `__array_*__` for numpy related dunders.

Of course we use most Python defined dunders, but I am not sure that
you are looking for that?

Best,

Sebastian


> Thanks
>
> fun info: i am a tiny numpy contributor with a one line merge.
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Abdur-Rahmaan Janhangeer
Ah thank you for info, yes i'm talking about normal methods. 
If i can get a link to a file that shows how dunder methods help with having cool coding APIs that would be great!

Thanks!


Yours,

Abdur-Rahmaan Janhangeer
Mauritius


On Thu, Mar 5, 2020 at 10:32 PM Sebastian Berg <[hidden email]> wrote:
Hi,

On Thu, 2020-03-05 at 11:14 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
>
> I have a talk about dunder methods in Python
>
> (
> https://conference.mscc.mu/speaker/67604187-57c3-4be6-987c-ea4bef388ad3
> )
>
> and it would be nice to include Numpy in the mix. Can someone point
> me to one or two use cases / file link where dunder methods help
> numpy?
>

I am not sure in what sense you are looking for. NumPy has its own set
of dunder methods (some of which should not be used super much
probably), like `__array__`, `__array_interface__`, `__array_ufunc__`,
`__array_function__`, `__array_finalize__`, ...
So we are using `__array_*__` for numpy related dunders.

Of course we use most Python defined dunders, but I am not sure that
you are looking for that?

Best,

Sebastian


> Thanks
>
> fun info: i am a tiny numpy contributor with a one line merge.
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Gregory Lee


On Thu, Mar 5, 2020 at 2:01 PM Abdur-Rahmaan Janhangeer <[hidden email]> wrote:
Ah thank you for info, yes i'm talking about normal methods. 
If i can get a link to a file that shows how dunder methods help with having cool coding APIs that would be great!

Thanks!


Yours,

Abdur-Rahmaan Janhangeer
Mauritius


You may want to take a look at PEP 465 as an example, then. If I recall correctly, the __matmul__ method described in it was added to the standard library largely with NumPy in mind.


 

On Thu, Mar 5, 2020 at 10:32 PM Sebastian Berg <[hidden email]> wrote:
Hi,

On Thu, 2020-03-05 at 11:14 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
>
> I have a talk about dunder methods in Python
>
> (
> https://conference.mscc.mu/speaker/67604187-57c3-4be6-987c-ea4bef388ad3
> )
>
> and it would be nice to include Numpy in the mix. Can someone point
> me to one or two use cases / file link where dunder methods help
> numpy?
>

I am not sure in what sense you are looking for. NumPy has its own set
of dunder methods (some of which should not be used super much
probably), like `__array__`, `__array_interface__`, `__array_ufunc__`,
`__array_function__`, `__array_finalize__`, ...
So we are using `__array_*__` for numpy related dunders.

Of course we use most Python defined dunders, but I am not sure that
you are looking for that?

Best,

Sebastian


> Thanks
>
> fun info: i am a tiny numpy contributor with a one line merge.
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Abdur-Rahmaan Janhangeer


On Fri, 6 Mar 2020, 02:14 Gregory Lee, <[hidden email]> wrote:

You may want to take a look at PEP 465 as an example, then. If I recall correctly, the __matmul__ method described in it was added to the standard library largely with NumPy in mind.


Hum thanks i just discovered a completely new feature of Py along the way (the @)

Thanks 👌👍🎉


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Chris Barker - NOAA Federal
In reply to this post by Gregory Lee
On Thu, Mar 5, 2020 at 2:15 PM Gregory Lee <[hidden email]> wrote:
If i can get a link to a file that shows how dunder methods help with having cool coding APIs that would be great!


You may want to take a look at PEP 465 as an example, then. If I recall correctly, the __matmul__ method described in it was added to the standard library largely with NumPy in mind.

and so were "rich comparisons", and in-place operators (at least in part).

numpy is VERY, VERY, heavily built on the concept of overloading operators, i.e. using dunders or magic methods.

I'm going to venture a guess that numpy arrays custom define every single standard dunder -- and certainly most of them.

-CHB



 
On Thu, Mar 5, 2020 at 10:32 PM Sebastian Berg <[hidden email]> wrote:
Hi,

On Thu, 2020-03-05 at 11:14 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
>
> I have a talk about dunder methods in Python
>
> (
> https://conference.mscc.mu/speaker/67604187-57c3-4be6-987c-ea4bef388ad3
> )
>
> and it would be nice to include Numpy in the mix. Can someone point
> me to one or two use cases / file link where dunder methods help
> numpy?
>

I am not sure in what sense you are looking for. NumPy has its own set
of dunder methods (some of which should not be used super much
probably), like `__array__`, `__array_interface__`, `__array_ufunc__`,
`__array_function__`, `__array_finalize__`, ...
So we are using `__array_*__` for numpy related dunders.

Of course we use most Python defined dunders, but I am not sure that
you are looking for that?

Best,

Sebastian


> Thanks
>
> fun info: i am a tiny numpy contributor with a one line merge.
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Good use of __dunder__ methods in numpy

Abdur-Rahmaan Janhangeer
Thanks for info!

Kind Regards,

Abdur-Rahmaan Janhangeer
Mauritius


On Mon, Mar 23, 2020 at 10:56 PM Chris Barker <[hidden email]> wrote:
On Thu, Mar 5, 2020 at 2:15 PM Gregory Lee <[hidden email]> wrote:
If i can get a link to a file that shows how dunder methods help with having cool coding APIs that would be great!


You may want to take a look at PEP 465 as an example, then. If I recall correctly, the __matmul__ method described in it was added to the standard library largely with NumPy in mind.

and so were "rich comparisons", and in-place operators (at least in part).

numpy is VERY, VERY, heavily built on the concept of overloading operators, i.e. using dunders or magic methods.

I'm going to venture a guess that numpy arrays custom define every single standard dunder -- and certainly most of them.

-CHB



 
On Thu, Mar 5, 2020 at 10:32 PM Sebastian Berg <[hidden email]> wrote:
Hi,

On Thu, 2020-03-05 at 11:14 +0400, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
>
> I have a talk about dunder methods in Python
>
> (
> https://conference.mscc.mu/speaker/67604187-57c3-4be6-987c-ea4bef388ad3
> )
>
> and it would be nice to include Numpy in the mix. Can someone point
> me to one or two use cases / file link where dunder methods help
> numpy?
>

I am not sure in what sense you are looking for. NumPy has its own set
of dunder methods (some of which should not be used super much
probably), like `__array__`, `__array_interface__`, `__array_ufunc__`,
`__array_function__`, `__array_finalize__`, ...
So we are using `__array_*__` for numpy related dunders.

Of course we use most Python defined dunders, but I am not sure that
you are looking for that?

Best,

Sebastian


> Thanks
>
> fun info: i am a tiny numpy contributor with a one line merge.
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion