docs: add optype.numpy.ctypeslib reference page#581
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new reference page documenting the optype.numpy.ctypeslib module, which provides typed ctypes constructor reexports and abstract typing aliases for NumPy scalar-like C types (addressing the request in #448 to document this niche-but-existing API surface).
Changes:
- Introduces
docs/reference/numpy/ctypeslib.mddescribing the reexportedctypesconstructors exposed byoptype.numpy.ctypeslib. - Documents the module’s higher-level abstract typing aliases (
CType,CScalar,Array, numeric families, etc.).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@jorenham could you please re-review request from copilot, so that we can check if anything is missing. Thanks! |
jorenham
left a comment
There was a problem hiding this comment.
The navigation link is missing (see zensical.toml)
| <tr> | ||
| <td align="left"><code>CType</code></td> | ||
| <td align="left"><code>ctypes._SimpleCData[T]</code></td> | ||
| <td align="left">Scalar-value ctypes base type.</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>CScalar</code></td> | ||
| <td align="left"><code>ctypes._CData</code></td> | ||
| <td align="left">Broad base for ctypes objects (scalar, array, pointer, structure, union, ...).</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Array</code></td> | ||
| <td align="left"><code>ctypes.Array[CT]</code> (including nested arrays)</td> | ||
| <td align="left"><code>CT</code> is bound to <code>CType</code>.</td> | ||
| </tr> |
There was a problem hiding this comment.
You've introduce a ct alias above (line 12), but here you use the full ctypes. module.
| <tr> | ||
| <td align="left"><code>SignedInteger</code>, <code>UnsignedInteger</code></td> | ||
| <td align="left">signed and unsigned integer constructor groups</td> | ||
| <td align="left"></td> | ||
| </tr> |
There was a problem hiding this comment.
i used for SignedInteger and UnsignedInteger "when we call to construct something", but i feel i was wrong here , it should be actual union type directly from our code like Int8 | Int16 | Int32 | Int64 | Short | IntC | IntP | Long | LongLong.
i'll update ..
| <td align="left"><code>CT</code> is bound to <code>CType</code>.</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>SignedInteger</code>, <code>UnsignedInteger</code></td> |
There was a problem hiding this comment.
Let's keep to to one row per type alias, and explicitly describe the (union of) C types.
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Void</code></td> | ||
| <td align="left"><code>ctypes.Structure | ctypes.Union</code></td> |
There was a problem hiding this comment.
| <td align="left"><code>ctypes.Structure | ctypes.Union</code></td> | |
| <td align="left"><code>ct.Structure | ct.Union</code></td> |
| <tr> | ||
| <td align="left"><code>Integer</code>, <code>Floating</code>, <code>ComplexFloating</code></td> | ||
| <td align="left">numeric scalar families</td> | ||
| <td align="left">Modeled via <code>CScalar</code> for static typing.</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Inexact</code>, <code>Number</code></td> | ||
| <td align="left">combined numeric families</td> | ||
| <td align="left"><code>Inexact = Floating | ComplexFloating</code>, <code>Number = Integer | Floating | ComplexFloating</code>.</td> | ||
| </tr> |
There was a problem hiding this comment.
These should also be split up and described in terms of their actual union types, as above
| <tr> | ||
| <th align="left">alias</th> | ||
| <th align="left">covers</th> | ||
| <th align="left">notes</th> |
There was a problem hiding this comment.
I don't think we need this "notes" column. The type definitions speak for itself, and I expect that every reader of this page will understand that union types cannot be instantiated at runtime.
| import ctypes as ct | ||
| ``` | ||
|
|
||
| ## Reexported `ctypes` constructors |
There was a problem hiding this comment.
| ## Reexported `ctypes` constructors | |
| ## Concrete types |
| <tr> | ||
| <td align="left"><code>Int8</code>, <code>UInt8</code>, <code>Int16</code>, <code>UInt16</code>, <code>Int32</code>, <code>UInt32</code>, <code>Int64</code>, <code>UInt64</code></td> | ||
| <td align="left"><code>c_int8</code>, <code>c_uint8</code>, <code>c_int16</code>, <code>c_uint16</code>, <code>c_int32</code>, <code>c_uint32</code>, <code>c_int64</code>, <code>c_uint64</code></td> | ||
| <td align="left">fixed-width integers</td> | ||
| <td align="left"></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Byte</code>, <code>UByte</code>, <code>Short</code>, <code>UShort</code>, <code>IntC</code>, <code>UIntC</code>, <code>IntP</code>, <code>UIntP</code>, <code>Long</code>, <code>ULong</code>, <code>LongLong</code>, <code>ULongLong</code></td> | ||
| <td align="left"><code>c_byte</code>, <code>c_ubyte</code>, <code>c_short</code>, <code>c_ushort</code>, <code>c_int</code>, <code>c_uint</code>, <code>c_ssize_t</code>, <code>c_size_t</code>, <code>c_long</code>, <code>c_ulong</code>, <code>c_longlong</code>, <code>c_ulonglong</code></td> | ||
| <td align="left">platform-width integers</td> | ||
| <td align="left"><code>UIntP</code> uses <code>c_size_t</code> (<code>c_void_p</code> on NumPy < 2, but almost always equivalent).</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Float32</code>, <code>Float64</code>, <code>LongDouble</code></td> | ||
| <td align="left"><code>c_float</code>, <code>c_double</code>, <code>c_longdouble</code></td> | ||
| <td align="left">floating-point</td> | ||
| <td align="left"><code>LongDouble</code> is mainly useful as a type annotation target.</td> | ||
| </tr> | ||
| <tr> | ||
| <td align="left"><code>Complex64</code>, <code>Complex128</code>, <code>CLongDouble</code></td> | ||
| <td align="left"><code>c_float_complex</code>, <code>c_double_complex</code>, <code>c_longdouble_complex</code></td> | ||
| <td align="left">complex floating-point</td> | ||
| <td align="left">Available on Python 3.14+ on non-Windows only; otherwise these aliases are <code>Never</code>.</td> | ||
| </tr> |
There was a problem hiding this comment.
One row per type would make this easier to read.
There was a problem hiding this comment.
yes, this make sense .
|
thanks for the review, this needs lot improvement, i'll take some time for this and update (maybe on sunday) |
|
hoping did not miss anything, i'll try to verify once again from my side, as i think this is going to create pain for you to review 🙏 . |
fixes #448