|
| 1 | +.. _dpnp_tensor_data_types: |
| 2 | + |
| 3 | +.. currentmodule:: dpnp.tensor |
| 4 | + |
| 5 | +Data types |
| 6 | +========== |
| 7 | + |
| 8 | +:py:mod:`dpnp.tensor` supports the following data types: |
| 9 | + |
| 10 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 11 | +| Data Type | Description | |
| 12 | ++================+=========================================================================================================================================================================================+ |
| 13 | +| ``bool`` | Boolean (``True`` or ``False``) | |
| 14 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 15 | +| ``int8`` | An 8-bit signed integer type capable of representing :math:`v` subject to :math:`-2^7 \le v < 2^7` | |
| 16 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 17 | +| ``int16`` | A 16-bit signed integer type capable of representing :math:`v` subject to :math:`-2^{15} \le v < 2^{15}` | |
| 18 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 19 | +| ``int32`` | A 32-bit signed integer type capable of representing :math:`v` subject to :math:`-2^{31} \le v < 2^{31}` | |
| 20 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 21 | +| ``int64`` | A 64-bit signed integer type capable of representing :math:`v` subject to :math:`-2^{63} \le v < 2^{63}` | |
| 22 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 23 | +| ``uint8`` | An 8-bit unsigned integer type capable of representing :math:`v` subject to :math:`0 \le v < 2^8` | |
| 24 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 25 | +| ``uint16`` | A 16-bit unsigned integer type capable of representing :math:`v` subject to :math:`0 \le v < 2^{16}` | |
| 26 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 27 | +| ``uint32`` | A 32-bit unsigned integer type capable of representing :math:`v` subject to :math:`0 \le v < 2^{32}` | |
| 28 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 29 | +| ``uint64`` | A 64-bit unsigned integer type capable of representing :math:`v` subject to :math:`0 \le v < 2^{64}` | |
| 30 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 31 | +| ``float16`` | An IEEE-754 half-precision (16-bit) binary floating-point number (see `IEEE 754-2019`_) | |
| 32 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 33 | +| ``float32`` | An IEEE-754 single-precision (32-bit) binary floating-point number (see `IEEE 754-2019`_) | |
| 34 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 35 | +| ``float64`` | An IEEE-754 double-precision (64-bit) binary floating-point number (see `IEEE 754-2019`_) | |
| 36 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 37 | +| ``complex64`` | Single-precision (64-bit) complex floating-point number whose real and imaginary components are IEEE 754 single-precision (32-bit) binary floating-point numbers (see `IEEE 754-2019`_) | |
| 38 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 39 | +| ``complex128`` | Double-precision (128-bit) complex floating-point number whose real and imaginary components are IEEE 754 double-precision (64-bit) binary floating-point numbers (see `IEEE 754-2019`_)| |
| 40 | ++----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 41 | + |
| 42 | +.. _IEEE 754-2019: https://doi.org/10.1109%2FIEEESTD.2019.8766229 |
| 43 | + |
| 44 | +Data type support by array object :py:class:`usm_ndarray` depends on capabilities of :class:`dpctl.SyclDevice` where array is allocated. |
| 45 | + |
| 46 | +Half-precision floating-point type ``float16`` is supported only for devices whose attribute :attr:`dpctl.SyclDevice.has_aspect_fp16` evaluates to ``True``. |
| 47 | + |
| 48 | +Double-precision floating-point type ``float64`` and double-precision complex floating-point type ``complex128`` are supported only for devices whose attribute :attr:`dpctl.SyclDevice.has_aspect_fp64` |
| 49 | +evaluates to ``True``. |
| 50 | + |
| 51 | +If prerequisites are not met, requests to create an instance of an array object for these types will raise an exception. |
| 52 | + |
| 53 | +Data type objects are instances of :py:class:`dtype` object, and support equality comparison by implementing |
| 54 | +special method :meth:`__eq__`. |
| 55 | + |
| 56 | +.. py:class:: dtype |
| 57 | +
|
| 58 | + Same as :py:class:`numpy.dtype` |
| 59 | + |
| 60 | + .. py:method:: __eq__ |
| 61 | +
|
| 62 | + Check if data-type instances are equal. |
| 63 | + |
| 64 | + |
| 65 | +Default integral data type |
| 66 | +-------------------------- |
| 67 | + |
| 68 | +The default integral data type is :attr:`int64` for all supported devices. |
| 69 | + |
| 70 | +Default indexing data type |
| 71 | +-------------------------- |
| 72 | + |
| 73 | +The default indexing data type is :attr:`int64` for all supported devices. |
| 74 | + |
| 75 | +Default real floating-point data type |
| 76 | +------------------------------------- |
| 77 | + |
| 78 | +The default real floating-point type depends on the capabilities of device where array is allocated. |
| 79 | +If the device support double precision floating-point types, the default real floating-point type |
| 80 | +is :attr:`float64`, otherwise :attr:`float32`. |
| 81 | + |
| 82 | +Make sure to select an appropriately capable device for an application that requires use of double |
| 83 | +precision floating-point type. |
| 84 | + |
| 85 | +Default complex floating-point data type |
| 86 | +---------------------------------------- |
| 87 | + |
| 88 | +Like for the default real floating-point type, the default complex floating-point type depends on |
| 89 | +capabilities of device. If the device support double precision real floating-point types, the default |
| 90 | +complex floating-point type is :attr:`complex128`, otherwise :attr:`complex64`. |
| 91 | + |
| 92 | + |
| 93 | +Querying default data types programmatically |
| 94 | +-------------------------------------------- |
| 95 | + |
| 96 | +The data type can be discovered programmatically using Array API :ref:`inspection functions <dpnp_tensor_inspection>`: |
| 97 | + |
| 98 | +.. code-block:: python |
| 99 | +
|
| 100 | + import dpctl |
| 101 | + from dpnp import tensor |
| 102 | +
|
| 103 | + device = dpctl.select_default_device() |
| 104 | + # get default data types for default-selected device |
| 105 | + default_types = tensor.__array_namespace_info__().default_dtypes(device) |
| 106 | + int_dt = default_types["integral"] |
| 107 | + ind_dt = default_types["indexing"] |
| 108 | + rfp_dt = default_types["real floating"] |
| 109 | + cfp_dt = default_types["complex floating"] |
| 110 | +
|
| 111 | +
|
| 112 | +Type promotion rules |
| 113 | +-------------------- |
| 114 | + |
| 115 | +Type promotion rules govern the behavior of an array library when a function does not have |
| 116 | +a dedicated implementation for the data type(s) of the input array(s). |
| 117 | + |
| 118 | +In such a case, input arrays may be cast to data types for which a dedicated implementation |
| 119 | +exists. For example, when :data:`sin` is applied to array of integral values. |
| 120 | + |
| 121 | +Type promotion rules used in :py:mod:`dpnp.tensor` are consistent with the |
| 122 | +Python Array API specification's `type promotion rules <https://data-apis.org/array-api/latest/API_specification/type_promotion.html>`_ |
| 123 | +for devices that support double precision floating-point type. |
| 124 | + |
| 125 | + |
| 126 | +For devices that do not support double precision floating-point type, the type promotion rule is |
| 127 | +truncated by removing nodes corresponding to unsupported data types and edges that lead to them. |
0 commit comments