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

Fixes asarray for the Array API#25

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 2 commits intomainfromhypo
Jun 30, 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
NextNext commit
Fixes asarray for the Array API
  • Loading branch information
@xadupre
xadupre committedJun 29, 2023
commita8f3905269caf83bb2531941703f34582e8e8d2d
20 changes: 20 additions & 0 deletions_unittests/ut_array_api/test_hypothesis_array_api.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
import warnings
from os import getenv
from functools import reduce
import numpy as np
from operator import mul
from hypothesis import given
from onnx_array_api.ext_test_case import ExtTestCase
Expand DownExpand Up@@ -94,6 +95,25 @@ def test_scalar_strategies(self):
kw=array_api_kwargs(dtype=strategies.none() | self.xps.scalar_dtypes()),
)
def fct(x, kw):
asa = np.asarray(x)
try:
asp = onxp.asarray(x)
except Exception as e:
raise AssertionError(f"asarray fails with x={x!r}, asp={asa!r}.") from e
self.assertEqualArray(asa, asp.numpy())
try:
asa = np.asarray(x, **kw)
except Exception as e:
raise AssertionError(
f"numpy asarray fails with x={x!r}, kw={kw!r}, asp={asa!r}."
) from e
try:
asp = onxp.asarray(x, **kw)
except Exception as e:
raise AssertionError(
f"asarray fails with x={x!r}, kw={kw!r}, asp={asa!r}."
) from e
self.assertEqualArray(asa, asp.numpy())
args_np.append((x, kw))

fct()
Expand Down
5 changes: 5 additions & 0 deletionsonnx_array_api/array_api/_onnx_common.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
from typing import Any, Optional
import numpy as np
from numpy.array_api._array_object import Array
from ..npx.npx_types import (
DType,
ElemType,
Expand DownExpand Up@@ -77,6 +78,10 @@ def asarray(
v = TEagerTensor(np.array(a, dtype=np.str_))
elif isinstance(a, list):
v = TEagerTensor(np.array(a))
elif isinstance(a, np.ndarray):
v = TEagerTensor(a)
elif isinstance(a, Array):
v = TEagerTensor(np.asarray(a))
else:
raise RuntimeError(f"Unexpected type {type(a)} for the first input.")
if dtype is not None:
Expand Down
2 changes: 1 addition & 1 deletionrequirements-dev.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ black
coverage
flake8
furo
hypothesis<6.80.0
hypothesis
isort
joblib
lightgbm
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp