Skip to main content

ONNX backed array library compliant with Array API standard.

Project description

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
    from jax.experimental import array_api as jxp
    
    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(jxp.asarray([-10, 0.5, 1, 5]))
    onnx_result = mean_drop_outliers(ndx.asarray([-10, 0.5, 1, 5]))
    
    assert np_result == onnx_result.to_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 is tracked in api-coverage-tests. Missing coverage is tracked in the skips.txt file. Contributions are welcome!

Summary(1119 total):

  • 961 passed
  • 107 failed
  • 51 deselected

Run the tests with:

pixi run arrayapitests

Project details


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.9.0.tar.gz (309.5 kB view details)

Uploaded Source

Built Distribution

ndonnx-0.9.0-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ndonnx-0.9.0.tar.gz
  • Upload date:
  • Size: 309.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for ndonnx-0.9.0.tar.gz
Algorithm Hash digest
SHA256 b30abda255a10ed5d98deac82dfe37f41c05155164394f0ea9861f87961f5212
MD5 d8eb5a26f06de4f64ad85276b0780122
BLAKE2b-256 b70addd379bfe0e46543fbf7e3987394f1d491169532407c8dbc05a1828868bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ndonnx-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 54.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for ndonnx-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcedf7949b40061b6ddaddf4eb1fd8275e42602f373a41ffdae9f040d2e27a14
MD5 d9aca915e0fba2dd5d76b79dfc83e725
BLAKE2b-256 a3860d0e12583cd721cece727ad26b9cdf846fd02006269da735af46d0df1d0a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page