MAINT: use new dtype in view creation rather than going through two views by mhvk · Pull Request #31271 · numpy/numpy · GitHub
Skip to content

MAINT: use new dtype in view creation rather than going through two views#31271

Merged
seberg merged 1 commit intonumpy:mainfrom
mhvk:view-include-dtype-change
Apr 23, 2026
Merged

MAINT: use new dtype in view creation rather than going through two views#31271
seberg merged 1 commit intonumpy:mainfrom
mhvk:view-include-dtype-change

Conversation

@mhvk
Copy link
Copy Markdown
Contributor

@mhvk mhvk commented Apr 19, 2026

EDITED since now follow-up rather than an alternative to #31234.

This PR lets PyArray_View() do a one-step view of both a possibly new subtype and a new dtype. To avoid duplicated checks on the dtype, I factored out that piece of the internal _set_dtype.

No AI was used.

@seberg
Copy link
Copy Markdown
Member

seberg commented Apr 19, 2026

@mhvk mhvk force-pushed the view-include-dtype-change branch 4 times, most recently from c051800 to 3487318 Compare April 23, 2026 10:51
@mhvk mhvk marked this pull request as ready for review April 23, 2026 10:53
@mhvk
Copy link
Copy Markdown
Contributor Author

mhvk commented Apr 23, 2026

@seberg - I've adapted this follow-up, where just one view is done for the "standard in the future" path. Note that I got carried away a bit in my reorganization of the code, which makes the difference view rather poor. You may want to just look at the file directly... (I do think it has become clearer as a result, in particular by just putting the path of the future first...)

@seberg
Copy link
Copy Markdown
Member

seberg commented Apr 23, 2026

Nice, so this "just" re-organizes the double view. I'll have a look, moves things around, but I think otherwise I'll probably just put it in unless I find an issue.

(I have a "more complete fix (TM)" for the deprecation, almost lined up, but might just put this in and rebase. it's a bit ridiculous and of course nothing is really 100%, but considering how important the .dtype assignment deprecation is in a sense...)

Comment thread numpy/_core/src/multiarray/convert.c
@mhvk mhvk force-pushed the view-include-dtype-change branch 2 times, most recently from e6533c0 to d1f2b1c Compare April 23, 2026 11:23
@mhvk
Copy link
Copy Markdown
Contributor Author

mhvk commented Apr 23, 2026

MacOS / Accelerate warning would seem unrelated...

@mhvk mhvk force-pushed the view-include-dtype-change branch from d1f2b1c to 21828a3 Compare April 23, 2026 13:18
@mhvk
Copy link
Copy Markdown
Contributor Author

mhvk commented Apr 23, 2026

@seberg - sorry, looking at it again, I felt I could clean up the addition a bit more, so I did... Should now be truly ready for final review.

Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

A few small nits I'll just apply. Thanks.

Comment thread numpy/_core/src/multiarray/convert.c
Comment thread numpy/_core/src/multiarray/convert.c Outdated
Comment thread numpy/_core/src/multiarray/common.c Outdated
Comment thread numpy/_core/src/multiarray/getset.c
…iews.

This includes moving the new dtype checking stuff to common.c and use
that in dtype setting as well.
@seberg seberg force-pushed the view-include-dtype-change branch from 21828a3 to e751d28 Compare April 23, 2026 13:51
@mhvk
Copy link
Copy Markdown
Contributor Author

mhvk commented Apr 23, 2026

@seberg seberg changed the title Let view include dtype change and pass that to __array_finalize__ MAINT: Refactor helper and create only one view if dtype is changed Apr 23, 2026
@seberg seberg changed the title MAINT: Refactor helper and create only one view if dtype is changed MAINT: Refactor helper for single view if view dtype is change Apr 23, 2026
@seberg seberg changed the title MAINT: Refactor helper for single view if view dtype is change MAINT: use new dtype in view creation rather than going through two views Apr 23, 2026
@seberg seberg merged commit f1b52e3 into numpy:main Apr 23, 2026
86 checks passed
@mhvk mhvk deleted the view-include-dtype-change branch April 23, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants