ndonnx


Namendonnx JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryONNX backed array library compliant with Array API standard.
upload_time2024-06-15 10:47:52
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords numpy onnx array-api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ndonnx

[![CI](https://img.shields.io/github/actions/workflow/status/quantco/ndonnx/ci.yml?style=flat-square&branch=main)](https://github.com/quantco/ndonnx/actions/workflows/ci.yml)
[![Documentation](https://readthedocs.org/projects/ndonnx/badge/?version=latest)](https://ndonnx.readthedocs.io/en/latest/?badge=latest)
[![conda-forge](https://img.shields.io/conda/pn/conda-forge/ndonnx?style=flat-square&logoColor=white&logo=conda-forge)](https://prefix.dev/channels/conda-forge/packages/ndonnx)

An ONNX-backed array library that is compliant with the [Array API](https://data-apis.org/array-api/) standard.

## Installation

Releases are available on PyPI and conda-forge.

```bash
# 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:

```bash
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`](https://data-apis.org/array-api/) standard. Standard compliant code can be executed without changes across numerous backends such as like `NumPy`, `JAX` and now `ndonnx`.

  ```python
  import numpy.array_api as npx
  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)])

  arr = [-12.12, 1.12, 2.12, 2.13, 123.,]

  np_result = mean_drop_outliers(npx.asarray(arr))
  jax_result = mean_drop_outliers(jxp.asarray(arr))
  ndx_result = mean_drop_outliers(ndx.asarray(arr))
  print(np_result)  # 1.79
  print(jax_result)  # 1.79
  print(ndx_result) # Array(1.79, dtype=ndx.Float64)
  assert np_result == ndx_result.to_numpy()
  ```

- It supports ONNX export. This allows you persist your logic into an ONNX computation graph for convenient and performant inference.

  ```python
  import onnx
  import ndonnx as ndx

  a = ndx.array(shape=("N",), dtype=ndx.float64)
  b = ndx.array(shape=("N",), dtype=ndx.float64)
  out = a[:2] + b[:2]
  model_proto = ndx.build({"a": a, "b": b}, {"c": out})
  onnx.save(model_proto, "model.onnx")

  # Having serialised your model to disk, perform
  # inference using a runtime of your choosing.
  import onnxruntime as ort
  import numpy as np
  inference_session = ort.InferenceSession("model.onnx")
  prediction, = inference_session.run(None, {
      "a": np.array([1, 2, 3], dtype=np.float64),
      "b": np.array([4, 5, 6], dtype=np.float64),
  })
  print(prediction)  # array([5., 7.])
  ```

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 the array-api coverage test suite in `api-coverage-tests`. Missing coverage is tracked in the `skips.txt` file. Contributions are welcome!

Summary(1119 total):

- 898 passed
- 210 failed
- 11 deselected

Run the tests with:

```bash
pixi run arrayapitests
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ndonnx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "numpy, onnx, array-api",
    "author": null,
    "author_email": "Aditya Goel <agoel4512@gmail.com>, Christian Bourjau <christian.bourjau@quantco.com>",
    "download_url": "https://files.pythonhosted.org/packages/ae/c1/a17930859988d84f00ecff210ae703170411976b828766584caf00605755/ndonnx-0.4.0.tar.gz",
    "platform": null,
    "description": "# ndonnx\n\n[![CI](https://img.shields.io/github/actions/workflow/status/quantco/ndonnx/ci.yml?style=flat-square&branch=main)](https://github.com/quantco/ndonnx/actions/workflows/ci.yml)\n[![Documentation](https://readthedocs.org/projects/ndonnx/badge/?version=latest)](https://ndonnx.readthedocs.io/en/latest/?badge=latest)\n[![conda-forge](https://img.shields.io/conda/pn/conda-forge/ndonnx?style=flat-square&logoColor=white&logo=conda-forge)](https://prefix.dev/channels/conda-forge/packages/ndonnx)\n\nAn ONNX-backed array library that is compliant with the [Array API](https://data-apis.org/array-api/) standard.\n\n## Installation\n\nReleases are available on PyPI and conda-forge.\n\n```bash\n# using pip\npip install ndonnx\n# using conda\nconda install ndonnx\n# using pixi\npixi add ndonnx\n```\n\n## Development\n\nYou can install the package in development mode using:\n\n```bash\ngit clone https://github.com/quantco/ndonnx\ncd ndonnx\n\n# For Array API tests\ngit submodule update --init --recursive\n\npixi shell\npre-commit run -a\npip install --no-build-isolation --no-deps -e .\npytest tests -n auto\n```\n\n## Quick start\n\n`ndonnx` is an ONNX based python array library.\n\nIt has a couple of key features:\n\n- It implements the [`Array API`](https://data-apis.org/array-api/) standard. Standard compliant code can be executed without changes across numerous backends such as like `NumPy`, `JAX` and now `ndonnx`.\n\n  ```python\n  import numpy.array_api as npx\n  import ndonnx as ndx\n  from jax.experimental import array_api as jxp\n\n  def mean_drop_outliers(a, low=-5, high=5):\n      xp = a.__array_namespace__()\n      return xp.mean(a[(low < a) & (a < high)])\n\n  arr = [-12.12, 1.12, 2.12, 2.13, 123.,]\n\n  np_result = mean_drop_outliers(npx.asarray(arr))\n  jax_result = mean_drop_outliers(jxp.asarray(arr))\n  ndx_result = mean_drop_outliers(ndx.asarray(arr))\n  print(np_result)  # 1.79\n  print(jax_result)  # 1.79\n  print(ndx_result) # Array(1.79, dtype=ndx.Float64)\n  assert np_result == ndx_result.to_numpy()\n  ```\n\n- It supports ONNX export. This allows you persist your logic into an ONNX computation graph for convenient and performant inference.\n\n  ```python\n  import onnx\n  import ndonnx as ndx\n\n  a = ndx.array(shape=(\"N\",), dtype=ndx.float64)\n  b = ndx.array(shape=(\"N\",), dtype=ndx.float64)\n  out = a[:2] + b[:2]\n  model_proto = ndx.build({\"a\": a, \"b\": b}, {\"c\": out})\n  onnx.save(model_proto, \"model.onnx\")\n\n  # Having serialised your model to disk, perform\n  # inference using a runtime of your choosing.\n  import onnxruntime as ort\n  import numpy as np\n  inference_session = ort.InferenceSession(\"model.onnx\")\n  prediction, = inference_session.run(None, {\n      \"a\": np.array([1, 2, 3], dtype=np.float64),\n      \"b\": np.array([4, 5, 6], dtype=np.float64),\n  })\n  print(prediction)  # array([5., 7.])\n  ```\n\nIn 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.\n\n## Array API coverage\n\nArray API compatibility is tracked in the array-api coverage test suite in `api-coverage-tests`. Missing coverage is tracked in the `skips.txt` file. Contributions are welcome!\n\nSummary(1119 total):\n\n- 898 passed\n- 210 failed\n- 11 deselected\n\nRun the tests with:\n\n```bash\npixi run arrayapitests\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "ONNX backed array library compliant with Array API standard.",
    "version": "0.4.0",
    "project_urls": {
        "repository": "https://github.com/quantco/ndonnx"
    },
    "split_keywords": [
        "numpy",
        " onnx",
        " array-api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "74d357db06038f0195065b2dbc014ee06342cb6814f0962797e5527e8c6c67f0",
                "md5": "08ec8547ee74e3f4890bb751164b2a06",
                "sha256": "03e45e2e2e6e4cad28b2130c7d6d9f8e1cac46c6c216554e8c2537e7bb96d4b9"
            },
            "downloads": -1,
            "filename": "ndonnx-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "08ec8547ee74e3f4890bb751164b2a06",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 45584,
            "upload_time": "2024-06-15T10:47:50",
            "upload_time_iso_8601": "2024-06-15T10:47:50.324975Z",
            "url": "https://files.pythonhosted.org/packages/74/d3/57db06038f0195065b2dbc014ee06342cb6814f0962797e5527e8c6c67f0/ndonnx-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aec1a17930859988d84f00ecff210ae703170411976b828766584caf00605755",
                "md5": "d8a553ff333174b0ba80aea8be976c78",
                "sha256": "5bbc7298d4afd209d324bf313704be42a06e90d6f42880cfe321cdf520870cce"
            },
            "downloads": -1,
            "filename": "ndonnx-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d8a553ff333174b0ba80aea8be976c78",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 293828,
            "upload_time": "2024-06-15T10:47:52",
            "upload_time_iso_8601": "2024-06-15T10:47:52.944208Z",
            "url": "https://files.pythonhosted.org/packages/ae/c1/a17930859988d84f00ecff210ae703170411976b828766584caf00605755/ndonnx-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-15 10:47:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "quantco",
    "github_project": "ndonnx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ndonnx"
}
        
Elapsed time: 0.28519s