Skip to content

Commit

Permalink
Switch to readthedocs (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagoel4512 committed Jun 15, 2024
1 parent bd94b71 commit af5ad37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
build:
os: "ubuntu-22.04"
commands:
- curl -fsSL https://pixi.sh/install.sh | bash
- chmod +x ~/.pixi/bin/pixi
- ~/.pixi/bin/pixi run -e docs postinstall
- ~/.pixi/bin/pixi run -e docs docs
- mkdir -p $READTHEDOCS_OUTPUT/html/
- cp -r docs/_build/html/** $READTHEDOCS_OUTPUT/html/
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![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)
[![conda-forge](https://img.shields.io/conda/vn/conda-forge/ndonnx?style=flat-square&logoColor=white&logo=conda-forge)](https://anaconda.org/conda-forge/ndonnx)
[![pypi](https://img.shields.io/pypi/v/ndonnx.svg?logo=pypi&logoColor=white)](https://pypi.org/project/ndonnx)

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

Expand Down Expand Up @@ -53,46 +54,45 @@ It has a couple of key features:
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([-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]))

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()
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 for convenient and performant inference.
- It supports ONNX export. This allows you persist your logic into an ONNX computation graph.

```python
import onnx
import ndonnx as ndx
import onnx

# Instantiate placeholder ndonnx array
x = ndx.array(shape=("N",), dtype=ndx.float32)
y = mean_drop_outliers(x)

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")
# 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.

# Having serialised your model to disk, perform
# inference using a runtime of your choosing.
```python
import onnxruntime as ort
import numpy as np
inference_session = ort.InferenceSession("model.onnx")
inference_session = ort.InferenceSession("mean_drop_outliers.onnx")
prediction, = inference_session.run(None, {
"a": np.array([1, 2, 3], dtype=np.float64),
"b": np.array([4, 5, 6], dtype=np.float64),
"x": np.array([-10, 0.5, 1, 5], dtype=np.float32),
})
print(prediction) # array([5., 7.])
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 the array-api coverage test suite in `api-coverage-tests`. Missing coverage is tracked in the `skips.txt` file. Contributions are welcome!
Array API compatibility is tracked in `api-coverage-tests`. Missing coverage is tracked in the `skips.txt` file. Contributions are welcome!

Summary(1119 total):

Expand Down

0 comments on commit af5ad37

Please sign in to comment.