Skip to content

Add pytato.array_api: Python Array API conformance namespace + test infrastructure#663

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/test-pytato-against-python-api-standard
Draft

Add pytato.array_api: Python Array API conformance namespace + test infrastructure#663
Copilot wants to merge 3 commits into
mainfrom
copilot/test-pytato-against-python-api-standard

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

Implements the Array API 2023.12-compatible namespace (pytato.array_api) and wires up the array-api-tests conformance suite against it.

How it works

Each operation in pytato.array_api wraps inputs in pytato DataWrapper nodes, builds the pytato expression graph, then immediately evaluates via the new NumpyPythonTarget — exercising pytato's full codegen pipeline while returning concrete numpy results the conformance tests can inspect.

import pytato.array_api as xp

x = xp.asarray([1.0, 2.0, 3.0])
y = xp.sum(x)            # builds pt.sum() graph, evaluates via numpy codegen
z = xp.matmul(xp.ones((2, 3)), xp.ones((3, 2)))  # pt.matmul → numpy

Changes

  • pytato/array_api.py — new module implementing the full Array API 2023.12 surface: creation, element-wise, reductions, manipulation, searching/sorting, set functions, linear algebra, indexing, __array_namespace_info__, etc.
  • pytato/target/python/__init__.py — adds NumpyPythonTarget, a concrete NumpyLikePythonTarget subclass that generates code targeting numpy (used by array_api.py for eager evaluation).
  • pytato/target/python/numpy_like.py — fixes ProductReductionOperation codegen mapping from removed numpy.productnumpy.prod (NumPy 2.0 compatibility bug).
  • .github/workflows/array_api.yml — CI job that clones array-api-tests at HEAD and runs the conformance suite against pytato.array_api.
  • array-api-tests.xfails.txt — expected failures: missing optional extensions (linalg, fft) and scalar weak-typing differences (Python int scalar + integer array dtype promotion deviates from Array API spec).

Current conformance status

With --max-examples=50: 452 pass, 37 fail (all failures are the unimplemented linalg/fft optional extensions listed in xfails.txt), 97 skipped.

Copilot AI linked an issue May 8, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add script to test Pytato against Python API standard Add pytato.array_api: Python Array API conformance namespace + test infrastructure May 8, 2026
Copilot AI requested a review from inducer May 8, 2026 15:14
Copilot finished work on behalf of inducer May 8, 2026 15:14
PYTATO_REDUCTION_TO_NP_REDUCTION: Mapping[type[ReductionOperation], str] = {
SumReductionOperation: "sum",
ProductReductionOperation: "product",
ProductReductionOperation: "prod",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inducer This should probably make it to main first, since np.product no longer exists 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test pytato against the Python API standard

3 participants