|
2 | 2 |
|
3 | 3 | [](https://github.com/quantco/ndonnx/actions/workflows/ci.yml)
|
4 | 4 | [](https://ndonnx.readthedocs.io/en/latest/?badge=latest)
|
5 |
| -[](https://prefix.dev/channels/conda-forge/packages/ndonnx) |
| 5 | +[](https://anaconda.org/conda-forge/ndonnx) |
| 6 | +[](https://pypi.org/project/ndonnx) |
6 | 7 |
|
7 | 8 | An ONNX-backed array library that is compliant with the [Array API](https://data-apis.org/array-api/) standard.
|
8 | 9 |
|
@@ -53,46 +54,45 @@ It has a couple of key features:
|
53 | 54 | xp = a.__array_namespace__()
|
54 | 55 | return xp.mean(a[(low < a) & (a < high)])
|
55 | 56 |
|
56 |
| - arr = [-12.12, 1.12, 2.12, 2.13, 123.,] |
| 57 | + np_result = mean_drop_outliers(npx.asarray([-10, 0.5, 1, 5])) |
| 58 | + jax_result = mean_drop_outliers(jxp.asarray([-10, 0.5, 1, 5])) |
| 59 | + onnx_result = mean_drop_outliers(ndx.asarray([-10, 0.5, 1, 5])) |
57 | 60 |
|
58 |
| - np_result = mean_drop_outliers(npx.asarray(arr)) |
59 |
| - jax_result = mean_drop_outliers(jxp.asarray(arr)) |
60 |
| - ndx_result = mean_drop_outliers(ndx.asarray(arr)) |
61 |
| - print(np_result) # 1.79 |
62 |
| - print(jax_result) # 1.79 |
63 |
| - print(ndx_result) # Array(1.79, dtype=ndx.Float64) |
64 |
| - assert np_result == ndx_result.to_numpy() |
| 61 | + assert np_result == onnx_result.to_numpy() == jax_result == 0.75 |
65 | 62 | ```
|
66 | 63 |
|
67 |
| -- It supports ONNX export. This allows you persist your logic into an ONNX computation graph for convenient and performant inference. |
| 64 | +- It supports ONNX export. This allows you persist your logic into an ONNX computation graph. |
68 | 65 |
|
69 | 66 | ```python
|
70 |
| - import onnx |
71 | 67 | import ndonnx as ndx
|
| 68 | + import onnx |
| 69 | + |
| 70 | + # Instantiate placeholder ndonnx array |
| 71 | + x = ndx.array(shape=("N",), dtype=ndx.float32) |
| 72 | + y = mean_drop_outliers(x) |
72 | 73 |
|
73 |
| - a = ndx.array(shape=("N",), dtype=ndx.float64) |
74 |
| - b = ndx.array(shape=("N",), dtype=ndx.float64) |
75 |
| - out = a[:2] + b[:2] |
76 |
| - model_proto = ndx.build({"a": a, "b": b}, {"c": out}) |
77 |
| - onnx.save(model_proto, "model.onnx") |
| 74 | + # Build and save ONNX model to disk |
| 75 | + model = ndx.build({"x": x}, {"y": y}) |
| 76 | + onnx.save(model, "mean_drop_outliers.onnx") |
| 77 | + ``` |
| 78 | + |
| 79 | + You can then make predictions using a runtime of your choice. |
78 | 80 |
|
79 |
| - # Having serialised your model to disk, perform |
80 |
| - # inference using a runtime of your choosing. |
| 81 | + ```python |
81 | 82 | import onnxruntime as ort
|
82 | 83 | import numpy as np
|
83 |
| - inference_session = ort.InferenceSession("model.onnx") |
| 84 | + inference_session = ort.InferenceSession("mean_drop_outliers.onnx") |
84 | 85 | prediction, = inference_session.run(None, {
|
85 |
| - "a": np.array([1, 2, 3], dtype=np.float64), |
86 |
| - "b": np.array([4, 5, 6], dtype=np.float64), |
| 86 | + "x": np.array([-10, 0.5, 1, 5], dtype=np.float32), |
87 | 87 | })
|
88 |
| - print(prediction) # array([5., 7.]) |
| 88 | + assert prediction == 0.75 |
89 | 89 | ```
|
90 | 90 |
|
91 | 91 | 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.
|
92 | 92 |
|
93 | 93 | ## Array API coverage
|
94 | 94 |
|
95 |
| -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! |
| 95 | +Array API compatibility is tracked in `api-coverage-tests`. Missing coverage is tracked in the `skips.txt` file. Contributions are welcome! |
96 | 96 |
|
97 | 97 | Summary(1119 total):
|
98 | 98 |
|
|
0 commit comments