A few dtype method docstrings

This commit is contained in:
Ivan Smirnov 2016-10-22 10:51:04 +01:00 committed by Wenzel Jakob
parent f70cc112f0
commit ef5a38044c

View File

@ -185,26 +185,30 @@ public:
m_ptr = from_args(args).release().ptr(); m_ptr = from_args(args).release().ptr();
} }
/// This is essentially the same as calling numpy.dtype(args) in Python.
static dtype from_args(object args) { static dtype from_args(object args) {
// This is essentially the same as calling np.dtype() constructor in Python
PyObject *ptr = nullptr; PyObject *ptr = nullptr;
if (!detail::npy_api::get().PyArray_DescrConverter_(args.release().ptr(), &ptr) || !ptr) if (!detail::npy_api::get().PyArray_DescrConverter_(args.release().ptr(), &ptr) || !ptr)
pybind11_fail("NumPy: failed to create structured dtype"); pybind11_fail("NumPy: failed to create structured dtype");
return object(ptr, false); return object(ptr, false);
} }
/// Return dtype associated with a C++ type.
template <typename T> static dtype of() { template <typename T> static dtype of() {
return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::dtype(); return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::dtype();
} }
/// Size of the data type in bytes.
size_t itemsize() const { size_t itemsize() const {
return (size_t) PyArrayDescr_GET_(m_ptr, elsize); return (size_t) PyArrayDescr_GET_(m_ptr, elsize);
} }
/// Returns true for structured data types.
bool has_fields() const { bool has_fields() const {
return PyArrayDescr_GET_(m_ptr, names) != nullptr; return PyArrayDescr_GET_(m_ptr, names) != nullptr;
} }
/// Single-character type code.
char kind() const { char kind() const {
return PyArrayDescr_GET_(m_ptr, kind); return PyArrayDescr_GET_(m_ptr, kind);
} }