Conversation
Added accessors for typenum, alignment, byteorder and flags fields of PyArray_Descr struct.
for more information, see https://pre-commit.ci
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
for more information, see https://pre-commit.ci
|
Failures are due to error while cloning the Eigen repo. |
|
Actually, now that it's merged, not sure the new ctor is really necessary. Wouldn't have worked? @oleksandr-pavlyk ? |
|
Actually, since In fact modifying the test file: diff --git a/tests/test_numpy_dtypes.cpp b/tests/test_numpy_dtypes.cpp
index 7de36f2f..8ed6ff8d 100644
--- a/tests/test_numpy_dtypes.cpp
+++ b/tests/test_numpy_dtypes.cpp
@@ -291,7 +291,7 @@ py::list test_dtype_ctors() {
list.append(py::dtype(names, formats, offsets, 20));
list.append(py::dtype(py::buffer_info((void *) 0, sizeof(unsigned int), "I", 1)));
list.append(py::dtype(py::buffer_info((void *) 0, 0, "T{i:a:f:b:}", 1)));
- list.append(py::dtype(py::detail::npy_api::NPY_DOUBLE_));
+ list.append(py::dtype::from_args(py::int_(static_cast<int>(py::detail::npy_api::NPY_DOUBLE_))));
return list;
}
and running raises the same error. Even if this worked, it would still be less efficient that the added ctor, since the argument Python object needs to be constructed. |
|
I am just wondering if these is a less ambiguous way to build that ctor. Perhaps we could have it take an enum instead of an int or something along those lines? Or maybe it would make more sense to have it be a static factory method. It's a bit weird for the dtype to have an int constructor as it stands currently. Right now it's a public constructor that could only be used via an implementation detail enum, which is actually really weird. Thoughts @henryiii @rwgk ? |
|
I am just having second thoughts about having this ctor be a part of the public API for dtypes considering the values that are used for it are themselves not public. |
|
Yes, agreed, the non-public nature of type numbers has bugged me too, but I dismissed it since it is easy to Also the exposure of |
|
@oleksandr-pavlyk We can revisit this PR in connection to casters we design for #3858 . I'm sure once we see them sketched out we can figure out a better way to either expose the enums or only expose them to the casters. |
Description
Added explicit constructor for
py::dtypefrom type number. Also added accessor to retrieve thetype_numfield of the struct.While at it, added other accessors.
Added tests.
Suggested changelog entry: