Skip to content

Commit

Permalink
bad arg tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samir-nasibli committed Oct 10, 2024
1 parent 09cb477 commit 8b083ba
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
54 changes: 52 additions & 2 deletions onedal/datatypes/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
pytest.param((2000, 50), id="(2000, 50)"),
]

unsupported_data_shapes = [
pytest.param((2, 3, 4), id="(2, 3, 4)"),
pytest.param((2, 3, 4, 5), id="(2, 3, 4, 5)"),
]

ORDER_DICT = {"F": np.asfortranarray, "C": np.ascontiguousarray}


Expand Down Expand Up @@ -335,5 +340,50 @@ def test_table_conversions(dataframe, queue, order, data_shape):
)


# TODO:
# def test_wrong_inputs_for_sua_iface_conversion
@pytest.mark.skipif(
not _is_dpc_backend,
reason="__sycl_usm_array_interface__ support requires DPC backend.",
)
@pytest.mark.parametrize(
"dataframe,queue", get_dataframes_and_queues("dpctl, dpnp", "cpu, gpu")
)
@pytest.mark.parametrize("data_shape", unsupported_data_shapes)
def test_sua_iface_interop_invalid_shape(dataframe, queue, data_shape):
X = np.zeros(data_shape)
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
sua_iface, _, _ = _get_sycl_namespace(X)

expected_err_msg = (
"Unable to convert from SUA interface: only 1D & 2D tensors are allowed"
)
with pytest.raises(ValueError, match=expected_err_msg):
convert_one_to_table(X, sua_iface=sua_iface)


@pytest.mark.skipif(
not _is_dpc_backend,
reason="__sycl_usm_array_interface__ support requires DPC backend.",
)
@pytest.mark.parametrize(
"dataframe,queue", get_dataframes_and_queues("dpctl, dpnp", "cpu, gpu")
)
@pytest.mark.parametrize(
"dtype",
[
pytest.param(np.uint16, id=np.dtype(np.uint16).name),
pytest.param(np.uint32, id=np.dtype(np.uint32).name),
pytest.param(np.uint64, id=np.dtype(np.uint64).name),
],
)
def test_sua_iface_interop_unsupported_dtypes(dataframe, queue, dtype):
# sua iface interobility supported only for OneDAL supported dtypes
# for input data: int32, int64, float32, float64.
# Checking some common dtypes supported by dpctl, dpnp for exception
# raise.
X = np.zeros((10, 20), dtype=dtype)
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
sua_iface, _, _ = _get_sycl_namespace(X)

expected_err_msg = "Unable to convert from SUA interface: unknown data type"
with pytest.raises(ValueError, match=expected_err_msg):
convert_one_to_table(X, sua_iface=sua_iface)
4 changes: 2 additions & 2 deletions onedal/datatypes/utils/sua_iface_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ py::tuple get_sua_shape(const py::dict& sua) {
}

void report_problem_for_sua_iface(const char* clarification) {
constexpr const char* const base_message = "Unable to convert from SUA interface.";
constexpr const char* const base_message = "Unable to convert from SUA interface";

std::string message{ base_message };
message += std::string{ clarification };
Expand Down Expand Up @@ -143,7 +143,7 @@ dal::data_layout get_sua_iface_layout(const py::dict& sua_dict,
}

void report_problem_to_sua_iface(const char* clarification) {
constexpr const char* const base_message = "Unable to convert to SUA interface.";
constexpr const char* const base_message = "Unable to convert to SUA interface";

std::string message{ base_message };
message += std::string{ clarification };
Expand Down

0 comments on commit 8b083ba

Please sign in to comment.