-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
550331d
commit c417ab4
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,12 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
import array_api_strict as xp # type: ignore[import-not-found] | ||
import array_api_strict as xp | ||
from numpy.testing import assert_array_equal | ||
|
||
from array_api_extra import atleast_nd | ||
|
||
|
||
class TestAtLeastND: | ||
def test_1d_to_2d(self): | ||
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 y.ndim == 2 | ||
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))) |