diff options
author | Nathan Goldbaum <nathan.goldbaum@gmail.com> | 2023-03-10 08:21:19 -0700 |
---|---|---|
committer | Nathan Goldbaum <nathan.goldbaum@gmail.com> | 2023-03-17 09:52:37 -0600 |
commit | a24e785ead6dbd80050cb157326a6a23b279d4e4 (patch) | |
tree | b2b941a4fa915dfda6b2f8ff6def671eafd8cb4c /numpy/array_api | |
parent | e42c9503a14d66adfd41356ef5640c6975c45218 (diff) | |
download | numpy-a24e785ead6dbd80050cb157326a6a23b279d4e4.tar.gz |
ENH: allow using dtype classes in array creation functions
This enables writing np.array(some_object, dtype=type(np.dtype('i'))). This
is a follow-on from https://github.com/numpy/numpy/pull/23154, see that PR
for more details.
I had to add a new include to `ctors.h` to bring in the definition of the
`npy_dtype_info` struct. Since `ctors.h` is included in many other files inside
numpy, I found that I needed to modify fewer includes across numpy if I moved
the definition of `npy_dtype_info` to `common.h` from `descriptor.h`. The new
includes of `common.h` are needed to support later includes of `ctors.h` in
those files. If anyone has an alternate place to put `npy_dtype_info` that would
cause less churn of includes I'd love to hear about it.
I spent a bunch of time tweaking the reference counts. I'm reasonably confident
this is correct but not 100%, an additional careful pass over the reference
count logic from a reviewer would be very appreciated.
I could have made `_PyArray_FromAny` and `_PyArray_CheckFromAny` take just a
`npy_dtype_info` struct, but I found it made the reference count logic more
complicated, since `PyArray_FromAny` and `PyArray_CheckFromAny` steal the
reference to the descriptor they are passed and I needed to conserve that
behavior. Also both functions support passing in a `NULL` pointer for the
descriptor and I needed to maintain that behavior as well.
The change to `ucsnarrow.h` fixes a preexisting conflict with the prototype
in `ucsnarrow.c` that triggered a compiler error while I was working on this.
Diffstat (limited to 'numpy/array_api')
0 files changed, 0 insertions, 0 deletions