Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Supports function full for the Array API#21

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

Merged
sdpython merged 5 commits intomainfromfull
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix keys by adding types
  • Loading branch information
@xadupre
xadupre committedJun 18, 2023
commit870ba4b8990f6f73730ebfc7d15eb27c717f9b51
2 changes: 1 addition & 1 deletion_unittests/test_array_api.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
export ARRAY_API_TESTS_MODULE=onnx_array_api.array_api.onnx_numpy
pytest ../array-api-tests/array_api_tests/test_creation_functions.py::test_full || exit 1
pytest ../array-api-tests/array_api_tests/test_creation_functions.py::test_ones || exit 1
# pytest ../array-api-tests/array_api_tests/test_creation_functions.py --help
pytest ../array-api-tests/array_api_tests/test_creation_functions.py --hypothesis-explain --skips-file=_unittests/onnx-numpy-skips.txt || exit 1
18 changes: 17 additions & 1 deletion_unittests/ut_array_api/test_onnx_numpy.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,22 @@ def test_zeros(self):
a = xp.absolute(mat)
self.assertEqualArray(np.absolute(mat.numpy()), a.numpy())

def test_zeros_none(self):
c = EagerTensor(np.array([4, 5], dtype=np.int64))
mat = xp.zeros(c)
matnp = mat.numpy()
self.assertEqual(matnp.shape, (4, 5))
self.assertNotEmpty(matnp[0, 0])
self.assertEqualArray(matnp, np.zeros((4, 5)))

def test_ones_none(self):
c = EagerTensor(np.array([4, 5], dtype=np.int64))
mat = xp.ones(c)
matnp = mat.numpy()
self.assertEqual(matnp.shape, (4, 5))
self.assertNotEmpty(matnp[0, 0])
self.assertEqualArray(matnp, np.ones((4, 5)))

def test_full(self):
c = EagerTensor(np.array([4, 5], dtype=np.int64))
mat = xp.full(c, fill_value=5, dtype=xp.int64)
Expand All@@ -38,5 +54,5 @@ def test_full_bool(self):


if __name__ == "__main__":
TestOnnxNumpy().test_full_bool()
TestOnnxNumpy().test_zeros_none()
unittest.main(verbosity=2)
5 changes: 3 additions & 2 deletions_unittests/ut_npx/test_npx.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -710,8 +710,8 @@ def impl(
keys = list(sorted(f.onxs))
self.assertIsInstance(f.onxs[keys[0]], ModelProto)
k = keys[-1]
self.assertEqual(len(k),3)
self.assertEqual(k[1:], ("axis", 0))
self.assertEqual(len(k),4)
self.assertEqual(k[1:], ("axis",int,0))

def test_numpy_topk(self):
f = topk(Input("X"), Input("K"))
Expand DownExpand Up@@ -2416,6 +2416,7 @@ def compute_labels(X, centers, use_sqrt=False):
(DType(TensorProto.DOUBLE), 2),
(DType(TensorProto.DOUBLE), 2),
"use_sqrt",
bool,
True,
)
self.assertEqual(f.available_versions, [key])
Expand Down
2 changes: 1 addition & 1 deletiononnx_array_api/_helpers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ def np_dtype_to_tensor_dtype(dtype: Any):
elif dtype is int:
dt = TensorProto.INT64
elif dtype is float:
dt = TensorProto.FLOAT64
dt = TensorProto.DOUBLE
else:
raise KeyError(f"Unable to guess type for dtype={dtype}.")
return dt
7 changes: 3 additions & 4 deletionsonnx_array_api/array_api/onnx_numpy.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
"""
from typing import Any, Optional
import numpy as np
from onnx import TensorProto
from ..npx.npx_functions import (
all,
abs,
Expand DownExpand Up@@ -60,7 +59,7 @@ def asarray(

def ones(
shape: TensorType[ElemType.int64, "I", (None,)],
dtype: OptParType[DType] =DType(TensorProto.FLOAT),
dtype: OptParType[DType] =None,
order: OptParType[str] = "C",
) -> TensorType[ElemType.numerics, "T"]:
if isinstance(shape, tuple):
Expand All@@ -78,7 +77,7 @@ def ones(

def empty(
shape: TensorType[ElemType.int64, "I", (None,)],
dtype: OptParType[DType] =DType(TensorProto.FLOAT),
dtype: OptParType[DType] =None,
order: OptParType[str] = "C",
) -> TensorType[ElemType.numerics, "T"]:
raise RuntimeError(
Expand All@@ -89,7 +88,7 @@ def empty(

def zeros(
shape: TensorType[ElemType.int64, "I", (None,)],
dtype: OptParType[DType] =DType(TensorProto.FLOAT),
dtype: OptParType[DType] =None,
order: OptParType[str] = "C",
) -> TensorType[ElemType.numerics, "T"]:
if isinstance(shape, tuple):
Expand Down
8 changes: 4 additions & 4 deletionsonnx_array_api/npx/npx_functions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -501,7 +501,7 @@ def matmul(
@npxapi_inline
def ones(
shape: TensorType[ElemType.int64, "I", (None,)],
dtype: OptParType[DType] =DType(TensorProto.FLOAT),
dtype: OptParType[DType] =None,
order: OptParType[str] = "C",
) -> TensorType[ElemType.numerics, "T"]:
"""
Expand All@@ -510,7 +510,7 @@ def ones(
if order != "C":
raise RuntimeError(f"order={order!r} != 'C' not supported.")
if dtype is None:
dtype = DType(TensorProto.FLOAT)
dtype = DType(TensorProto.DOUBLE)
return var(
shape,
value=make_tensor(name="one", data_type=dtype.code, dims=[1], vals=[1]),
Expand DownExpand Up@@ -711,7 +711,7 @@ def where(
@npxapi_inline
def zeros(
shape: TensorType[ElemType.int64, "I", (None,)],
dtype: OptParType[DType] =DType(TensorProto.FLOAT),
dtype: OptParType[DType] =None,
order: OptParType[str] = "C",
) -> TensorType[ElemType.numerics, "T"]:
"""
Expand All@@ -720,7 +720,7 @@ def zeros(
if order != "C":
raise RuntimeError(f"order={order!r} != 'C' not supported.")
if dtype is None:
dtype = DType(TensorProto.FLOAT)
dtype = DType(TensorProto.DOUBLE)
return var(
shape,
value=make_tensor(name="zero", data_type=dtype.code, dims=[1], vals=[0]),
Expand Down
4 changes: 3 additions & 1 deletiononnx_array_api/npx/npx_jit_eager.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,6 +132,7 @@ def make_key(*values, **kwargs):
if isinstance(v, (Var, EagerTensor, JitTensor)):
res.append(v.key)
elif isinstance(v, (int, float, bool, DType)):
res.append(type(v))
res.append(v)
elif isinstance(v, slice):
res.append(("slice", v.start, v.stop, v.step))
Expand DownExpand Up@@ -170,7 +171,8 @@ def make_key(*values, **kwargs):
newv.append(t)
res.append(tuple(newv))
elif v is None and k in {"dtype"}:
continue
res.append(k)
res.append(v)
else:
raise TypeError(
f"Type {type(v)} is not yet supported, "
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp