- Notifications
You must be signed in to change notification settings - Fork0
Extends Array API to EagerOrt#18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
2749bf1
Extends Array API to EagerOrt
xadupre0e73dda
fix empty shape
xadupre62b8220
fix shape
xadupre2d26568
fix azure
xadupre857e3b0
refactoring
xadupre6b949cb
fix command line
xadupre10d438e
CI
xadupre0d0e927
fix CI
xadupre73585c5
fix CI
xadupreFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,6 +8,7 @@ _cache/* | ||
dist/* | ||
build/* | ||
.eggs/* | ||
.hypothesis/* | ||
*egg-info/* | ||
_doc/auto_examples/* | ||
_doc/examples/_cache/* | ||
13 changes: 13 additions & 0 deletions_unittests/onnx-numpy-skips.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# API failures | ||
array_api_tests/test_creation_functions.py::test_arange | ||
array_api_tests/test_creation_functions.py::test_asarray_scalars | ||
array_api_tests/test_creation_functions.py::test_asarray_arrays | ||
array_api_tests/test_creation_functions.py::test_empty | ||
array_api_tests/test_creation_functions.py::test_empty_like | ||
array_api_tests/test_creation_functions.py::test_eye | ||
array_api_tests/test_creation_functions.py::test_full | ||
array_api_tests/test_creation_functions.py::test_full_like | ||
array_api_tests/test_creation_functions.py::test_linspace | ||
array_api_tests/test_creation_functions.py::test_meshgrid | ||
array_api_tests/test_creation_functions.py::test_ones_like | ||
array_api_tests/test_creation_functions.py::test_zeros_like |
15 changes: 15 additions & 0 deletions_unittests/onnx-ort-skips.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Not implementated by onnxruntime | ||
array_api_tests/test_creation_functions.py::test_arange | ||
array_api_tests/test_creation_functions.py::test_asarray_scalars | ||
array_api_tests/test_creation_functions.py::test_asarray_arrays | ||
array_api_tests/test_creation_functions.py::test_empty | ||
array_api_tests/test_creation_functions.py::test_empty_like | ||
array_api_tests/test_creation_functions.py::test_eye | ||
array_api_tests/test_creation_functions.py::test_full | ||
array_api_tests/test_creation_functions.py::test_full_like | ||
array_api_tests/test_creation_functions.py::test_linspace | ||
array_api_tests/test_creation_functions.py::test_meshgrid | ||
array_api_tests/test_creation_functions.py::test_ones | ||
array_api_tests/test_creation_functions.py::test_ones_like | ||
array_api_tests/test_creation_functions.py::test_zeros | ||
array_api_tests/test_creation_functions.py::test_zeros_like |
112 changes: 112 additions & 0 deletions_unittests/ut_array_api/test_array_apis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import unittest | ||
from inspect import isfunction, ismethod | ||
import numpy as np | ||
from onnx_array_api.ext_test_case import ExtTestCase | ||
from onnx_array_api.array_api import onnx_numpy as xpn | ||
from onnx_array_api.array_api import onnx_ort as xpo | ||
# from onnx_array_api.npx.npx_numpy_tensors import EagerNumpyTensor | ||
# from onnx_array_api.ort.ort_tensors import EagerOrtTensor | ||
class TestArraysApis(ExtTestCase): | ||
def test_zeros_numpy_1(self): | ||
c = xpn.zeros(1) | ||
d = c.numpy() | ||
self.assertEqualArray(np.array([0], dtype=np.float32), d) | ||
def test_zeros_ort_1(self): | ||
c = xpo.zeros(1) | ||
d = c.numpy() | ||
self.assertEqualArray(np.array([0], dtype=np.float32), d) | ||
def test_ffinfo(self): | ||
dt = np.float32 | ||
fi1 = np.finfo(dt) | ||
fi2 = xpn.finfo(dt) | ||
fi3 = xpo.finfo(dt) | ||
dt1 = fi1.dtype | ||
dt2 = fi2.dtype | ||
dt3 = fi3.dtype | ||
self.assertEqual(dt2, dt3) | ||
self.assertNotEqual(dt1.__class__, dt2.__class__) | ||
mi1 = fi1.min | ||
mi2 = fi2.min | ||
self.assertEqual(mi1, mi2) | ||
mi1 = fi1.smallest_normal | ||
mi2 = fi2.smallest_normal | ||
self.assertEqual(mi1, mi2) | ||
for n in dir(fi1): | ||
if n.startswith("__"): | ||
continue | ||
if n in {"machar"}: | ||
continue | ||
v1 = getattr(fi1, n) | ||
with self.subTest(att=n): | ||
v2 = getattr(fi2, n) | ||
v3 = getattr(fi3, n) | ||
if isfunction(v1) or ismethod(v1): | ||
try: | ||
v1 = v1() | ||
except TypeError: | ||
continue | ||
v2 = v2() | ||
v3 = v3() | ||
if v1 != v2: | ||
raise AssertionError( | ||
f"12: info disagree on name {n!r}: {v1} != {v2}, " | ||
f"type(v1)={type(v1)}, type(v2)={type(v2)}, " | ||
f"ismethod={ismethod(v1)}." | ||
) | ||
if v2 != v3: | ||
raise AssertionError( | ||
f"23: info disagree on name {n!r}: {v2} != {v3}, " | ||
f"type(v1)={type(v1)}, type(v2)={type(v2)}, " | ||
f"ismethod={ismethod(v1)}." | ||
) | ||
def test_iiinfo(self): | ||
dt = np.int64 | ||
fi1 = np.iinfo(dt) | ||
fi2 = xpn.iinfo(dt) | ||
fi3 = xpo.iinfo(dt) | ||
dt1 = fi1.dtype | ||
dt2 = fi2.dtype | ||
dt3 = fi3.dtype | ||
self.assertEqual(dt2, dt3) | ||
self.assertNotEqual(dt1.__class__, dt2.__class__) | ||
mi1 = fi1.min | ||
mi2 = fi2.min | ||
self.assertEqual(mi1, mi2) | ||
for n in dir(fi1): | ||
if n.startswith("__"): | ||
continue | ||
if n in {"machar"}: | ||
continue | ||
v1 = getattr(fi1, n) | ||
with self.subTest(att=n): | ||
v2 = getattr(fi2, n) | ||
v3 = getattr(fi3, n) | ||
if isfunction(v1) or ismethod(v1): | ||
try: | ||
v1 = v1() | ||
except TypeError: | ||
continue | ||
v2 = v2() | ||
v3 = v3() | ||
if v1 != v2: | ||
raise AssertionError( | ||
f"12: info disagree on name {n!r}: {v1} != {v2}, " | ||
f"type(v1)={type(v1)}, type(v2)={type(v2)}, " | ||
f"ismethod={ismethod(v1)}." | ||
) | ||
if v2 != v3: | ||
raise AssertionError( | ||
f"23: info disagree on name {n!r}: {v2} != {v3}, " | ||
f"type(v1)={type(v1)}, type(v2)={type(v2)}, " | ||
f"ismethod={ismethod(v1)}." | ||
) | ||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
4 changes: 2 additions & 2 deletions_unittests/ut_array_api/test_onnx_numpy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions_unittests/ut_array_api/test_onnx_ort.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import unittest | ||
import numpy as np | ||
from onnx_array_api.ext_test_case import ExtTestCase | ||
from onnx_array_api.array_api import onnx_ort as xp | ||
from onnx_array_api.ort.ort_tensors import EagerOrtTensor as EagerTensor | ||
class TestOnnxOrt(ExtTestCase): | ||
def test_abs(self): | ||
c = EagerTensor(np.array([4, 5], dtype=np.int64)) | ||
mat = xp.zeros(c, dtype=xp.int64) | ||
matnp = mat.numpy() | ||
self.assertEqual(matnp.shape, (4, 5)) | ||
self.assertNotEmpty(matnp[0, 0]) | ||
a = xp.absolute(mat) | ||
self.assertEqualArray(np.absolute(mat.numpy()), a.numpy()) | ||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
48 changes: 45 additions & 3 deletions_unittests/ut_ort/test_ort_tensor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletionsazure-pipelines.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletionsonnx_array_api/_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
from typing import Any | ||
from onnx import helper, TensorProto | ||
def np_dtype_to_tensor_dtype(dtype: Any): | ||
""" | ||
Improves :func:`onnx.helper.np_dtype_to_tensor_dtype`. | ||
""" | ||
try: | ||
dt = helper.np_dtype_to_tensor_dtype(dtype) | ||
except KeyError: | ||
if dtype == np.float32: | ||
dt = TensorProto.FLOAT | ||
elif dtype == np.float64: | ||
dt = TensorProto.DOUBLE | ||
elif dtype == np.int64: | ||
dt = TensorProto.INT64 | ||
elif dtype == np.int32: | ||
dt = TensorProto.INT32 | ||
elif dtype == np.int16: | ||
dt = TensorProto.INT16 | ||
elif dtype == np.int8: | ||
dt = TensorProto.INT8 | ||
elif dtype == np.uint64: | ||
dt = TensorProto.UINT64 | ||
elif dtype == np.uint32: | ||
dt = TensorProto.UINT32 | ||
elif dtype == np.uint16: | ||
dt = TensorProto.UINT16 | ||
elif dtype == np.uint8: | ||
dt = TensorProto.UINT8 | ||
elif dtype == np.float16: | ||
dt = TensorProto.FLOAT16 | ||
elif dtype in (bool, np.bool_): | ||
dt = TensorProto.BOOL | ||
elif dtype in (str, np.str_): | ||
dt = TensorProto.STRING | ||
elif dtype is int: | ||
dt = TensorProto.INT64 | ||
elif dtype is float: | ||
dt = TensorProto.FLOAT64 | ||
else: | ||
raise KeyError(f"Unable to guess type for dtype={dtype}.") | ||
return dt |
36 changes: 36 additions & 0 deletionsonnx_array_api/array_api/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.