From fa3d72ba5e9e8caf5420e13e7f31712eeb30579a Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 19 Mar 2024 17:59:11 -0400 Subject: [PATCH 1/4] Added all hyberbolic tests for shapes and dtypes. --- tests/test_hyperbolic.py | 247 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 tests/test_hyperbolic.py diff --git a/tests/test_hyperbolic.py b/tests/test_hyperbolic.py new file mode 100644 index 0000000..5bc83f4 --- /dev/null +++ b/tests/test_hyperbolic.py @@ -0,0 +1,247 @@ +import random + +import pytest + +import arrayfire_wrapper.dtypes as dtype +import arrayfire_wrapper.lib as wrapper + + +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, + "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, + "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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_asinh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test inverse hyperbolic sine operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.asinh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_asinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test inverse hyperbolic sine operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.asinh(wrapper.randu((10, 10), invdtypes)) +@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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_acosh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test inverse hyperbolic cosine operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.acosh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_acosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test inverse hyperbolic cosine operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.acosh(wrapper.randu((10, 10), invdtypes)) +@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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_atanh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test inverse hyperbolic tan operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.atanh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_atanh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test inverse hyperbolic tan operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.atanh(wrapper.randu((10, 10), invdtypes)) + +@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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_cosh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test hyperbolic cosine operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.cosh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_cosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test hyperbolic cosine operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.cosh(wrapper.randu((10, 10), invdtypes)) + +@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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_sinh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test hyberbolic sin operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.sinh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_sinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test hyperbolic sine operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.sinh(wrapper.randu((10, 10), invdtypes)) + +@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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_tanh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: + """Test hyberbolic tan operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.tanh(values) + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_tanh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test hyberbolic tan operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.tanh(wrapper.randu((10, 10), invdtypes)) From eca38ca1343492256c7b4da2490e5d7624b37882 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 19 Mar 2024 18:01:35 -0400 Subject: [PATCH 2/4] Adhered to all checkstyle requirements. --- tests/test_hyperbolic.py | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/tests/test_hyperbolic.py b/tests/test_hyperbolic.py index 5bc83f4..2fca416 100644 --- a/tests/test_hyperbolic.py +++ b/tests/test_hyperbolic.py @@ -5,17 +5,7 @@ import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper - 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, @@ -28,16 +18,6 @@ # '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, "bool": dtype.b8, "s16": dtype.s16, "s32": dtype.s32, @@ -51,7 +31,6 @@ # 'f64': dtype.f64, # 'c32': dtype.c32, # 'c64': dtype.c64, - 'b8': dtype.b8, "b8": dtype.b8, } @@ -60,7 +39,7 @@ "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)), @@ -87,11 +66,13 @@ def test_asinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test inverse hyperbolic sine operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.asinh(wrapper.randu((10, 10), invdtypes)) + + @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)), @@ -118,11 +99,13 @@ def test_acosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test inverse hyperbolic cosine operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.acosh(wrapper.randu((10, 10), invdtypes)) + + @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)), @@ -150,11 +133,12 @@ def test_atanh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.atanh(wrapper.randu((10, 10), invdtypes)) + @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)), @@ -182,11 +166,12 @@ def test_cosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.cosh(wrapper.randu((10, 10), invdtypes)) + @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)), @@ -214,11 +199,12 @@ def test_sinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.sinh(wrapper.randu((10, 10), invdtypes)) + @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)), From baa715d161a7d5d80bad651fc2299cb414869041 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 26 Mar 2024 15:14:29 -0400 Subject: [PATCH 3/4] Removed type map, added all necessary coverage. --- tests/test_hyperbolic.py | 60 +++++++++------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/tests/test_hyperbolic.py b/tests/test_hyperbolic.py index 2fca416..6856c9f 100644 --- a/tests/test_hyperbolic.py +++ b/tests/test_hyperbolic.py @@ -4,35 +4,7 @@ import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper - -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 tests.utility_functions import check_type_supported, get_all_types, get_float_types @pytest.mark.parametrize( @@ -40,16 +12,15 @@ [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_asinh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test inverse hyperbolic sine operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.asinh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -73,16 +44,15 @@ def test_asinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_acosh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test inverse hyperbolic cosine operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.acosh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -106,16 +76,15 @@ def test_acosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_atanh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test inverse hyperbolic tan operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.atanh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -139,16 +108,15 @@ def test_atanh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_cosh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test hyperbolic cosine operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.cosh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -172,16 +140,15 @@ def test_cosh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_sinh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test hyberbolic sin operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.sinh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -205,16 +172,15 @@ def test_sinh_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: [ (), (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), random.randint(1, 10)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_tanh_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test hyberbolic tan operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.tanh(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa From 7ad6f7337123257a182d29b71b6ed4d67d610c11 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 26 Mar 2024 15:16:01 -0400 Subject: [PATCH 4/4] Adhered to all checkstyle changes. --- tests/test_hyperbolic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_hyperbolic.py b/tests/test_hyperbolic.py index 6856c9f..a066ed2 100644 --- a/tests/test_hyperbolic.py +++ b/tests/test_hyperbolic.py @@ -4,7 +4,7 @@ import arrayfire_wrapper.dtypes as dtype import arrayfire_wrapper.lib as wrapper -from tests.utility_functions import check_type_supported, get_all_types, get_float_types +from tests.utility_functions import check_type_supported, get_all_types @pytest.mark.parametrize(