mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-07 16:13:27 +08:00
chore: simplify numpy dtype ctor (#3869)
* Simplify numpy dtype ctor * Simplify c_str ctor * Remove compat macro for str in numpy
This commit is contained in:
parent
45164c1fcb
commit
3829b7624c
@ -540,18 +540,16 @@ public:
|
|||||||
PYBIND11_OBJECT_DEFAULT(dtype, object, detail::npy_api::get().PyArrayDescr_Check_);
|
PYBIND11_OBJECT_DEFAULT(dtype, object, detail::npy_api::get().PyArrayDescr_Check_);
|
||||||
|
|
||||||
explicit dtype(const buffer_info &info) {
|
explicit dtype(const buffer_info &info) {
|
||||||
dtype descr(_dtype_from_pep3118()(PYBIND11_STR_TYPE(info.format)));
|
dtype descr(_dtype_from_pep3118()(pybind11::str(info.format)));
|
||||||
// If info.itemsize == 0, use the value calculated from the format string
|
// If info.itemsize == 0, use the value calculated from the format string
|
||||||
m_ptr = descr.strip_padding(info.itemsize != 0 ? info.itemsize : descr.itemsize())
|
m_ptr = descr.strip_padding(info.itemsize != 0 ? info.itemsize : descr.itemsize())
|
||||||
.release()
|
.release()
|
||||||
.ptr();
|
.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit dtype(const std::string &format) {
|
explicit dtype(const std::string &format) : dtype(from_args(pybind11::str(format))) {}
|
||||||
m_ptr = from_args(pybind11::str(format)).release().ptr();
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit dtype(const char *format) : dtype(std::string(format)) {}
|
explicit dtype(const char *format) : dtype(from_args(pybind11::str(format))) {}
|
||||||
|
|
||||||
dtype(list names, list formats, list offsets, ssize_t itemsize) {
|
dtype(list names, list formats, list offsets, ssize_t itemsize) {
|
||||||
dict args;
|
dict args;
|
||||||
@ -638,7 +636,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct field_descr {
|
struct field_descr {
|
||||||
PYBIND11_STR_TYPE name;
|
pybind11::str name;
|
||||||
object format;
|
object format;
|
||||||
pybind11::int_ offset;
|
pybind11::int_ offset;
|
||||||
};
|
};
|
||||||
@ -653,7 +651,7 @@ private:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
field_descriptors.push_back(
|
field_descriptors.push_back(
|
||||||
{(PYBIND11_STR_TYPE) name, format.strip_padding(format.itemsize()), offset});
|
{(pybind11::str) name, format.strip_padding(format.itemsize()), offset});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(field_descriptors.begin(),
|
std::sort(field_descriptors.begin(),
|
||||||
@ -1359,7 +1357,7 @@ PYBIND11_NOINLINE void register_structured_dtype(any_container<field_descriptor>
|
|||||||
pybind11_fail(std::string("NumPy: unsupported field dtype: `") + field.name + "` @ "
|
pybind11_fail(std::string("NumPy: unsupported field dtype: `") + field.name + "` @ "
|
||||||
+ tinfo.name());
|
+ tinfo.name());
|
||||||
}
|
}
|
||||||
names.append(PYBIND11_STR_TYPE(field.name));
|
names.append(pybind11::str(field.name));
|
||||||
formats.append(field.descr);
|
formats.append(field.descr);
|
||||||
offsets.append(pybind11::int_(field.offset));
|
offsets.append(pybind11::int_(field.offset));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user