Third-party array libraries¶
APyTypes can interoperate with several third-party array libraries. These can be used as input to APyTypes functions. APyTypes arrays can be converted to these formats and comparisons can generate results in these formats.
It is required to install these third-party libraries separately if you want to use them.
The following third-party array libraries are supported
NumPy
PyTorch
TensorFlow
JAX
CuPy
These are represented by the enumeration ThirdPartyArrayLibrary.
- class apytypes.ThirdPartyArrayLibrary(*values)¶
- NUMPY = 0¶
Use NumPy.
- PYTORCH = 1¶
Use PyTorch.
- TENSORFLOW = 2¶
Use TensorFlow.
- JAX = 3¶
Use JAX.
- CUPY = 4¶
Use CuPy.
To choose which third-party library to use for output arrays, the following functions are provided
- apytypes.set_array_library(array_lib: ThirdPartyArrayLibrary) None¶
- apytypes.set_array_library(arg: str, /) None
Overloaded function.
set_array_library(array_lib: ThirdPartyArrayLibrary) -> Noneset_array_library(arg: str, /) -> NoneSet the preferred third-party array library returned when nothing else is specified.
The preferred third-party array library is used only when APyTypes needs to return a non-APyTypes array, and when no third-party array library is specified explicitly. For example, when two APyTypes’ arrays are compared against one another, the resulting array of bool will have the type specified by this function.
The preferred third-party array library is a global state. When loading in the APyTypes module, it is set to
ThirdPartyArrayLibrary.NUMPY.
- Parameters:
- array_lib{ “numpy”, “pytorch”, “tensorflow”, “jax”, “cupy” } or
ThirdPartyArrayLibrary Preferred third-party array library to use.
- array_lib{ “numpy”, “pytorch”, “tensorflow”, “jax”, “cupy” } or
- apytypes.get_array_library() ThirdPartyArrayLibrary¶
Return the preferred third-party array library in use with APyTypes.
- Returns:
ThirdPartyArrayLibraryThe preferred third-party array library in use.
See also