Skip to main content

ndonnx

CI Documentation conda-forge pypi

An ONNX-backed array library that is compliant with the Array API standard.

Installation

Releases are available on PyPI and conda-forge.

# using pip
pip install ndonnx
# using conda
conda install ndonnx
# using pixi
pixi add ndonnx

Development

You can install the package in development mode using:

git clone https://github.com/quantco/ndonnx
cd ndonnx

# For Array API tests
git submodule update --init --recursive

pixi shell
pre-commit run -a
pip install --no-build-isolation --no-deps -e .
pytest tests -n auto

Quick start

ndonnx is an ONNX based python array library.

It has a couple of key features:

  • It implements the Array API standard. Standard compliant code can be executed without changes across numerous backends such as like NumPy, JAX and now ndonnx.

    import numpy as np
    import ndonnx as ndx
    import jax.numpy as jnp
    
    def mean_drop_outliers(a, low=-5, high=5):
        xp = a.__array_namespace__()
        return xp.mean(a[(low < a) & (a < high)])
    
    np_result = mean_drop_outliers(np.asarray([-10, 0.5, 1, 5]))
    jax_result = mean_drop_outliers(jnp.asarray([-10, 0.5, 1, 5]))
    onnx_result = mean_drop_outliers(ndx.asarray([-10, 0.5, 1, 5]))
    
    assert np_result == onnx_result.unwrap_numpy() == jax_result == 0.75
    
  • It supports ONNX export. This allows you persist your logic into an ONNX computation graph.

    import ndonnx as ndx
    import onnx
    
    # Instantiate placeholder ndonnx array
    x = ndx.array(shape=("N",), dtype=ndx.float32)
    y = mean_drop_outliers(x)
    
    # Build and save ONNX model to disk
    model = ndx.build({"x": x}, {"y": y})
    onnx.save(model, "mean_drop_outliers.onnx")
    

    You can then make predictions using a runtime of your choice.

    import onnxruntime as ort
    import numpy as np
    
    inference_session = ort.InferenceSession("mean_drop_outliers.onnx")
    prediction, = inference_session.run(None, {
        "x": np.array([-10, 0.5, 1, 5], dtype=np.float32),
    })
    assert prediction == 0.75
    

In the future we will be enabling a stable API for an extensible data type system. This will allow users to define their own data types and operations on arrays with these data types.

Array API coverage

Array API compatibility tested against the official array-api-tests suite. Missing coverage is tracked in the skips.txt file. Contributions are welcome!

Run the tests with:

pixi run arrayapitests

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndonnx-0.21.0.tar.gz (353.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ndonnx-0.21.0-py3-none-any.whl (83.8 kB view details)

Uploaded Python 3

File details

Details for the file ndonnx-0.21.0.tar.gz.

File metadata

  • Download URL: ndonnx-0.21.0.tar.gz
  • Upload date:
  • Size: 353.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ndonnx-0.21.0.tar.gz
Algorithm Hash digest
SHA256 4a188b7732dd192d38d8a0cb5c6721e2a6abb9393046528529c5b7c97055eede
MD5 8ee564cc8c85d0ba61bf10aa108e2d46
BLAKE2b-256 167c495a0f56471f6cd6687a261e89a8c83497b5d35b90808a68c8104a039e1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndonnx-0.21.0.tar.gz:

Publisher: build.yml on Quantco/ndonnx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ndonnx-0.21.0-py3-none-any.whl.

File metadata

  • Download URL: ndonnx-0.21.0-py3-none-any.whl
  • Upload date:
  • Size: 83.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ndonnx-0.21.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d49c7adacb456fc0187cd8f8bc38c2e4c629649730f5df195acfd7cce1ef424
MD5 f17faafb200b546ddf0dbd18028d2004
BLAKE2b-256 f267fcc14201a4154d39085ad51dd47eafb765aac5a58dbfb7274172d7d9ce02

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndonnx-0.21.0-py3-none-any.whl:

Publisher: build.yml on Quantco/ndonnx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page