Skip to content

Added unit tests for the upper function #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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Changes from all 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
45 changes: 45 additions & 0 deletions tests/test_upper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest

import arrayfire_wrapper.dtypes as dtypes
import arrayfire_wrapper.lib as wrapper


@pytest.mark.parametrize(
"shape",
[
(3, 3),
(3, 3, 3),
(3, 3, 3, 3),
],
)
def test_diag_is_unit(shape: tuple) -> None:
"""Test if when is_unit_diag in lower returns an array with a unit diagonal"""
dtype = dtypes.s64
constant_array = wrapper.constant(3, shape, dtype)

lower_array = wrapper.upper(constant_array, True)
diagonal = wrapper.diag_extract(lower_array, 0)
diagonal_value = wrapper.get_scalar(diagonal, dtype)

assert diagonal_value == 1


@pytest.mark.parametrize(
"shape",
[
(3, 3),
(3, 3, 3),
(3, 3, 3, 3),
],
)
def test_is_original(shape: tuple) -> None:
"""Test if is_original keeps the diagonal the same as the original array"""
dtype = dtypes.s64
constant_array = wrapper.constant(3, shape, dtype)
original_value = wrapper.get_scalar(constant_array, dtype)

lower_array = wrapper.upper(constant_array, False)
diagonal = wrapper.diag_extract(lower_array, 0)
diagonal_value = wrapper.get_scalar(diagonal, dtype)

assert original_value == diagonal_value