Array API Strict

raw JSON →
2.5 verified Mon Apr 27 auth: no python

A strict, minimal implementation of the Python array API standard (version 2.5). Provides a reference implementation for the standard, enforcing the specification strictly. Has a maintenance release cadence with major updates approximately yearly.

pip install array-api-strict
error AttributeError: module 'array_api_strict' has no attribute 'array'
cause array_api_strict does not export a function called 'array'; use 'asarray' instead.
fix
Replace xp.array(...) with xp.asarray(...).
error ValueError: Data type casting violation
cause Mixed dtype operation that violates strict casting rules.
fix
Explicitly convert inputs to the same dtype: xp.asarray(a, dtype=xp.float64) + b.
error AttributeError: module 'array_api_strict' has no attribute 'linalg'
cause Linear algebra submodule is not in top-level namespace; must be imported.
fix
Add 'from array_api_strict.linalg import ...' before using linalg functions.
breaking Version 2.0 removed many previously included functions that are not part of the official array API standard (e.g., trigonometric functions from the 'math' extension). Use a full array library like NumPy for those.
fix Migrate to NumPy or another array library for non-standard functions.
breaking array-api-strict enforces strict data type promotion rules. Mixed type operations (e.g., int32 + float64) may raise errors instead of promoting.
fix Ensure inputs have the same dtype or convert explicitly using xp.asarray(..., dtype=xp.float64).
deprecated The 'finfo' function returned 'numpy.finfo' objects in older versions; now returns array API 'finfo' objects. Access methods like 'eps' via attribute, not key.
fix Use finfo_obj.eps instead of finfo_obj['eps'].
gotcha Indexing semantics differ from NumPy: array_api_strict does not support advanced indexing that results in a copy vs view ambiguity. All indexing returns a copy (no views).
fix Do not rely on views; assign modified copies back to the original array if needed.

Create two 1-D arrays and compute their dot product using the array API standard functions.

import array_api_strict as xp

def main():
    a = xp.asarray([1, 2, 3])
    b = xp.asarray([4, 5, 6])
    c = xp.dot(a, b)
    print(c)

if __name__ == '__main__':
    main()