Skip to content

Allow other (non-sub)classes to handle binary ufuncs with unyt_array#641

Open
kyleaoman wants to merge 3 commits into
yt-project:mainfrom
kyleaoman:array_ufunc_rmul
Open

Allow other (non-sub)classes to handle binary ufuncs with unyt_array#641
kyleaoman wants to merge 3 commits into
yt-project:mainfrom
kyleaoman:array_ufunc_rmul

Conversation

@kyleaoman
Copy link
Copy Markdown
Contributor

#572 added the ability for subclasses of unyt_array to intervene before and after numpy ufunc calls to "prepare" the arguments and "finalize" the result.

In this PR I propose to extend this ability to classes that are not subclasses, allowing them to implement __unyt_ufunc_prepare__ and __unyt_ufunc_finalize__ if they wish. Note that the other class cannot control the result via e.g. __mul__ and __rmul__ because control ends up in unyt_array.__array_ufunc__ and leads to an exception leaving the other class no chance to intervene.

The included tests have a bare-bones example of how a class might use this functionality.

#640 is related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant