forked from data-apis/array-api-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_funcs.py
69 lines (46 loc) · 1.81 KB
/
test_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from __future__ import annotations
# array-api-strict#6
import array_api_strict as xp # type: ignore[import-untyped]
from numpy.testing import assert_array_equal
from array_api_extra import atleast_nd
class TestAtLeastND:
def test_0D(self):
x = xp.asarray(1)
y = atleast_nd(x, ndim=0, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=1, xp=xp)
assert_array_equal(y, xp.ones((1,)))
y = atleast_nd(x, ndim=5, xp=xp)
assert_array_equal(y, xp.ones((1, 1, 1, 1, 1)))
def test_1D(self):
x = xp.asarray([0, 1])
y = atleast_nd(x, ndim=0, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=1, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=2, xp=xp)
assert_array_equal(y, xp.asarray([[0, 1]]))
y = atleast_nd(x, ndim=5, xp=xp)
assert_array_equal(y, xp.reshape(xp.arange(2), (1, 1, 1, 1, 2)))
def test_2D(self):
x = xp.asarray([[3]])
y = atleast_nd(x, ndim=0, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=2, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=3, xp=xp)
assert_array_equal(y, 3 * xp.ones((1, 1, 1)))
y = atleast_nd(x, ndim=5, xp=xp)
assert_array_equal(y, 3 * xp.ones((1, 1, 1, 1, 1)))
def test_5D(self):
x = xp.ones((1, 1, 1, 1, 1))
y = atleast_nd(x, ndim=0, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=4, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=5, xp=xp)
assert_array_equal(y, x)
y = atleast_nd(x, ndim=6, xp=xp)
assert_array_equal(y, xp.ones((1, 1, 1, 1, 1, 1)))
y = atleast_nd(x, ndim=9, xp=xp)
assert_array_equal(y, xp.ones((1, 1, 1, 1, 1, 1, 1, 1, 1)))