-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Dtype kind vs char #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dtype kind vs char #2864
Changes from 5 commits
df1be99
b59299d
1400520
f455222
400ffea
f3ba900
14c9f7d
46701ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,6 +251,38 @@ py::list test_dtype_ctors() { | |
| return list; | ||
| } | ||
|
|
||
| py::list test_dtype_kind() { | ||
| py::list list; | ||
| for (auto& dt : { | ||
| py::dtype("bool8"), // bool | ||
| py::dtype("int16"), // short | ||
| py::dtype("int32"), // int | ||
| py::dtype("int64"), // long int | ||
| py::dtype("float32"), // float | ||
| py::dtype("float64"), // double | ||
| py::dtype("float128") // long double | ||
| }) { | ||
| list.append(dt.kind()); | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| py::list test_dtype_char_() { | ||
| py::list list; | ||
| for (auto& dt : { | ||
| py::dtype("bool8"), // bool | ||
| py::dtype("int16"), // short | ||
| py::dtype("int32"), // int | ||
| py::dtype("int64"), // long int | ||
| py::dtype("float32"), // float | ||
| py::dtype("float64"), // double | ||
| py::dtype("float128") // long double | ||
|
||
| }) { | ||
| list.append(dt.char_()); | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| struct A {}; | ||
| struct B {}; | ||
|
|
||
|
|
@@ -376,6 +408,8 @@ TEST_SUBMODULE(numpy_dtypes, m) { | |
| return l; | ||
| }); | ||
| m.def("test_dtype_ctors", &test_dtype_ctors); | ||
| m.def("test_dtype_kind", &test_dtype_kind); | ||
| m.def("test_dtype_char_", &test_dtype_char_); | ||
| m.def("test_dtype_methods", []() { | ||
| py::list list; | ||
| auto dt1 = py::dtype::of<int32_t>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a comment that we're following the Python API of
dtype(i.e.,dtype.char), rather than NumPy's internal C API (PyArray_Descr::type), for the name?See also https://numpy.org/devdocs/reference/c-api/types-and-structures.html#c.PyArray_Descr for the root cause of the
typevs.charconfusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay !