Skip to content
Merged
Changes from 2 commits
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
51 changes: 51 additions & 0 deletions array_api_tests/test_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,57 @@ def test_eye(n_rows, n_cols, kw):
raise



@given(x=hh.arrays(dtype=hh.numeric_dtypes, shape=hh.matrix_shapes()), data=st.data())
def test_tril(x, data):
n, m = x.shape[-2:]
k = data.draw(
st.integers(min_value=-max(n, m, 1), max_value=max(n, m, 1)),
label="k",
)
repro_snippet = ph.format_snippet(f"xp.tril({x!r}, k={k!r})")
try:
out = xp.tril(x, k=k)
ph.assert_dtype("tril", in_dtype=x.dtype, out_dtype=out.dtype)
ph.assert_shape("tril", out_shape=out.shape, expected=x.shape)
for idx in sh.ndindex(out.shape):
*_, i, j = idx
expected = x[idx] if j <= i + k else xp.asarray(0, dtype=out.dtype)
ph.assert_array_elements(
"tril",
out=out[idx],
expected=expected,
)
Comment thread
ev-br marked this conversation as resolved.
Outdated
except Exception as exc:
ph.add_note(exc, repro_snippet)
raise


@given(x=hh.arrays(dtype=hh.numeric_dtypes, shape=hh.matrix_shapes()), data=st.data())
def test_triu(x, data):
n, m = x.shape[-2:]
k = data.draw(
st.integers(min_value=-max(n, m, 1), max_value=max(n, m, 1)),
label="k",
)
repro_snippet = ph.format_snippet(f"xp.triu({x!r}, k={k!r})")
try:
out = xp.triu(x, k=k)
ph.assert_dtype("triu", in_dtype=x.dtype, out_dtype=out.dtype)
ph.assert_shape("triu", out_shape=out.shape, expected=x.shape)
for idx in sh.ndindex(out.shape):
*_, i, j = idx
expected = x[idx] if j >= i + k else xp.asarray(0, dtype=out.dtype)
ph.assert_array_elements(
"triu",
out=out[idx],
expected=expected,
)
except Exception as exc:
ph.add_note(exc, repro_snippet)
raise


default_unsafe_dtypes = [xp.uint64]
if dh.default_int == xp.int32:
default_unsafe_dtypes.extend([xp.uint32, xp.int64])
Expand Down
Loading