summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-04-15 20:53:52 +0300
committerGitHub <noreply@github.com>2019-04-15 20:53:52 +0300
commit80823c4daa17c736961fa4f5b7b2ec8a0cad904f (patch)
tree149f3f7b68d0550d93f5fb354d9d674599c56dba
parent37da972f018a5605aba398b2dacc103f619971cf (diff)
parent271d2dd1c6c8c8d29fd90570b187e61743028501 (diff)
downloadnumpy-80823c4daa17c736961fa4f5b7b2ec8a0cad904f.tar.gz
Merge pull request #13335 from eric-wieser/document-ctypeslib
DOC: Add as_ctypes_type to the documentation
-rw-r--r--doc/release/1.16.1-notes.rst4
-rw-r--r--doc/release/1.17.0-notes.rst4
-rw-r--r--doc/source/reference/routines.ctypeslib.rst1
-rw-r--r--numpy/ctypeslib.py12
4 files changed, 13 insertions, 8 deletions
diff --git a/doc/release/1.16.1-notes.rst b/doc/release/1.16.1-notes.rst
index 2483b1834..2a190ef91 100644
--- a/doc/release/1.16.1-notes.rst
+++ b/doc/release/1.16.1-notes.rst
@@ -80,9 +80,9 @@ Improvements
Further improvements to ``ctypes`` support in ``np.ctypeslib``
--------------------------------------------------------------
-A new ``np.ctypeslib.as_ctypes_type`` function has been added, which can be
+A new `numpy.ctypeslib.as_ctypes_type` function has been added, which can be
used to converts a `dtype` into a best-guess `ctypes` type. Thanks to this
-new function, ``np.ctypeslib.as_ctypes`` now supports a much wider range of
+new function, `numpy.ctypeslib.as_ctypes` now supports a much wider range of
array types, including structures, booleans, and integers of non-native
endianness.
diff --git a/doc/release/1.17.0-notes.rst b/doc/release/1.17.0-notes.rst
index 1155449a7..54980e8b4 100644
--- a/doc/release/1.17.0-notes.rst
+++ b/doc/release/1.17.0-notes.rst
@@ -152,9 +152,9 @@ lengths has improved and is on par with complex-valued FFTs.
Further improvements to ``ctypes`` support in ``np.ctypeslib``
--------------------------------------------------------------
-A new ``np.ctypeslib.as_ctypes_type`` function has been added, which can be
+A new `numpy.ctypeslib.as_ctypes_type` function has been added, which can be
used to converts a `dtype` into a best-guess `ctypes` type. Thanks to this
-new function, ``np.ctypeslib.as_ctypes`` now supports a much wider range of
+new function, `numpy.ctypeslib.as_ctypes` now supports a much wider range of
array types, including structures, booleans, and integers of non-native
endianness.
diff --git a/doc/source/reference/routines.ctypeslib.rst b/doc/source/reference/routines.ctypeslib.rst
index 71b944a63..562638e9c 100644
--- a/doc/source/reference/routines.ctypeslib.rst
+++ b/doc/source/reference/routines.ctypeslib.rst
@@ -8,6 +8,7 @@ C-Types Foreign Function Interface (:mod:`numpy.ctypeslib`)
.. autofunction:: as_array
.. autofunction:: as_ctypes
+.. autofunction:: as_ctypes_type
.. autofunction:: ctypes_load_library
.. autofunction:: load_library
.. autofunction:: ndpointer
diff --git a/numpy/ctypeslib.py b/numpy/ctypeslib.py
index 1967a85b6..55b0d721c 100644
--- a/numpy/ctypeslib.py
+++ b/numpy/ctypeslib.py
@@ -462,7 +462,7 @@ if ctypes is not None:
def as_ctypes_type(dtype):
- """
+ r"""
Convert a dtype into a ctypes type.
Parameters
@@ -472,7 +472,7 @@ if ctypes is not None:
Returns
-------
- ctypes
+ ctype
A ctype scalar, union, array, or struct
Raises
@@ -485,13 +485,17 @@ if ctypes is not None:
This function does not losslessly round-trip in either direction.
``np.dtype(as_ctypes_type(dt))`` will:
+
- insert padding fields
- reorder fields to be sorted by offset
- discard field titles
``as_ctypes_type(np.dtype(ctype))`` will:
- - discard the class names of ``Structure``s and ``Union``s
- - convert single-element ``Union``s into single-element ``Structure``s
+
+ - discard the class names of `ctypes.Structure`\ s and
+ `ctypes.Union`\ s
+ - convert single-element `ctypes.Union`\ s into single-element
+ `ctypes.Structure`\ s
- insert padding fields
"""