Skip to content

Add complex number support to astype #445

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

Merged
merged 4 commits into from
Nov 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion spec/API_specification/array_api/data_type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array:
Casting floating-point ``NaN`` and ``infinity`` values to integral data types is not specified and is implementation-dependent.

.. note::
When casting a boolean input array to a real-valued data type, a value of ``True`` must cast to a numeric value equal to ``1``, and a value of ``False`` must cast to a numeric value equal to ``0``.
When casting a complex floating-point array to a real-valued data type, imaginary components must be discarded (i.e., for a complex floating-point array ``x``, ``astype(x)`` must equal ``astype(real(x))``).

More generally, the result of casting a complex floating-point array ``x`` to a real-valued data type must be equal to the result of casting a real-valued floating-point array containing only the real components of ``x``.

.. note::
When casting a boolean input array to a real-valued data type, a value of ``True`` must cast to a real-valued number equal to ``1``, and a value of ``False`` must cast to a real-valued number equal to ``0``.

When casting a boolean input array to a complex floating-point data type, a value of ``True`` must cast to a complex number equal to ``1 + 0j``, and a value of ``False`` must cast to a complex number equal to ``0 + 0j``.

.. note::
When casting a real-valued input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``.

When casting a complex floating-point array to ``bool``, a value of ``0 + 0j`` must cast to ``False``, and all other values must cast to ``True``.

Parameters
----------
x: array
Expand Down