Skip to content

ENH: Allow user-dtypes return views on .conjugate() - #31264

Merged
seberg merged 3 commits into
numpy:mainfrom
seberg:conj-user-dtypes
Apr 20, 2026
Merged

seberg merged 3 commits into
numpy:mainfrom
seberg:conj-user-dtypes

Conversation

@seberg

@seberg seberg commented Apr 17, 2026

Copy link
Copy Markdown
Member

This uses the fact that if something doesn't define an imag, then conjugate() should be defined as a simple view (similar to .real).

This is a follow-up of a previous PR, where I didn't implement this isn't really backportable.

With this, QuadDType for example does return a view (and a complex new-style dtype can opt out this).

This doesn't yet support for .conjugate() to return a view for complex numbers (which would make a lot of sense and could be added but take a bit more effort).

CC @SwayamInSync in case you have time to do the main review maybe, follow up to that other PR (but not backportable, IMO -- I really don't mind adding that .conj() could be a view eventually).

This uses the fact that if something _doesn't_ define an imag, then
`conjugate()` should be defined as a simple view (similar to `.real`).

This is a follow-up of a previous PR, where I didn't implement this
isn't really backportable.

With this, QuadDType for example does return a view (and a complex
new-style dtype can opt out this).

This _doesn't_ yet support for `.conjugate()` to return a view for
complex numbers (which would make a lot of sense and could be added
but take a bit more effort).

@SwayamInSync SwayamInSync left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks @seberg
I agree making the ufunc path also return views might be good work, but at least with this PR user-defined behaviour will be consistent with builtins real types.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense, nice!

@seberg

seberg commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews.

@seberg
seberg merged commit b6bc683 into numpy:main Apr 20, 2026
86 checks passed
@seberg
seberg deleted the conj-user-dtypes branch April 20, 2026 07:26
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.

3 participants