ENH: Convert flatiter, broadcast and nditer to heap types - #32641
prathamhole14 wants to merge 5 commits into
Conversation
77ccd21 to
9e636d2
Compare
9e636d2 to
ef6096d
Compare
|
Ready for review. |
| api_table[NPY_API_INDEX_PyArrayMultiIter_Type] = state->broadcast_type; | ||
| api_table[NPY_API_INDEX_NpyIter_Type] = state->nditer_type; | ||
| } | ||
|
|
There was a problem hiding this comment.
Since we export these types, and CPython errors when creating static types with heap type base classes, I am not sure we can do this yet.
There was a problem hiding this comment.
You are right, PyType_Ready rejects it and none of these three set Py_TPFLAGS_BASETYPE and neither does ufunc, so the static C route only ever worked because PyType_Ready skips that check.
Maybe BASETYPE is the line to draw here. If a type never claimed to be a base, converting it seems correct.
ndarray, dtype and the scalar types are the real problem and i think they need their own discussion.
Also does this require release note?
Edit: I have added release note
|
I don't think we can merge this, since it will break any subclassing of these types with static types. |
|
Forgive my ignorance Matti but I was just curious, does numpy subclass those with static types somewhere or are you thinking users might? |
|
Users might, since we export them in the API struct. |
|
So would like to know which direction is acceptable.
If neither works, then |
|
I think we should discuss this at a community/triage meeting. In the meantime, can you scan popular github projects for code subclassing these types as static (or for that matter, even heap) types? |
|
I searched for this and for the types in this PR no project sets |
|
We discussed this at the community meeting and the general opinion was positive, the probability that anyone is subclassing these is quite small. I will give this one more review pass. |
|
Other than @ngoldbaum's valid analysis on the performance cost of the change to heap types on #32552, I didn't find any problems here. One thing it might be nice to check is that the assignments of the type in PyArray_API succeed. A good test would be to add to |
PR summary
Related to: #31913 as part of adaptation of LIMITED API for
_multiarray_umathmoduleAlso related to: #32451 and #32747
AI Disclosure
Ported
nditermyself and after getting idea of it (and other changes are almost similar) and mechanical used claude opus 5 extra high to convert to heap type, and verified the code changes myself.