From 33327906a12ed86f00b7ef7f6a1f1bc1f0ea7cf4 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 19 Mar 2024 15:58:16 -0400 Subject: [PATCH 1/4] Added shape and datatype tests for all exp and log operations within arrayfire. --- tests/test_exp_log.py | 581 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 581 insertions(+) create mode 100644 tests/test_exp_log.py diff --git a/tests/test_exp_log.py b/tests/test_exp_log.py new file mode 100644 index 0000000..2965956 --- /dev/null +++ b/tests/test_exp_log.py @@ -0,0 +1,581 @@ +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, + # '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), random.randint(1, 10)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_cbrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test cube root operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.cbrt(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_cbrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test cube root operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.cbrt(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_erf_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test gaussian error operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.erf(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_erf_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test gaussian error operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.erf(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_erfc_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test gaussian error complement operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.erfc(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_erfc_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test gaussian error complement operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.erfc(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_exp_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test exponent operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.exp(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test exponent operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.exp(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_exp1_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test exponent - 1 operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.expm1(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test exponent - 1 operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.expm1(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_exp_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test exponent operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.exp(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test exponent operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.exp(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_fac_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test exponent operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.factorial(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_fac_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test exponent operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.factorial(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_lgamma_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test lgamma operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.lgamma(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_lgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test lgamma operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.lgamma(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_log_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test log operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.log(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_log_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test log operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.log(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_log10_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test log10 operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.log10(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_log10_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test log10 operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.log10(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_log1p_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test natural logarithm of 1 + input operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.log1p(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_log1p_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test logarithm of 1 + input operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.log1p(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_log2_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test log2 operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.log2(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_log2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test log2 operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.log2(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_pow_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test power operation across all supported data types.""" + lhs = wrapper.randu(shape, dtype_name) + rhs = wrapper.randu(shape, dtype_name) + result = wrapper.pow(lhs, rhs) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_pow_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test power operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.pow(wrapper.randu((10,), invdtypes), wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_root_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test root operation across all supported data types.""" + lhs = wrapper.randu(shape, dtype_name) + rhs = wrapper.randu(shape, dtype_name) + result = wrapper.root(lhs, rhs) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_root_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test root operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.root(wrapper.randu((10,), invdtypes), wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_pow2_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test 2 to power operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.pow2(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_pow2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test 2 to power operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.pow2(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_rsqrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test reciprocal square root operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.rsqrt(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_rsqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test reciprocal square root operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.rsqrt(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_sqrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test square root operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.sqrt(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_sqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test square root operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.sqrt(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_tgamma_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test gamma operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.tgamma(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_tgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test gamma operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.tgamma(wrapper.randu((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)), + ], +) +@pytest.mark.parametrize("dtype_name", dtype_map.values()) +def test_sigmoid_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: + """Test sigmoid operation across all supported data types.""" + values = wrapper.randu(shape, dtype_name) + result = wrapper.sigmoid(values) + assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" +@pytest.mark.parametrize( + "invdtypes", + [ + dtype.c64, + dtype.f64, + ], +) +def test_sigmoid_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: + """Test sigmoid operation for unsupported data types.""" + with pytest.raises(RuntimeError): + wrapper.sigmoid(wrapper.randu((10,), invdtypes)) From d8ba177b3077d78c956801421928dbadae9dff83 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 19 Mar 2024 16:24:09 -0400 Subject: [PATCH 2/4] Adhered to all checkstyle requirements. --- tests/test_exp_log.py | 242 ++++++++++++++++++++++++------------------ 1 file changed, 137 insertions(+), 105 deletions(-) diff --git a/tests/test_exp_log.py b/tests/test_exp_log.py index 2965956..821bd2d 100644 --- a/tests/test_exp_log.py +++ b/tests/test_exp_log.py @@ -1,43 +1,45 @@ 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)), @@ -45,11 +47,13 @@ ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_cbrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_cbrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test cube root operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.cbrt(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -61,11 +65,13 @@ def test_cbrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test cube root operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.cbrt(wrapper.randu((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)), @@ -73,11 +79,13 @@ def test_cbrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_erf_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_erf_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gaussian error operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.erf(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -90,11 +98,12 @@ def test_erf_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.erf(wrapper.randu((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)), @@ -102,11 +111,13 @@ def test_erf_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_erfc_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_erfc_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gaussian error complement operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.erfc(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -118,11 +129,13 @@ def test_erfc_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test gaussian error complement operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.erfc(wrapper.randu((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)), @@ -130,11 +143,13 @@ def test_erfc_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_exp_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_exp_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.exp(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -147,11 +162,12 @@ def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.exp(wrapper.randu((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)), @@ -159,11 +175,13 @@ def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_exp1_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_exp1_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent - 1 operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.expm1(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -171,44 +189,17 @@ def test_exp1_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: dtype.f64, ], ) -def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: +def test_expm1_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test exponent - 1 operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.expm1(wrapper.randu((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)), - ], -) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_exp_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: - """Test exponent operation across all supported data types.""" - values = wrapper.randu(shape, dtype_name) - result = wrapper.exp(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" -@pytest.mark.parametrize( - "invdtypes", - [ - dtype.c64, - dtype.f64, - ], -) -def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: - """Test exponent operation for unsupported data types.""" - with pytest.raises(RuntimeError): - wrapper.exp(wrapper.randu((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)), @@ -216,11 +207,13 @@ def test_exp_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_fac_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_fac_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.factorial(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -233,11 +226,12 @@ def test_fac_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.factorial(wrapper.randu((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)), @@ -245,11 +239,13 @@ def test_fac_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_lgamma_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_lgamma_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test lgamma operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.lgamma(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -261,11 +257,13 @@ def test_lgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test lgamma operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.lgamma(wrapper.randu((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)), @@ -273,11 +271,13 @@ def test_lgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_log_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_log_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.log(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -289,11 +289,13 @@ def test_log_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test log operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.log(wrapper.randu((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)), @@ -301,11 +303,13 @@ def test_log_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_log10_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_log10_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log10 operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.log10(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -317,11 +321,13 @@ def test_log10_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test log10 operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.log10(wrapper.randu((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)), @@ -329,11 +335,13 @@ def test_log10_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_log1p_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_log1p_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test natural logarithm of 1 + input operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.log1p(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -346,11 +354,12 @@ def test_log1p_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.log1p(wrapper.randu((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)), @@ -358,11 +367,13 @@ def test_log1p_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_log2_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_log2_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log2 operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.log2(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -375,11 +386,12 @@ def test_log2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.log2(wrapper.randu((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)), @@ -387,12 +399,13 @@ def test_log2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_pow_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_pow_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test power operation across all supported data types.""" lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) result = wrapper.pow(lhs, rhs) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + @pytest.mark.parametrize( "invdtypes", @@ -404,12 +417,14 @@ def test_pow_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: def test_pow_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test power operation for unsupported data types.""" with pytest.raises(RuntimeError): - wrapper.pow(wrapper.randu((10,), invdtypes), wrapper.randu((10, invdtypes))) + wrapper.pow(wrapper.randu((10, 10), invdtypes), 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)), @@ -417,12 +432,13 @@ def test_pow_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_root_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_root_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test root operation across all supported data types.""" lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) result = wrapper.root(lhs, rhs) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + @pytest.mark.parametrize( "invdtypes", @@ -434,13 +450,14 @@ def test_root_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: def test_root_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test root operation for unsupported data types.""" with pytest.raises(RuntimeError): - wrapper.root(wrapper.randu((10,), invdtypes), wrapper.randu((10, invdtypes))) + wrapper.root(wrapper.randu((10, 10), invdtypes), 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)), @@ -448,11 +465,13 @@ def test_root_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_pow2_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_pow2_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test 2 to power operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.pow2(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -465,11 +484,12 @@ def test_pow2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.pow2(wrapper.randu((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)), @@ -477,11 +497,13 @@ def test_pow2_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_rsqrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_rsqrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test reciprocal square root operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.rsqrt(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -493,11 +515,13 @@ def test_rsqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: """Test reciprocal square root operation for unsupported data types.""" with pytest.raises(RuntimeError): wrapper.rsqrt(wrapper.randu((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)), @@ -505,11 +529,13 @@ def test_rsqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_sqrt_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_sqrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test square root operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.sqrt(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -522,11 +548,12 @@ def test_sqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.sqrt(wrapper.randu((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)), @@ -534,11 +561,13 @@ def test_sqrt_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_tgamma_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_tgamma_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gamma operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.tgamma(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ @@ -551,11 +580,12 @@ def test_tgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: with pytest.raises(RuntimeError): wrapper.tgamma(wrapper.randu((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)), @@ -563,11 +593,13 @@ def test_tgamma_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: ], ) @pytest.mark.parametrize("dtype_name", dtype_map.values()) -def test_sigmoid_shape_dtypes(shape:tuple, dtype_name: dtype.Dtype) -> None: +def test_sigmoid_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test sigmoid operation across all supported data types.""" values = wrapper.randu(shape, dtype_name) result = wrapper.sigmoid(values) - assert wrapper.get_dims(result)[0:len(shape)] == shape, f"failed for shape: {shape}" + assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa + + @pytest.mark.parametrize( "invdtypes", [ From 2a7afa27670d4de4b3e5ddb05db8c199ce02b553 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 26 Mar 2024 15:31:54 -0400 Subject: [PATCH 3/4] Added all dtype coverage, removed dmap. --- tests/test_exp_log.py | 100 ++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 63 deletions(-) diff --git a/tests/test_exp_log.py b/tests/test_exp_log.py index 821bd2d..4b06e1b 100644 --- a/tests/test_exp_log.py +++ b/tests/test_exp_log.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,15 +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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_cbrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test cube root operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.cbrt(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -72,15 +44,15 @@ def test_cbrt_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_erf_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gaussian error operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.erf(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -104,15 +76,15 @@ def test_erf_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_erfc_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gaussian error complement operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.erfc(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -136,15 +108,15 @@ def test_erfc_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_exp_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.exp(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -168,15 +140,15 @@ def test_exp_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_exp1_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent - 1 operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.expm1(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -200,15 +172,15 @@ def test_expm1_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_fac_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test exponent operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.factorial(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -238,9 +210,10 @@ def test_fac_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: (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_lgamma_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test lgamma operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.lgamma(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -264,15 +237,15 @@ def test_lgamma_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_log_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.log(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -296,15 +269,15 @@ def test_log_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_log10_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log10 operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.log10(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -328,15 +301,15 @@ def test_log10_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_log1p_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test natural logarithm of 1 + input operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.log1p(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -360,15 +333,15 @@ def test_log1p_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_log2_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test log2 operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.log2(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -392,15 +365,15 @@ def test_log2_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_pow_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test power operation across all supported data types.""" + check_type_supported(dtype_name) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) result = wrapper.pow(lhs, rhs) @@ -425,15 +398,15 @@ def test_pow_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_root_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test root operation across all supported data types.""" + check_type_supported(dtype_name) lhs = wrapper.randu(shape, dtype_name) rhs = wrapper.randu(shape, dtype_name) result = wrapper.root(lhs, rhs) @@ -464,9 +437,10 @@ def test_root_unsupported_dtypes(invdtypes: dtype.Dtype) -> None: (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_pow2_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test 2 to power operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.pow2(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -490,15 +464,15 @@ def test_pow2_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_rsqrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test reciprocal square root operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.rsqrt(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -522,15 +496,15 @@ def test_rsqrt_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_sqrt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test square root operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.sqrt(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -554,15 +528,15 @@ def test_sqrt_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_tgamma_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test gamma operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.tgamma(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa @@ -586,15 +560,15 @@ def test_tgamma_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)), ], ) -@pytest.mark.parametrize("dtype_name", dtype_map.values()) +@pytest.mark.parametrize("dtype_name", get_all_types()) def test_sigmoid_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None: """Test sigmoid operation across all supported data types.""" + check_type_supported(dtype_name) values = wrapper.randu(shape, dtype_name) result = wrapper.sigmoid(values) assert wrapper.get_dims(result)[0 : len(shape)] == shape, f"failed for shape: {shape}" # noqa From 1de90c63929638f2760c5349319d18adc292090f Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Tue, 26 Mar 2024 15:33:03 -0400 Subject: [PATCH 4/4] Wrapped up checkstyle changes. --- tests/test_exp_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_exp_log.py b/tests/test_exp_log.py index 4b06e1b..f46cba5 100644 --- a/tests/test_exp_log.py +++ b/tests/test_exp_log.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(