From af4a315acc019577a3b82e8f8ccdd9cc59d91d7a Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 18 Mar 2024 12:55:40 -0400 Subject: [PATCH 1/8] Wrapped up multiplication/divison unit tests, ensured that all cases were covered and currently exploring division by 0 case --- tests/test_muldiv.py | 266 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 tests/test_muldiv.py diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py new file mode 100644 index 0000000..77e37ce --- /dev/null +++ b/tests/test_muldiv.py @@ -0,0 +1,266 @@ +import numpy as np +import pytest + +import arrayfire_wrapper.dtypes as dtype +import arrayfire_wrapper.lib as wrapper +import arrayfire_wrapper.lib.mathematical_functions as ops +from arrayfire_wrapper.lib.create_and_modify_array.helper_functions import array_to_string + + +import random + +dtype_map = { + 'int16': dtype.s16, + 'int32': dtype.s32, + 'int64': dtype.s64, + 'uint8': dtype.u8, + 'uint16': dtype.u16, + 'uint32': dtype.u32, + 'uint64': dtype.u64, + 'float16': dtype.f16, + 'float32': dtype.f32, + # 'float64': dtype.f64, + # 'complex64': dtype.c64, + 'complex32': dtype.c32, + 'bool': dtype.b8, + 's16': dtype.s16, + 's32': dtype.s32, + 's64': dtype.s64, + 'u8': dtype.u8, + 'u16': dtype.u16, + 'u32': dtype.u32, + 'u64': dtype.u64, + 'f16': dtype.f16, + 'f32': dtype.f32, + # 'f64': dtype.f64, + 'c32': dtype.c32, + # 'c64': dtype.c64, + 'b8': dtype.b8, +} + +@pytest.mark.parametrize( + "shape", + [ + (), + (random.randint(1, 10), ), + (random.randint(1, 10), random.randint(1, 10)), + (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), + (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), + ], +) +def test_multiply_shapes(shape: tuple) -> None: + """Test multiplication operation between two arrays of the same shape""" + lhs = wrapper.randu(shape, dtype.f16) + rhs = wrapper.randu(shape, dtype.f16) + + result = wrapper.mul(lhs, rhs) + + assert wrapper.get_dims(result)[0 : len(shape)] == shape + +def test_multiply_different_shapes() -> None: + """Test if multiplication handles arrays of different shapes""" + with pytest.raises(RuntimeError): + lhs_shape = (2, 3) + rhs_shape = (3, 2) + dtypes = dtype.f16 + lhs = wrapper.randu(lhs_shape, dtypes) + rhs = wrapper.randu(rhs_shape, dtypes) + result = wrapper.mul(lhs, rhs) + expected_shape = np.broadcast(np.empty(lhs), np.empty(rhs)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + +def test_multiply_negative_shapes() -> None: + """Test if multiplication handles arrays of negative shapes""" + with pytest.raises(RuntimeError): + lhs_shape = (2, -2) + rhs_shape = (-2, 2) + dtypes = dtype.f16 + lhs = wrapper.randu(lhs_shape, dtypes) + rhs = wrapper.randu(rhs_shape, dtypes) + result = wrapper.mul(lhs, rhs) + expected_shape = np.broadcast(np.empty(lhs), np.empty(rhs)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_multiply_supported_dtypes(dtype_name: str) -> None: + """Test multiplication operation across all supported data types.""" + shape = (5, 5) + lhs = wrapper.randu(shape, dtype_name) + rhs = wrapper.randu(shape, dtype_name) + result = wrapper.mul(lhs, rhs) + assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_multiply_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test multiplication operation for unsupported data types.""" + with pytest.raises(RuntimeError): + shape = (5, 5) + lhs = wrapper.randu(shape, invdtypes) + rhs = wrapper.randu(shape, invdtypes) + wrapper.mul(lhs, rhs) + +def test_multiply_zero_sized_arrays() -> None: + """Test multiplication with arrays where at least one array has zero size.""" + with pytest.raises(RuntimeError): + zero_shape = (0, 5) + normal_shape = (5, 5) + zero_array = wrapper.randu(zero_shape, dtype.f32) + normal_array = wrapper.randu(normal_shape, dtype.f32) + + result_rhs_zero = wrapper.mul(normal_array, zero_array) + assert wrapper.get_dims(result_rhs_zero) == normal_shape + + result_lhs_zero = wrapper.mul(zero_array, normal_array) + assert wrapper.get_dims(result_lhs_zero) == zero_shape + +@pytest.mark.parametrize( + "shape_a, shape_b", + [ + ((1, 5), (5, 1)), # 2D with 2D inverse + ((5, 5), (5, 1)), # 2D with 2D + ((5, 5), (1, 1)), # 2D with 2D + ((1, 1, 1), (5, 5, 5)), # 3D with 3D + ((5,), (5,)), # 1D with 1D broadcast + ], +) +def test_multiply_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None: + """Test multiplication with arrays of varying dimensionality.""" + lhs = wrapper.randu(shape_a, dtype.f32) + rhs = wrapper.randu(shape_b, dtype.f32) + + result = wrapper.mul(lhs, rhs) + expected_shape = np.broadcast(np.empty(shape_a), np.empty(shape_b)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {shape_a} and {shape_b}" + +@pytest.mark.parametrize( + "shape", + [ + (), + (random.randint(1, 10), ), + (random.randint(1, 10), random.randint(1, 10)), + (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), + (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), + ], +) +def test_divide_shapes(shape: tuple) -> None: + """Test division operation between two arrays of the same shape""" + lhs = wrapper.randu(shape, dtype.f16) + rhs = wrapper.randu(shape, dtype.f16) + # Ensure no division by zero for test integrity + rhs = wrapper.add(rhs, wrapper.constant(0.001, shape, dtype.f16)) + + result = wrapper.div(lhs, rhs) + + assert wrapper.get_dims(result)[0 : len(shape)] == shape + +def test_divide_different_shapes() -> None: + """Test if division handles arrays of different shapes""" + with pytest.raises(RuntimeError): + lhs_shape = (2, 3) + rhs_shape = (3, 2) + dtypes = dtype.f16 + lhs = wrapper.randu(lhs_shape, dtypes) + rhs = wrapper.randu(rhs_shape, dtypes) + result = wrapper.div(lhs, rhs) + expected_shape = np.broadcast(np.empty(lhs_shape), np.empty(rhs_shape)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + +def test_divide_negative_shapes() -> None: + """Test if division handles arrays of negative shapes""" + with pytest.raises(RuntimeError): + lhs_shape = (2, -2) + rhs_shape = (-2, 2) + dtypes = dtype.f16 + lhs = wrapper.randu(lhs_shape, dtypes) + rhs = wrapper.randu(rhs_shape, dtypes) + result = wrapper.div(lhs, rhs) + expected_shape = np.broadcast(np.empty(lhs_shape), np.empty(rhs_shape)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_divide_supported_dtypes(dtype_name: str) -> None: + """Test division operation across all supported data types.""" + shape = (5, 5) + lhs = wrapper.randu(shape, dtype_name) + rhs = wrapper.randu(shape, dtype_name) + # Ensure no division by zero for test integrity + rhs = wrapper.add(rhs, wrapper.constant(0.001, shape, dtype_name)) + + result = wrapper.div(lhs, rhs) + assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + +def test_divide_by0() -> None: + """Test division operation for undefined error type.""" + shape = (2, 2) + lhs = wrapper.constant(5, shape, dtype.f16) + rhs = wrapper.constant(0, shape, dtype.f16) + lhsnp = np.full(shape, 5) + rhsnp = np.zeros(shape) + out = np.divide(lhsnp, rhsnp) + print(out) + with pytest.raises(RuntimeError): + divOut = wrapper.div(lhs, rhs) + print(array_to_string("", divOut, 3, False)) + wrapper.div(lhs, rhs) + + # result = wrapper.div(lhs, rhs) + # assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_divide_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test division operation for unsupported data types.""" + with pytest.raises(RuntimeError): + shape = (5, 5) + lhs = wrapper.randu(shape, invdtypes) + rhs = wrapper.randu(shape, invdtypes) + # Prevent division by zero in unsupported dtype test + rhs = wrapper.add(rhs, wrapper.constant(0.001, shape, invdtypes)) + + wrapper.div(lhs, rhs) + +def test_divide_zero_sized_arrays() -> None: + """Test division with arrays where at least one array has zero size.""" + with pytest.raises(RuntimeError): + zero_shape = (0, 5) + normal_shape = (5, 5) + zero_array = wrapper.randu(zero_shape, dtype.f32) + normal_array = wrapper.randu(normal_shape, dtype.f32) + + result_rhs_zero = wrapper.div(normal_array, zero_array) + assert wrapper.get_dims(result_rhs_zero) == normal_shape + + result_lhs_zero = wrapper.div(zero_array, normal_array) + assert wrapper.get_dims(result_lhs_zero) == zero_shape + +@pytest.mark.parametrize( + "shape_a, shape_b", + [ + ((1, 5), (5, 1)), # 2D with 2D inverse + ((5, 5), (5, 1)), # 2D with 2D + ((5, 5), (1, 1)), # 2D with 2D + ((1, 1, 1), (5, 5, 5)), # 3D with 3D + ((5,), (5,)), # 1D with 1D broadcast + ], +) +def test_divide_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None: + """Test division with arrays of varying dimensionality.""" + lhs = wrapper.randu(shape_a, dtype.f32) + rhs = wrapper.randu(shape_b, dtype.f32) + # Prevent division by zero for dimensional test + rhs = wrapper.add(rhs, wrapper.constant(0.001, shape_b, dtype.f32)) + + result = wrapper.div(lhs, rhs) + expected_shape = np.broadcast(np.empty(shape_a), np.empty(shape_b)).shape + assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {shape_a} and {shape_b}" \ No newline at end of file From 02cde71867e1c0c3cbaa6740899582471a3a3fe7 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 18 Mar 2024 18:17:03 -0400 Subject: [PATCH 2/8] Ensured all checkstyle requirements are passing. --- tests/test_muldiv.py | 111 ++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 43 deletions(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index 77e37ce..ff3b721 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -1,48 +1,49 @@ +import random + import numpy as np import pytest import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper -import arrayfire_wrapper.lib.mathematical_functions as ops -from arrayfire_wrapper.lib.create_and_modify_array.helper_functions import array_to_string - -import random +# import arrayfire_wrapper.lib.mathematical_functions as ops +from arrayfire_wrapper.lib.create_and_modify_array.helper_functions import array_to_string dtype_map = { - 'int16': dtype.s16, - 'int32': dtype.s32, - 'int64': dtype.s64, - 'uint8': dtype.u8, - 'uint16': dtype.u16, - 'uint32': dtype.u32, - 'uint64': dtype.u64, - 'float16': dtype.f16, - 'float32': dtype.f32, + "int16": dtype.s16, + "int32": dtype.s32, + "int64": dtype.s64, + "uint8": dtype.u8, + "uint16": dtype.u16, + "uint32": dtype.u32, + "uint64": dtype.u64, + "float16": dtype.f16, + "float32": dtype.f32, # 'float64': dtype.f64, # 'complex64': dtype.c64, - 'complex32': dtype.c32, - 'bool': dtype.b8, - 's16': dtype.s16, - 's32': dtype.s32, - 's64': dtype.s64, - 'u8': dtype.u8, - 'u16': dtype.u16, - 'u32': dtype.u32, - 'u64': dtype.u64, - 'f16': dtype.f16, - 'f32': dtype.f32, + "complex32": dtype.c32, + "bool": dtype.b8, + "s16": dtype.s16, + "s32": dtype.s32, + "s64": dtype.s64, + "u8": dtype.u8, + "u16": dtype.u16, + "u32": dtype.u32, + "u64": dtype.u64, + "f16": dtype.f16, + "f32": dtype.f32, # 'f64': dtype.f64, - 'c32': dtype.c32, + "c32": dtype.c32, # 'c64': dtype.c64, - 'b8': dtype.b8, + "b8": dtype.b8, } + @pytest.mark.parametrize( "shape", [ (), - (random.randint(1, 10), ), + (random.randint(1, 10),), (random.randint(1, 10), random.randint(1, 10)), (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), @@ -55,7 +56,8 @@ def test_multiply_shapes(shape: tuple) -> None: result = wrapper.mul(lhs, rhs) - assert wrapper.get_dims(result)[0 : len(shape)] == shape + assert wrapper.get_dims(result)[0 : len(shape)] == shape # noqa + def test_multiply_different_shapes() -> None: """Test if multiplication handles arrays of different shapes""" @@ -66,8 +68,10 @@ def test_multiply_different_shapes() -> None: lhs = wrapper.randu(lhs_shape, dtypes) rhs = wrapper.randu(rhs_shape, dtypes) result = wrapper.mul(lhs, rhs) - expected_shape = np.broadcast(np.empty(lhs), np.empty(rhs)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + assert ( + wrapper.get_dims(result)[0 : len(lhs_shape)] == lhs_shape # noqa + ), f"Failed for shapes {lhs_shape} and {rhs_shape}" + def test_multiply_negative_shapes() -> None: """Test if multiplication handles arrays of negative shapes""" @@ -78,11 +82,13 @@ def test_multiply_negative_shapes() -> None: lhs = wrapper.randu(lhs_shape, dtypes) rhs = wrapper.randu(rhs_shape, dtypes) result = wrapper.mul(lhs, rhs) - expected_shape = np.broadcast(np.empty(lhs), np.empty(rhs)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + assert ( + wrapper.get_dims(result)[0 : len(lhs_shape)] == lhs_shape # noqa + ), f"Failed for shapes {lhs_shape} and {rhs_shape}" + @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_multiply_supported_dtypes(dtype_name: str) -> None: +def test_multiply_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test multiplication operation across all supported data types.""" shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) @@ -90,6 +96,7 @@ def test_multiply_supported_dtypes(dtype_name: str) -> None: result = wrapper.mul(lhs, rhs) assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + @pytest.mark.parametrize( "invdtypes", [ @@ -105,6 +112,7 @@ def test_multiply_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: rhs = wrapper.randu(shape, invdtypes) wrapper.mul(lhs, rhs) + def test_multiply_zero_sized_arrays() -> None: """Test multiplication with arrays where at least one array has zero size.""" with pytest.raises(RuntimeError): @@ -115,10 +123,11 @@ def test_multiply_zero_sized_arrays() -> None: result_rhs_zero = wrapper.mul(normal_array, zero_array) assert wrapper.get_dims(result_rhs_zero) == normal_shape - + result_lhs_zero = wrapper.mul(zero_array, normal_array) assert wrapper.get_dims(result_lhs_zero) == zero_shape + @pytest.mark.parametrize( "shape_a, shape_b", [ @@ -136,13 +145,16 @@ def test_multiply_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None result = wrapper.mul(lhs, rhs) expected_shape = np.broadcast(np.empty(shape_a), np.empty(shape_b)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {shape_a} and {shape_b}" + assert ( + wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape # noqa + ), f"Failed for shapes {shape_a} and {shape_b}" + @pytest.mark.parametrize( "shape", [ (), - (random.randint(1, 10), ), + (random.randint(1, 10),), (random.randint(1, 10), random.randint(1, 10)), (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), (random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)), @@ -157,7 +169,8 @@ def test_divide_shapes(shape: tuple) -> None: result = wrapper.div(lhs, rhs) - assert wrapper.get_dims(result)[0 : len(shape)] == shape + assert wrapper.get_dims(result)[0 : len(shape)] == shape # noqa + def test_divide_different_shapes() -> None: """Test if division handles arrays of different shapes""" @@ -169,7 +182,10 @@ def test_divide_different_shapes() -> None: rhs = wrapper.randu(rhs_shape, dtypes) result = wrapper.div(lhs, rhs) expected_shape = np.broadcast(np.empty(lhs_shape), np.empty(rhs_shape)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + assert ( + wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape # noqa + ), f"Failed for shapes {lhs_shape} and {rhs_shape}" + def test_divide_negative_shapes() -> None: """Test if division handles arrays of negative shapes""" @@ -181,10 +197,13 @@ def test_divide_negative_shapes() -> None: rhs = wrapper.randu(rhs_shape, dtypes) result = wrapper.div(lhs, rhs) expected_shape = np.broadcast(np.empty(lhs_shape), np.empty(rhs_shape)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {lhs_shape} and {rhs_shape}" + assert ( + wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape # noqa + ), f"Failed for shapes {lhs_shape} and {rhs_shape}" + @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_divide_supported_dtypes(dtype_name: str) -> None: +def test_divide_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test division operation across all supported data types.""" shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) @@ -195,6 +214,7 @@ def test_divide_supported_dtypes(dtype_name: str) -> None: result = wrapper.div(lhs, rhs) assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + def test_divide_by0() -> None: """Test division operation for undefined error type.""" shape = (2, 2) @@ -208,10 +228,11 @@ def test_divide_by0() -> None: divOut = wrapper.div(lhs, rhs) print(array_to_string("", divOut, 3, False)) wrapper.div(lhs, rhs) - + # result = wrapper.div(lhs, rhs) # assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" + @pytest.mark.parametrize( "invdtypes", [ @@ -230,6 +251,7 @@ def test_divide_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: wrapper.div(lhs, rhs) + def test_divide_zero_sized_arrays() -> None: """Test division with arrays where at least one array has zero size.""" with pytest.raises(RuntimeError): @@ -240,10 +262,11 @@ def test_divide_zero_sized_arrays() -> None: result_rhs_zero = wrapper.div(normal_array, zero_array) assert wrapper.get_dims(result_rhs_zero) == normal_shape - + result_lhs_zero = wrapper.div(zero_array, normal_array) assert wrapper.get_dims(result_lhs_zero) == zero_shape + @pytest.mark.parametrize( "shape_a, shape_b", [ @@ -263,4 +286,6 @@ def test_divide_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None: result = wrapper.div(lhs, rhs) expected_shape = np.broadcast(np.empty(shape_a), np.empty(shape_b)).shape - assert wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape, f"Failed for shapes {shape_a} and {shape_b}" \ No newline at end of file + assert ( + wrapper.get_dims(result)[0 : len(expected_shape)] == expected_shape # noqa + ), f"Failed for shapes {shape_a} and {shape_b}" From d476268f9d05376b8b8e680af853e2a1f2e48104 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 19 Mar 2024 16:54:59 -0400 Subject: [PATCH 3/8] Fixed division by 0 error. Ready to push! --- tests/test_muldiv.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index ff3b721..bd441af 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -164,7 +164,6 @@ def test_divide_shapes(shape: tuple) -> None: """Test division operation between two arrays of the same shape""" lhs = wrapper.randu(shape, dtype.f16) rhs = wrapper.randu(shape, dtype.f16) - # Ensure no division by zero for test integrity rhs = wrapper.add(rhs, wrapper.constant(0.001, shape, dtype.f16)) result = wrapper.div(lhs, rhs) @@ -208,31 +207,12 @@ def test_divide_supported_dtypes(dtype_name: dtype.Dtype) -> None: shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) - # Ensure no division by zero for test integrity rhs = wrapper.add(rhs, wrapper.constant(0.001, shape, dtype_name)) result = wrapper.div(lhs, rhs) assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" -def test_divide_by0() -> None: - """Test division operation for undefined error type.""" - shape = (2, 2) - lhs = wrapper.constant(5, shape, dtype.f16) - rhs = wrapper.constant(0, shape, dtype.f16) - lhsnp = np.full(shape, 5) - rhsnp = np.zeros(shape) - out = np.divide(lhsnp, rhsnp) - print(out) - with pytest.raises(RuntimeError): - divOut = wrapper.div(lhs, rhs) - print(array_to_string("", divOut, 3, False)) - wrapper.div(lhs, rhs) - - # result = wrapper.div(lhs, rhs) - # assert dtype.c_api_value_to_dtype(wrapper.get_type(result)) == dtype_name, f"Failed for dtype: {dtype_name}" - - @pytest.mark.parametrize( "invdtypes", [ From 3518eae80f8bee5615507e29ca35481e4d32c407 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Wed, 20 Mar 2024 16:44:53 -0400 Subject: [PATCH 4/8] Removed dtype_map --- tests/test_muldiv.py | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index bd441af..85a9a10 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -7,36 +7,8 @@ import arrayfire_wrapper.lib as wrapper # import arrayfire_wrapper.lib.mathematical_functions as ops -from arrayfire_wrapper.lib.create_and_modify_array.helper_functions import array_to_string - -dtype_map = { - "int16": dtype.s16, - "int32": dtype.s32, - "int64": dtype.s64, - "uint8": dtype.u8, - "uint16": dtype.u16, - "uint32": dtype.u32, - "uint64": dtype.u64, - "float16": dtype.f16, - "float32": dtype.f32, - # 'float64': dtype.f64, - # 'complex64': dtype.c64, - "complex32": dtype.c32, - "bool": dtype.b8, - "s16": dtype.s16, - "s32": dtype.s32, - "s64": dtype.s64, - "u8": dtype.u8, - "u16": dtype.u16, - "u32": dtype.u32, - "u64": dtype.u64, - "f16": dtype.f16, - "f32": dtype.f32, - # 'f64': dtype.f64, - "c32": dtype.c32, - # 'c64': dtype.c64, - "b8": dtype.b8, -} + +from . import utility_functions as util @pytest.mark.parametrize( @@ -87,9 +59,10 @@ def test_multiply_negative_shapes() -> None: ), f"Failed for shapes {lhs_shape} and {rhs_shape}" -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", util.get_all_types()) def test_multiply_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test multiplication operation across all supported data types.""" + util.check_type_supported(dtype_name) shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) @@ -201,9 +174,10 @@ def test_divide_negative_shapes() -> None: ), f"Failed for shapes {lhs_shape} and {rhs_shape}" -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", util.get_all_types()) def test_divide_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test division operation across all supported data types.""" + util.check_type_supported(dtype_name) shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) From 879ac5f4dae5161e3619dcc925bf6e86844eab25 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 25 Mar 2024 11:51:35 -0400 Subject: [PATCH 5/8] Removed unneeded comments, fixed import statement. --- tests/test_muldiv.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index 85a9a10..3a9d2a6 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -6,10 +6,7 @@ import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper -# import arrayfire_wrapper.lib.mathematical_functions as ops - -from . import utility_functions as util - +from utility_functions import check_type_supported, get_all_types @pytest.mark.parametrize( "shape", @@ -59,10 +56,10 @@ def test_multiply_negative_shapes() -> None: ), f"Failed for shapes {lhs_shape} and {rhs_shape}" -@pytest.mark.parametrize("dtype_name", util.get_all_types()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_multiply_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test multiplication operation across all supported data types.""" - util.check_type_supported(dtype_name) + check_type_supported(dtype_name) shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) @@ -174,10 +171,10 @@ def test_divide_negative_shapes() -> None: ), f"Failed for shapes {lhs_shape} and {rhs_shape}" -@pytest.mark.parametrize("dtype_name", util.get_all_types()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_divide_supported_dtypes(dtype_name: dtype.Dtype) -> None: """Test division operation across all supported data types.""" - util.check_type_supported(dtype_name) + check_type_supported(dtype_name) shape = (5, 5) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) From 4fd8644af30099f9df7015c51fe71ae80b1c3cd2 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 25 Mar 2024 11:53:00 -0400 Subject: [PATCH 6/8] Adhered to all checkstyle guidelines. --- tests/test_muldiv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index 3a9d2a6..26e1855 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -2,11 +2,11 @@ import numpy as np import pytest +from utility_functions import check_type_supported, get_all_types import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper -from utility_functions import check_type_supported, get_all_types @pytest.mark.parametrize( "shape", From 426acc6941b7d648507ebd20c32331918edc6502 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 25 Mar 2024 12:11:17 -0400 Subject: [PATCH 7/8] Fixed import statements in test_muldiv.py --- tests/test_muldiv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index 26e1855..c6d9a6e 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from utility_functions import check_type_supported, get_all_types +from tests.utility_functions import check_type_supported, get_all_types import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper From 89130807f4bdc44acf5168a550585ed40b4c8adc Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Mon, 25 Mar 2024 12:39:11 -0400 Subject: [PATCH 8/8] Still somehow missed isort despite running it. --- tests/test_muldiv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_muldiv.py b/tests/test_muldiv.py index c6d9a6e..28af85b 100644 --- a/tests/test_muldiv.py +++ b/tests/test_muldiv.py @@ -2,10 +2,10 @@ import numpy as np import pytest -from tests.utility_functions import check_type_supported, get_all_types import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper +from tests.utility_functions import check_type_supported, get_all_types @pytest.mark.parametrize(