From f67c73d702271e1eb7ee83141de388c36247113e Mon Sep 17 00:00:00 2001 From: Pearu Peterson Date: Wed, 8 Jan 2025 23:10:17 +0200 Subject: [PATCH] Add StableHLO complex log to stablehlo-complex-math-expander pass (#2681) As in the title. This PR is created on top of the branch of https://github.com/openxla/stablehlo/pull/2679. This PR improves the accuracy of JAX complex `log` function as follows: ``` Before ------ test_accuracy.py::test_unary[log-jax-cpu-complex64-default] maximal ULP difference: 4294967296 ULP difference == 0: 1612359 ULP difference == 1: 487617 ULP difference == 2: 306 ULP difference == 3: 140 ULP difference == 4: 68 ULP difference == 5: 49 ULP difference == 6: 26 ULP difference == 7: 35 ULP difference == 8: 19 ULP difference == 9: 15 ULP difference == 10: 15 ULP difference >= 11: 151 test_accuracy.py::test_unary[log-jax-cuda-complex64-default] maximal ULP difference: 4294967296 ULP difference == 0: 1797796 ULP difference == 1: 301398 ULP difference == 2: 1044 ULP difference == 3: 169 ULP difference == 4: 85 ULP difference == 5: 51 ULP difference == 6: 32 ULP difference == 7: 20 ULP difference == 8: 7 ULP difference == 9: 13 ULP difference == 10: 8 ULP difference >= 11: 177 After ----- test_accuracy.py::test_unary[log-jax-cpu-complex64-default] maximal ULP difference: 3 ULP difference == 0: 1581126 ULP difference == 1: 519652 ULP difference == 2: 19 ULP difference == 3: 3 test_accuracy.py::test_unary[log-jax-cuda-complex64-default] maximal ULP difference: 2 ULP difference == 0: 1775914 ULP difference == 1: 324185 ULP difference == 2: 701 ``` The corresponding accuracy patterns are available in https://github.com/pearu/functional_algorithms/issues/46#issuecomment-2566567331 . --- build_tools/math/README.md | 2 +- .../generate_ChloDecompositionPatternsMath.py | 1 + build_tools/math/generate_tests.py | 8 +- stablehlo/tests/math/log_complex128.mlir | 19 +++ stablehlo/tests/math/log_complex64.mlir | 19 +++ stablehlo/tests/math/log_float32.mlir | 19 +++ stablehlo/tests/math/log_float64.mlir | 19 +++ .../StablehloComplexMathExpanderPatterns.td | 155 +++++++++++++++++- 8 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 stablehlo/tests/math/log_complex128.mlir create mode 100644 stablehlo/tests/math/log_complex64.mlir create mode 100644 stablehlo/tests/math/log_float32.mlir create mode 100644 stablehlo/tests/math/log_float64.mlir diff --git a/build_tools/math/README.md b/build_tools/math/README.md index f2dca9c228..f885c308d8 100644 --- a/build_tools/math/README.md +++ b/build_tools/math/README.md @@ -31,7 +31,7 @@ following requirements: - Python 3.11 or newer - mpmath 1.3 or newer -- functional_algorithms 0.13.2 or newer +- functional_algorithms 0.14.1 or newer that can be installed via pypi: diff --git a/build_tools/math/generate_ChloDecompositionPatternsMath.py b/build_tools/math/generate_ChloDecompositionPatternsMath.py index 3d07361027..59d2dee441 100644 --- a/build_tools/math/generate_ChloDecompositionPatternsMath.py +++ b/build_tools/math/generate_ChloDecompositionPatternsMath.py @@ -99,6 +99,7 @@ def main(kind="CHLO"): ("CHLO_SquareOp", "real_square", ("x:float",)), ("StableHLO_Log1pOp", "complex_log1p", ("z:complex",)), ("StableHLO_SqrtOp", "complex_sqrt", ("z:complex",)), + ("StableHLO_LogOp", "complex_log", ("z:complex",)), ]: if not chloname.startswith(kind): continue diff --git a/build_tools/math/generate_tests.py b/build_tools/math/generate_tests.py index 8583eeb997..b8c5bec4b9 100644 --- a/build_tools/math/generate_tests.py +++ b/build_tools/math/generate_tests.py @@ -72,6 +72,10 @@ mpmath_name="log1p", namespace="stablehlo", passes="--stablehlo-complex-math-expander"), + dict(name="log", + mpmath_name="log", + namespace="stablehlo", + passes="--stablehlo-complex-math-expander"), dict(name="sqrt", mpmath_name="sqrt", namespace="stablehlo", @@ -117,8 +121,8 @@ def main(): if fa_version < required_fa_version: msg = ( - f"functional_algorithm version {'.'.join(map(str, required_fa_version))}" - f" or newer is required, got {fa.__version__}") + f"functional_algorithms version {'.'.join(map(str, required_fa_version))}" + f" or newer is required, got {fa.__version__}, stopping.") warnings.warn(msg) return diff --git a/stablehlo/tests/math/log_complex128.mlir b/stablehlo/tests/math/log_complex128.mlir new file mode 100644 index 0000000000..7dad5a2f7f --- /dev/null +++ b/stablehlo/tests/math/log_complex128.mlir @@ -0,0 +1,19 @@ +// RUN: stablehlo-opt --stablehlo-complex-math-expander %s | stablehlo-translate --interpret +// This file is generated, see build_tools/math/README.md for more information. +module @log_complex128 { + func.func private @samples() -> tensor<169xcomplex> { + %0 = stablehlo.constant dense<"0x000000000000F0FF000000000000F0FFFFFFFFFFFFFFEFFF000000000000F0FFFEFFFFFFFFFFEFFF000000000000F0FF000000000000F8BF000000000000F0FF000000000000FC9F000000000000F0FF0100000000000080000000000000F0FF0000000000000000000000000000F0FF0100000000000000000000000000F0FF000000000000FC1F000000000000F0FF000000000000F83F000000000000F0FFFEFFFFFFFFFFEF7F000000000000F0FFFFFFFFFFFFFFEF7F000000000000F0FF000000000000F07F000000000000F0FF000000000000F0FFFFFFFFFFFFFFEFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFEFFFFEFFFFFFFFFFEFFFFFFFFFFFFFFFEFFF000000000000F8BFFFFFFFFFFFFFEFFF000000000000FC9FFFFFFFFFFFFFEFFF0100000000000080FFFFFFFFFFFFEFFF0000000000000000FFFFFFFFFFFFEFFF0100000000000000FFFFFFFFFFFFEFFF000000000000FC1FFFFFFFFFFFFFEFFF000000000000F83FFFFFFFFFFFFFEFFFFEFFFFFFFFFFEF7FFFFFFFFFFFFFEFFFFFFFFFFFFFFFEF7FFFFFFFFFFFFFEFFF000000000000F07FFFFFFFFFFFFFEFFF000000000000F0FFFEFFFFFFFFFFEFFFFFFFFFFFFFFFEFFFFEFFFFFFFFFFEFFFFEFFFFFFFFFFEFFFFEFFFFFFFFFFEFFF000000000000F8BFFEFFFFFFFFFFEFFF000000000000FC9FFEFFFFFFFFFFEFFF0100000000000080FEFFFFFFFFFFEFFF0000000000000000FEFFFFFFFFFFEFFF0100000000000000FEFFFFFFFFFFEFFF000000000000FC1FFEFFFFFFFFFFEFFF000000000000F83FFEFFFFFFFFFFEFFFFEFFFFFFFFFFEF7FFEFFFFFFFFFFEFFFFFFFFFFFFFFFEF7FFEFFFFFFFFFFEFFF000000000000F07FFEFFFFFFFFFFEFFF000000000000F0FF000000000000F8BFFFFFFFFFFFFFEFFF000000000000F8BFFEFFFFFFFFFFEFFF000000000000F8BF000000000000F8BF000000000000F8BF000000000000FC9F000000000000F8BF0100000000000080000000000000F8BF0000000000000000000000000000F8BF0100000000000000000000000000F8BF000000000000FC1F000000000000F8BF000000000000F83F000000000000F8BFFEFFFFFFFFFFEF7F000000000000F8BFFFFFFFFFFFFFEF7F000000000000F8BF000000000000F07F000000000000F8BF000000000000F0FF000000000000FC9FFFFFFFFFFFFFEFFF000000000000FC9FFEFFFFFFFFFFEFFF000000000000FC9F000000000000F8BF000000000000FC9F000000000000FC9F000000000000FC9F0100000000000080000000000000FC9F0000000000000000000000000000FC9F0100000000000000000000000000FC9F000000000000FC1F000000000000FC9F000000000000F83F000000000000FC9FFEFFFFFFFFFFEF7F000000000000FC9FFFFFFFFFFFFFEF7F000000000000FC9F000000000000F07F000000000000FC9F000000000000F0FF0100000000000080FFFFFFFFFFFFEFFF0100000000000080FEFFFFFFFFFFEFFF0100000000000080000000000000F8BF0100000000000080000000000000FC9F0100000000000080010000000000008001000000000000800000000000000000010000000000008001000000000000000100000000000080000000000000FC1F0100000000000080000000000000F83F0100000000000080FEFFFFFFFFFFEF7F0100000000000080FFFFFFFFFFFFEF7F0100000000000080000000000000F07F0100000000000080000000000000F0FF0000000000000000FFFFFFFFFFFFEFFF0000000000000000FEFFFFFFFFFFEFFF0000000000000000000000000000F8BF0000000000000000000000000000FC9F0000000000000000010000000000008000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000FC1F0000000000000000000000000000F83F0000000000000000FEFFFFFFFFFFEF7F0000000000000000FFFFFFFFFFFFEF7F0000000000000000000000000000F07F0000000000000000000000000000F0FF0100000000000000FFFFFFFFFFFFEFFF0100000000000000FEFFFFFFFFFFEFFF0100000000000000000000000000F8BF0100000000000000000000000000FC9F0100000000000000010000000000008001000000000000000000000000000000010000000000000001000000000000000100000000000000000000000000FC1F0100000000000000000000000000F83F0100000000000000FEFFFFFFFFFFEF7F0100000000000000FFFFFFFFFFFFEF7F0100000000000000000000000000F07F0100000000000000000000000000F0FF000000000000FC1FFFFFFFFFFFFFEFFF000000000000FC1FFEFFFFFFFFFFEFFF000000000000FC1F000000000000F8BF000000000000FC1F000000000000FC9F000000000000FC1F0100000000000080000000000000FC1F0000000000000000000000000000FC1F0100000000000000000000000000FC1F000000000000FC1F000000000000FC1F000000000000F83F000000000000FC1FFEFFFFFFFFFFEF7F000000000000FC1FFFFFFFFFFFFFEF7F000000000000FC1F000000000000F07F000000000000FC1F000000000000F0FF000000000000F83FFFFFFFFFFFFFEFFF000000000000F83FFEFFFFFFFFFFEFFF000000000000F83F000000000000F8BF000000000000F83F000000000000FC9F000000000000F83F0100000000000080000000000000F83F0000000000000000000000000000F83F0100000000000000000000000000F83F000000000000FC1F000000000000F83F000000000000F83F000000000000F83FFEFFFFFFFFFFEF7F000000000000F83FFFFFFFFFFFFFEF7F000000000000F83F000000000000F07F000000000000F83F000000000000F0FFFEFFFFFFFFFFEF7FFFFFFFFFFFFFEFFFFEFFFFFFFFFFEF7FFEFFFFFFFFFFEFFFFEFFFFFFFFFFEF7F000000000000F8BFFEFFFFFFFFFFEF7F000000000000FC9FFEFFFFFFFFFFEF7F0100000000000080FEFFFFFFFFFFEF7F0000000000000000FEFFFFFFFFFFEF7F0100000000000000FEFFFFFFFFFFEF7F000000000000FC1FFEFFFFFFFFFFEF7F000000000000F83FFEFFFFFFFFFFEF7FFEFFFFFFFFFFEF7FFEFFFFFFFFFFEF7FFFFFFFFFFFFFEF7FFEFFFFFFFFFFEF7F000000000000F07FFEFFFFFFFFFFEF7F000000000000F0FFFFFFFFFFFFFFEF7FFFFFFFFFFFFFEFFFFFFFFFFFFFFFEF7FFEFFFFFFFFFFEFFFFFFFFFFFFFFFEF7F000000000000F8BFFFFFFFFFFFFFEF7F000000000000FC9FFFFFFFFFFFFFEF7F0100000000000080FFFFFFFFFFFFEF7F0000000000000000FFFFFFFFFFFFEF7F0100000000000000FFFFFFFFFFFFEF7F000000000000FC1FFFFFFFFFFFFFEF7F000000000000F83FFFFFFFFFFFFFEF7FFEFFFFFFFFFFEF7FFFFFFFFFFFFFEF7FFFFFFFFFFFFFEF7FFFFFFFFFFFFFEF7F000000000000F07FFFFFFFFFFFFFEF7F000000000000F0FF000000000000F07FFFFFFFFFFFFFEFFF000000000000F07FFEFFFFFFFFFFEFFF000000000000F07F000000000000F8BF000000000000F07F000000000000FC9F000000000000F07F0100000000000080000000000000F07F0000000000000000000000000000F07F0100000000000000000000000000F07F000000000000FC1F000000000000F07F000000000000F83F000000000000F07FFEFFFFFFFFFFEF7F000000000000F07FFFFFFFFFFFFFEF7F000000000000F07F000000000000F07F000000000000F07F"> : tensor<169xcomplex> + return %0 : tensor<169xcomplex> + } + func.func private @expected() -> tensor<169xcomplex> { + %0 = stablehlo.constant dense<"0x000000000000F07FD221337F7CD902C0000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21F9BF000000000000F07F182D4454FB21E9BF000000000000F07F182D4454FB2109C036195AC708318640D221337F7CD902C036195AC708318640D221337F7CD902C0EF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BF36195AC708318640192D4454FB21E9BF36195AC708318640182D4454FB21E9BF000000000000F07F0000000000000000000000000000F07F182D4454FB2109C036195AC708318640D221337F7CD902C036195AC708318640D221337F7CD902C0EF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BFEF39FAFE422E8640182D4454FB21F9BF36195AC708318640182D4454FB21E9BF36195AC708318640182D4454FB21E9BF000000000000F07F0000000000000000000000000000F07F182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C01EE9DC75B310E83FD221337F7CD902C04C98BFEC23F3D93F182D4454FB21F9BF4C98BFEC23F3D93F182D4454FB21F9BF4C98BFEC23F3D93F182D4454FB21F9BF4C98BFEC23F3D93F182D4454FB21F9BF4C98BFEC23F3D93F182D4454FB21F9BF1EE9DC75B310E83F182D4454FB21E9BFEF39FAFE422E86400000000000000680EF39FAFE422E86400000000000000680000000000000F07F0000000000000000000000000000F07F182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C04C98BFEC23F3D93F182D4454FB2109C040438B3EC31F76C0D221337F7CD902C0CF014BCF4E2576C0182D4454FB21F9BFCF014BCF4E2576C0182D4454FB21F9BFCF014BCF4E2576C0182D4454FB21F9BF40438B3EC31F76C0182D4454FB21E9BF4C98BFEC23F3D93FABAAAAAAAAAAF29FEF39FAFE422E86400000000000000080EF39FAFE422E86400000000000000080000000000000F07F0000000000000000000000000000F07F182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C0EF39FAFE422E8640182D4454FB2109C04C98BFEC23F3D93F182D4454FB2109C0CF014BCF4E2576C0182D4454FB2109C07C920D7CBF4087C0D221337F7CD902C0C3716D44854387C0182D4454FB21F9BF7C920D7CBF4087C0182D4454FB21E9BFCF014BCF4E2576C0922449922449C29C4C98BFEC23F3D93F0000000000000080EF39FAFE422E86400000000000000080EF39FAFE422E86400000000000000080000000000000F07F0000000000000000000000000000F07F182D4454FB210940EF39FAFE422E8640182D4454FB210940EF39FAFE422E8640182D4454FB2109404C98BFEC23F3D93F182D4454FB210940CF014BCF4E2576C0182D4454FB210940C3716D44854387C0182D4454FB210940000000000000F0FF0000000000000000C3716D44854387C00000000000000000CF014BCF4E2576C000000000000000004C98BFEC23F3D93F0000000000000000EF39FAFE422E86400000000000000000EF39FAFE422E86400000000000000000000000000000F07F0000000000000000000000000000F07F182D4454FB210940EF39FAFE422E8640182D4454FB210940EF39FAFE422E8640182D4454FB2109404C98BFEC23F3D93F182D4454FB210940CF014BCF4E2576C0182D4454FB2109407C920D7CBF4087C0D221337F7CD90240C3716D44854387C0182D4454FB21F93F7C920D7CBF4087C0182D4454FB21E93FCF014BCF4E2576C0922449922449C21C4C98BFEC23F3D93F0000000000000000EF39FAFE422E86400000000000000000EF39FAFE422E86400000000000000000000000000000F07F0000000000000000000000000000F07F182D4454FB210940EF39FAFE422E8640182D4454FB210940EF39FAFE422E8640182D4454FB2109404C98BFEC23F3D93F182D4454FB21094040438B3EC31F76C0D221337F7CD90240CF014BCF4E2576C0182D4454FB21F93FCF014BCF4E2576C0182D4454FB21F93FCF014BCF4E2576C0182D4454FB21F93F40438B3EC31F76C0182D4454FB21E93F4C98BFEC23F3D93FABAAAAAAAAAAF21FEF39FAFE422E86400000000000000000EF39FAFE422E86400000000000000000000000000000F07F0000000000000000000000000000F07F182D4454FB210940EF39FAFE422E8640182D4454FB210940EF39FAFE422E8640182D4454FB2109401EE9DC75B310E83FD221337F7CD902404C98BFEC23F3D93F182D4454FB21F93F4C98BFEC23F3D93F182D4454FB21F93F4C98BFEC23F3D93F182D4454FB21F93F4C98BFEC23F3D93F182D4454FB21F93F4C98BFEC23F3D93F182D4454FB21F93F1EE9DC75B310E83F182D4454FB21E93FEF39FAFE422E86400000000000000600EF39FAFE422E86400000000000000600000000000000F07F0000000000000000000000000000F07F182D4454FB21094036195AC708318640D221337F7CD9024036195AC708318640D221337F7CD90240EF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93F36195AC708318640182D4454FB21E93F36195AC708318640182D4454FB21E93F000000000000F07F0000000000000000000000000000F07F182D4454FB21094036195AC708318640D221337F7CD9024036195AC708318640D221337F7CD90240EF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93FEF39FAFE422E8640182D4454FB21F93F36195AC708318640192D4454FB21E93F36195AC708318640182D4454FB21E93F000000000000F07F0000000000000000000000000000F07FD221337F7CD90240000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21F93F000000000000F07F182D4454FB21E93F"> : tensor<169xcomplex> + return %0 : tensor<169xcomplex> + } + func.func public @main() { + %0 = call @samples() : () -> tensor<169xcomplex> + %1 = "stablehlo.log"(%0) : (tensor<169xcomplex>) -> tensor<169xcomplex> + %2 = call @expected() : () -> tensor<169xcomplex> + check.expect_close %1, %2, max_ulp_difference = 3 : tensor<169xcomplex>, tensor<169xcomplex> + func.return + } +} diff --git a/stablehlo/tests/math/log_complex64.mlir b/stablehlo/tests/math/log_complex64.mlir new file mode 100644 index 0000000000..8cd409199b --- /dev/null +++ b/stablehlo/tests/math/log_complex64.mlir @@ -0,0 +1,19 @@ +// RUN: stablehlo-opt --stablehlo-complex-math-expander %s | stablehlo-translate --interpret +// This file is generated, see build_tools/math/README.md for more information. +module @log_complex64 { + func.func private @samples() -> tensor<169xcomplex> { + %0 = stablehlo.constant dense<"0x000080FF000080FFFFFF7FFF000080FFFEFF7FFF000080FF0000C0BF000080FF0000E09F000080FF01000080000080FF00000000000080FF01000000000080FF0000E01F000080FF0000C03F000080FFFEFF7F7F000080FFFFFF7F7F000080FF0000807F000080FF000080FFFFFF7FFFFFFF7FFFFFFF7FFFFEFF7FFFFFFF7FFF0000C0BFFFFF7FFF0000E09FFFFF7FFF01000080FFFF7FFF00000000FFFF7FFF01000000FFFF7FFF0000E01FFFFF7FFF0000C03FFFFF7FFFFEFF7F7FFFFF7FFFFFFF7F7FFFFF7FFF0000807FFFFF7FFF000080FFFEFF7FFFFFFF7FFFFEFF7FFFFEFF7FFFFEFF7FFF0000C0BFFEFF7FFF0000E09FFEFF7FFF01000080FEFF7FFF00000000FEFF7FFF01000000FEFF7FFF0000E01FFEFF7FFF0000C03FFEFF7FFFFEFF7F7FFEFF7FFFFFFF7F7FFEFF7FFF0000807FFEFF7FFF000080FF0000C0BFFFFF7FFF0000C0BFFEFF7FFF0000C0BF0000C0BF0000C0BF0000E09F0000C0BF010000800000C0BF000000000000C0BF010000000000C0BF0000E01F0000C0BF0000C03F0000C0BFFEFF7F7F0000C0BFFFFF7F7F0000C0BF0000807F0000C0BF000080FF0000E09FFFFF7FFF0000E09FFEFF7FFF0000E09F0000C0BF0000E09F0000E09F0000E09F010000800000E09F000000000000E09F010000000000E09F0000E01F0000E09F0000C03F0000E09FFEFF7F7F0000E09FFFFF7F7F0000E09F0000807F0000E09F000080FF01000080FFFF7FFF01000080FEFF7FFF010000800000C0BF010000800000E09F010000800100008001000080000000000100008001000000010000800000E01F010000800000C03F01000080FEFF7F7F01000080FFFF7F7F010000800000807F01000080000080FF00000000FFFF7FFF00000000FEFF7FFF000000000000C0BF000000000000E09F000000000100008000000000000000000000000001000000000000000000E01F000000000000C03F00000000FEFF7F7F00000000FFFF7F7F000000000000807F00000000000080FF01000000FFFF7FFF01000000FEFF7FFF010000000000C0BF010000000000E09F010000000100008001000000000000000100000001000000010000000000E01F010000000000C03F01000000FEFF7F7F01000000FFFF7F7F010000000000807F01000000000080FF0000E01FFFFF7FFF0000E01FFEFF7FFF0000E01F0000C0BF0000E01F0000E09F0000E01F010000800000E01F000000000000E01F010000000000E01F0000E01F0000E01F0000C03F0000E01FFEFF7F7F0000E01FFFFF7F7F0000E01F0000807F0000E01F000080FF0000C03FFFFF7FFF0000C03FFEFF7FFF0000C03F0000C0BF0000C03F0000E09F0000C03F010000800000C03F000000000000C03F010000000000C03F0000E01F0000C03F0000C03F0000C03FFEFF7F7F0000C03FFFFF7F7F0000C03F0000807F0000C03F000080FFFEFF7F7FFFFF7FFFFEFF7F7FFEFF7FFFFEFF7F7F0000C0BFFEFF7F7F0000E09FFEFF7F7F01000080FEFF7F7F00000000FEFF7F7F01000000FEFF7F7F0000E01FFEFF7F7F0000C03FFEFF7F7FFEFF7F7FFEFF7F7FFFFF7F7FFEFF7F7F0000807FFEFF7F7F000080FFFFFF7F7FFFFF7FFFFFFF7F7FFEFF7FFFFFFF7F7F0000C0BFFFFF7F7F0000E09FFFFF7F7F01000080FFFF7F7F00000000FFFF7F7F01000000FFFF7F7F0000E01FFFFF7F7F0000C03FFFFF7F7FFEFF7F7FFFFF7F7FFFFF7F7FFFFF7F7F0000807FFFFF7F7F000080FF0000807FFFFF7FFF0000807FFEFF7FFF0000807F0000C0BF0000807F0000E09F0000807F010000800000807F000000000000807F010000000000807F0000E01F0000807F0000C03F0000807FFEFF7F7F0000807FFFFF7F7F0000807F0000807F0000807F"> : tensor<169xcomplex> + return %0 : tensor<169xcomplex> + } + func.func private @expected() -> tensor<169xcomplex> { + %0 = stablehlo.constant dense<"0x0000807FE4CB16C00000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0FC9BF0000807FDB0F49BF0000807FDB0F49C08A23B242E4CB16C08A23B242E4CB16C01872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF8A23B242DB0F49BF8A23B242DB0F49BF0000807F000000000000807FDB0F49C08A23B242E4CB16C08A23B242E4CB16C01872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF1872B142DB0FC9BF8A23B242DB0F49BF8A23B242DA0F49BF0000807F000000000000807FDB0F49C01872B142DB0F49C01872B142DB0F49C09C85403FE4CB16C01F99CF3EDB0FC9BF1F99CF3EDB0FC9BF1F99CF3EDB0FC9BF1F99CF3EDB0FC9BF1F99CF3EDB0FC9BF9C85403FDB0F49BF1872B142000030801872B142000030800000807F000000000000807FDB0F49C01872B142DB0F49C01872B142DB0F49C01F99CF3EDB0F49C028D22DC2E4CB16C00C352FC2DB0FC9BF0C352FC2DB0FC9BF0C352FC2DB0FC9BF28D22DC2DB0F49BF1F99CF3E5555959F1872B142000000801872B142000000800000807F000000000000807FDB0F49C01872B142DB0F49C01872B142DB0F49C01F99CF3EDB0F49C00C352FC2DB0F49C05EDDCDC2E4CB16C0D08ECEC2DB0FC9BF5EDDCDC2DB0F49BF0C352FC2254992941F99CF3E000000801872B142000000801872B142000000800000807F000000000000807FDB0F49401872B142DB0F49401872B142DB0F49401F99CF3EDB0F49400C352FC2DB0F4940D08ECEC2DB0F4940000080FF00000000D08ECEC2000000000C352FC2000000001F99CF3E000000001872B142000000001872B142000000000000807F000000000000807FDB0F49401872B142DB0F49401872B142DB0F49401F99CF3EDB0F49400C352FC2DB0F49405EDDCDC2E4CB1640D08ECEC2DB0FC93F5EDDCDC2DB0F493F0C352FC2254992141F99CF3E000000001872B142000000001872B142000000000000807F000000000000807FDB0F49401872B142DB0F49401872B142DB0F49401F99CF3EDB0F494028D22DC2E4CB16400C352FC2DB0FC93F0C352FC2DB0FC93F0C352FC2DB0FC93F28D22DC2DB0F493F1F99CF3E5555951F1872B142000000001872B142000000000000807F000000000000807FDB0F49401872B142DB0F49401872B142DB0F49409C85403FE4CB16401F99CF3EDB0FC93F1F99CF3EDB0FC93F1F99CF3EDB0FC93F1F99CF3EDB0FC93F1F99CF3EDB0FC93F9C85403FDB0F493F1872B142000030001872B142000030000000807F000000000000807FDB0F49408A23B242E4CB16408A23B242E4CB16401872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F8A23B242DB0F493F8A23B242DA0F493F0000807F000000000000807FDB0F49408A23B242E4CB16408A23B242E4CB16401872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F1872B142DB0FC93F8A23B242DB0F493F8A23B242DB0F493F0000807F000000000000807FE4CB16400000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0FC93F0000807FDB0F493F"> : tensor<169xcomplex> + return %0 : tensor<169xcomplex> + } + func.func public @main() { + %0 = call @samples() : () -> tensor<169xcomplex> + %1 = "stablehlo.log"(%0) : (tensor<169xcomplex>) -> tensor<169xcomplex> + %2 = call @expected() : () -> tensor<169xcomplex> + check.expect_close %1, %2, max_ulp_difference = 3 : tensor<169xcomplex>, tensor<169xcomplex> + func.return + } +} diff --git a/stablehlo/tests/math/log_float32.mlir b/stablehlo/tests/math/log_float32.mlir new file mode 100644 index 0000000000..5858e8ea82 --- /dev/null +++ b/stablehlo/tests/math/log_float32.mlir @@ -0,0 +1,19 @@ +// RUN: stablehlo-opt --stablehlo-complex-math-expander %s | stablehlo-translate --interpret +// This file is generated, see build_tools/math/README.md for more information. +module @log_float32 { + func.func private @samples() -> tensor<169xf32> { + %0 = stablehlo.constant dense<"0x000080FFFFFF7FFFFEFF7FFF05E763FC88DAD5FA0BCE47F98EC1B9F711B52BF695A89DF4189C0FF39B8F81F11E83F3EFA17665EE246AD7ECA75D49EB2B51BBE9AE442DE831389FE6B42B11E5371F83E3BA12F5E13D0667E0C1F9D8DE44ED4ADDC7E0BCDB4AD42EDACDC7A0D850BB12D7D3AE84D557A2F6D3DA9568D25D89DAD0E07C4CCF6370BECDE66330CC6957A2CAED4A14C9703E86C7F331F8C576256AC4F918DCC27C0C4EC10000C0BF83F331BE06E7A3BC89DA15BB0CCE87B98FC1F9B712B56BB696A8DDB4199C4FB39C8FC1B11F8333B0A276A5AE256A17ADA85D89AB2C51FBA9AF446DA83238DFA6B52B51A5381FC3A3BB1235A23E06A7A0C2F9189F45ED8A9DC8E0FC9B4BD46E9ACEC7E09851BB5297D4AEC49558A23694DB95A8925E891A91E17C8C8F6470FE8DE763708C6A57E28AEE4A5489713EC687F43138867725AA84FA181C837D0C8E810100008000000000010000007D0C8E01FA181C037725AA04F4313806713EC607EE4A54096A57E20AE763700C6470FE0DE17C8C0F5E891A11DB95A81258A23614D4AEC41551BB5217CEC7E0184BD46E1AC8E0FC1B45ED8A1DC2F9181F3E06A720BB123522381FC323B52B51253238DF26AF446D282C51FB29A85D892B256A172DA276A52E1F8333309C8FC131199C4F3396A8DD3412B56B368FC1F9370CCE873989DA153B06E7A33C83F3313E0000C03F7C0C4E41F918DC4276256A44F331F845703E8647ED4A14496957A24AE663304C6370BE4DE07C4C4F5D89DA50DA95685257A2F653D3AE845550BB1257CDC7A0584AD42E5AC7E0BC5B44ED4A5DC1F9D85E3D066760BA12F561371F8363B42B116531389F66AE442D682B51BB69A75D496B246AD76CA176656E1E83F36F9B8F8171189C0F7395A89D7411B52B768EC1B9770BCE477988DAD57A05E7637CFEFF7F7FFFFF7F7F0000807F"> : tensor<169xf32> + return %0 : tensor<169xf32> + } + func.func private @expected() -> tensor<169xf32> { + %0 = stablehlo.constant dense<"0x0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F0000C07F000080FFD08ECEC235B1ABC23F58A7C27303A3C228B29EC2D9639AC21E1896C2A3CE91C221878DC2604189C2E8E584C26F8C80C26C6E78C21CCB6FC2E02D67C2E1955EC2710256C204734DC223E744C257353CC25A8133C208D62AC2FC3122C21F9419C294FB10C2AA6708C2A1AFFFC12097EEC1FE3DDDC1E0D3CBC1767BBAC1DE31A9C1DBF497C1A9C286C1BC336BC1A1F248C11BC026C1222304C10F95C2C058587AC0C4FEDFBF1F99CF3EB58D2340F76D9640A3F3DA40E1AD0F412E3532413E12554162CA7741DD318D4181719E41F9A5AF41BFD0C0410BF3D141DA0DE3417846F441A4DB02429E8A0B42BF3114423ED21C420E6D2542F3022E428B94364257223F4208B947429B7250428B2259427ACA6142A96B6A4210077342799D7B42C2178242DB5E864257A78A42BA048F422F5D934290B1974281029C428150A042F89BA44238E5A8421872B1421872B1420000807F"> : tensor<169xf32> + return %0 : tensor<169xf32> + } + func.func public @main() { + %0 = call @samples() : () -> tensor<169xf32> + %1 = "stablehlo.log"(%0) : (tensor<169xf32>) -> tensor<169xf32> + %2 = call @expected() : () -> tensor<169xf32> + check.expect_close %1, %2, max_ulp_difference = 3 : tensor<169xf32>, tensor<169xf32> + func.return + } +} diff --git a/stablehlo/tests/math/log_float64.mlir b/stablehlo/tests/math/log_float64.mlir new file mode 100644 index 0000000000..e007c6072a --- /dev/null +++ b/stablehlo/tests/math/log_float64.mlir @@ -0,0 +1,19 @@ +// RUN: stablehlo-opt --stablehlo-complex-math-expander %s | stablehlo-translate --interpret +// This file is generated, see build_tools/math/README.md for more information. +module @log_float64 { + func.func private @samples() -> tensor<169xf64> { + %0 = stablehlo.constant dense<"0x000000000000F0FFFFFFFFFFFFFFEFFFFEFFFFFFFFFFEFFF2A51BB12B52BD1FCC0F9189C8FC141FB56A276256A57B2F9EC4AD4AE44ED22F882F331381F8393F6189C8FC1F91804F5AE44ED4AD4AE74F343ED4AD4AE44E5F1D995A85D89DA55F06F3E06E76370C6EE05E763703E0637ED9B8FC1F9189CA7EB31381F83F33118EAC7E07C0CCEC788E85D89DA95A85DF9E6F231381F83F369E588DA95A85D89DAE31E83F331381F4BE2B42B51BB12B5BBE04AD4AE44ED4A2CDFE07C0CCEC7E09CDD76256A57A2760DDC0CCEC7E07C0C7EDAA176256A57A2EED8371F83F331385FD7CDC7E07C0CCECFD563703E06E76340D4F9189C8FC1F9B0D28FC1F9189C8F21D1256A57A2762592CFBB12B52B51BB02CE50BB12B52B5173CCE663703E06E7E3CA7C0CCEC7E07C54C912B52B51BB12C5C7A85D89DA95A835C63E06E763703EA6C4D4AE44ED4AD416C36A57A276256A87C1000000000000F8BF95A85D89DA9568BE2B51BB12B52BD9BCC1F9189C8FC149BB57A276256A57BAB9ED4AD4AE44ED2AB883F331381F839BB6199C8FC1F9180CB5AF44ED4AD4AE7CB344ED4AD4AE44EDB1DA95A85D89DA5DB0703E06E76370CEAE06E763703E063FAD9C8FC1F9189CAFAB32381F83F33120AAC8E07C0CCEC790A85E89DA95A85D01A7F331381F83F371A589DA95A85D89E2A31F83F331381F53A2B52B51BB12B5C3A04BD4AE44ED4A349FE17C0CCEC7E0A49D77256A57A276159C0DCEC7E07C0C869AA276256A57A2F698381F83F331386797CEC7E07C0CCED79564703E06E7634894FA189C8FC1F9B89290C1F9189C8F2991266A57A276259A8FBC12B52B51BB0A8E51BB12B52B517B8CE763703E06E7EB8A7D0CCEC7E07C5C8913B52B51BB12CD87A95D89DA95A83D863F06E763703EAE84D5AE44ED4AD41E836B57A276256A8F810100000000000080000000000000000001000000000000006B57A276256A8F01D5AE44ED4AD41E033F06E763703EAE04A95D89DA95A83D0613B52B51BB12CD077D0CCEC7E07C5C09E763703E06E7EB0A51BB12B52B517B0CBC12B52B51BB0A0E266A57A276259A0F90C1F9189C8F2911FA189C8FC1F9B81264703E06E7634814CEC7E07C0CCED715381F83F331386717A276256A57A2F6180DCEC7E07C0C861A77256A57A276151CE17C0CCEC7E0A41D4BD4AE44ED4A341FB52B51BB12B5C3201F83F331381F532289DA95A85D89E223F331381F83F371255E89DA95A85D0127C8E07C0CCEC7902832381F83F331202A9C8FC1F9189CAF2B06E763703E063F2D703E06E76370CE2EDA95A85D89DA5D3044ED4AD4AE44ED31AF44ED4AD4AE7C33199C8FC1F9180C3583F331381F839B36ED4AD4AE44ED2A3857A276256A57BA39C1F9189C8FC1493B2B51BB12B52BD93C95A85D89DA95683E000000000000F83F6A57A276256A8741D4AE44ED4AD416433E06E763703EA644A85D89DA95A8354612B52B51BB12C5477C0CCEC7E07C5449E663703E06E7E34A50BB12B52B51734CBB12B52B51BB024E256A57A27625924F8FC1F9189C8F2151F9189C8FC1F9B05263703E06E7634054CDC7E07C0CCECF55371F83F331385F57A176256A57A2EE580CCEC7E07C0C7E5A76256A57A2760D5CE07C0CCEC7E09C5D4AD4AE44ED4A2C5FB42B51BB12B5BB601E83F331381F4B6288DA95A85D89DA63F231381F83F369655D89DA95A85DF966C7E07C0CCEC7886831381F83F331186A9B8FC1F9189CA76B05E763703E06376D6F3E06E76370C66ED995A85D89DA557043ED4AD4AE44E571AE44ED4AD4AE7473189C8FC1F918047582F331381F839376EC4AD4AE44ED227856A276256A57B279C0F9189C8FC1417B2A51BB12B52BD17CFEFFFFFFFFFFEF7FFFFFFFFFFFFFEF7F000000000000F07F"> : tensor<169xf64> + return %0 : tensor<169xf64> + } + func.func private @expected() -> tensor<169xf64> { + %0 = stablehlo.constant dense<"0x000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F87F000000000000F0FFC3716D44854387C05F00F11A3C9E85C06431B97DC11385C07A2B8E9D478984C023D7D381CEFE83C0C9435F32567483C0BFDC7FB7DEE982C00093091A685F82C0C91A6063F2D481C0EE60839D7D4A81C054611DD309C080C08A8E910F973580C097041CBE4A567FC0E66F3D9D69417EC0EC3986D88A2C7DC08CA10C8EAE177CC0DBFA34DED4027BC02F8BEFEBFDED79C050B8FEDC29D978C077EC46DA58C477C051D729108BAF76C0030BEFAEC09A75C046603CEBF98574C05013A1FE367173C0CE343728785C72C070E05FADBD4771C0D2BB9FDA073370C0C23E4509AE3C6EC0267EF44EF1126CC0D78D4CE405E969C07CEC5B641DBF67C075F322EC379565C062175B9A556B63C0BF8E9A8F764161C0244BF7DC352F5EC0296A90B785DB59C04A9053FDDC8755C0C014BE013C3451C034E2DC3B46C149C0169A5162251A41C0C68CAC852CE630C04C98BFEC23F3D93F5CF49AA59EB531408C923CE1A38141406B04AAE262284A40B79D659885675140CAF791C6CDBA5540B805264F090E5A40DB2D687637615E4041F9E6B72B5A614028F5F42DB48363405CC602A334AD6540B120AB90ACD66740F898DC621B006A40D029EE7580296C40BCBAF17D0D536E40FA8CABED7C3E7040D2CDA9AB715371406A4BB9EA646872405AB5C89B567D7340F67CDEAE469274408BCE051335A775404D8D39B621BC7640D6104D850CD17740D358D26BF5E578401260FD53DCFA7940E9298426C10F7B40B3147BCAA3247C405FE82C2584397D408000EE19624E7E403AD5E9893D637F402002F5290B3C8040F7E80A2A76C680402474D4B1DF5081402FEE4FAC47DB8140765BAC02AE658240E2AF129C12F08240BAAB665D757A83408BCCFD28D6048440B0634ADE348F8440C36F785991198540EF39FAFE422E8640EF39FAFE422E8640000000000000F07F"> : tensor<169xf64> + return %0 : tensor<169xf64> + } + func.func public @main() { + %0 = call @samples() : () -> tensor<169xf64> + %1 = "stablehlo.log"(%0) : (tensor<169xf64>) -> tensor<169xf64> + %2 = call @expected() : () -> tensor<169xf64> + check.expect_close %1, %2, max_ulp_difference = 3 : tensor<169xf64>, tensor<169xf64> + func.return + } +} diff --git a/stablehlo/transforms/StablehloComplexMathExpanderPatterns.td b/stablehlo/transforms/StablehloComplexMathExpanderPatterns.td index c488f16595..22e5dd4105 100644 --- a/stablehlo/transforms/StablehloComplexMathExpanderPatterns.td +++ b/stablehlo/transforms/StablehloComplexMathExpanderPatterns.td @@ -14,7 +14,7 @@ limitations under the License. ==============================================================================*/ // -// This file is generated using functional_algorithms tool (0.13.1). +// This file is generated using functional_algorithms tool (0.14.1.dev0+ge22be68.d20241231). // See build_tools/math/README.md for more information. include "mlir/IR/OpBase.td" @@ -501,3 +501,156 @@ def SqrtOp_ComplexElementType_ComplexMathExpander: Pat<(StableHLO_SqrtOp Complex $lt_y_constant_0, (StableHLO_NegOp $ay_div_u), $ay_div_u)))>; + +// Logarithm of z on complex input: +// +// log(x + I * y) = log(hypot(x, y)) + I * arctan2(y, x) +// +// where +// +// x and y are real and imaginary parts of the input to log1p, and +// I is imaginary unit. +// +// For evaluating the real part of log accurately on the whole +// complex plane, we'll use the following formula: +// +// Case A +// ------ +// +// If `hypot(x, y)` is close to one, we'll use Dekker product and +// 2Sum algorithm to double the precision of computations to minimize +// cancellation errors: +// +// xxh, xxl = square_dekker(x) +// yyh, yyl = square_dekker(y) +// s = -1 + x * x + y * y = sum_2sum([-1, yyh, xxh, yyl, xxl]) +// +// so that +// +// real(log(x + I * y)) = 1/2 * log1p(s) +// +// when abs(s) < 0.5. +// +// Case B +// ------ +// +// Otherwise, we'll use +// +// real(log(x + I * y)) = log(mx) + 1/2 * log1p((mn / mx) ** 2) +// +// where +// +// mx = max(abs(x), abs(y)) +// mn = min(abs(x), abs(y)) +// +// For `mx == mn == inf` or `mx == mn == 0` case, we'll define `mn / mx == 1`. +// +// +def LogOp_ComplexElementType_ComplexMathExpander: Pat<(StableHLO_LogOp ComplexElementType:$z), + (StableHLO_ComplexOp + (StableHLO_SelectOp + (StableHLO_CompareOp + (StableHLO_AbsOp + (StableHLO_AddOp:$sum_fast2sum_high + (StableHLO_AddOp:$add_fast2sum_high + (StableHLO_AddOp:$_add_fast2sum_high_0_ + (StableHLO_AddOp:$_add_fast2sum_high_1_ + (StableHLO_AddOp:$_add_fast2sum_high_2_ + (StableHLO_ConstantLike<"-1.0">:$constant_fneg1 (StableHLO_RealOp:$x $z)), + (StableHLO_SelectOp:$mxh + (StableHLO_CompareOp:$gt_square_dekker_high__square_dekker_high_0_ + (StableHLO_MulOp:$square_dekker_high + (StableHLO_ImagOp:$y $z), + $y), + (StableHLO_MulOp:$_square_dekker_high_0_ $x, $x), + StableHLO_ComparisonDirectionValue<"GT">, + (STABLEHLO_DEFAULT_COMPARISON_TYPE)), + $square_dekker_high, + $_square_dekker_high_0_)), + (StableHLO_SelectOp:$mnh $gt_square_dekker_high__square_dekker_high_0_, $_square_dekker_high_0_, $square_dekker_high)), + (StableHLO_AddOp:$square_dekker_low + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_NegOp $square_dekker_high), + (StableHLO_MulOp + (StableHLO_AddOp:$yh + (StableHLO_MulOp:$multiply_veltkamp_splitter_constant_y + (StableHLO_SelectOp:$veltkamp_splitter_constant + (StableHLO_CompareOp + (StableHLO_ConstantLikeMaxFiniteValue:$largest $x), + (StableHLO_ConstantLike<"1e+308"> $x), + StableHLO_ComparisonDirectionValue<"GT">, + (STABLEHLO_DEFAULT_COMPARISON_TYPE)), + (StableHLO_ConstantLike<"134217729"> $x), + (StableHLO_SelectOp + (StableHLO_CompareOp + $largest, + (StableHLO_ConstantLike<"1e+38"> $x), + StableHLO_ComparisonDirectionValue<"GT">, + (STABLEHLO_DEFAULT_COMPARISON_TYPE)), + (StableHLO_ConstantLike<"4097"> $x), + (StableHLO_ConstantLike<"65"> $x))), + $y), + (StableHLO_SubtractOp $y, $multiply_veltkamp_splitter_constant_y)), + $yh)), + (StableHLO_MulOp:$multiply_yh_yl + $yh, + (StableHLO_SubtractOp:$yl $y, $yh))), + $multiply_yh_yl), + (StableHLO_MulOp $yl, $yl))), + (StableHLO_AddOp:$_square_dekker_low_0_ + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_NegOp $_square_dekker_high_0_), + (StableHLO_MulOp + (StableHLO_AddOp:$xh + (StableHLO_MulOp:$multiply_veltkamp_splitter_constant_x $veltkamp_splitter_constant, $x), + (StableHLO_SubtractOp $x, $multiply_veltkamp_splitter_constant_x)), + $xh)), + (StableHLO_MulOp:$multiply_xh_xl + $xh, + (StableHLO_SubtractOp:$xl $x, $xh))), + $multiply_xh_xl), + (StableHLO_MulOp $xl, $xl))), + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_AddOp + (StableHLO_SubtractOp:$add_fast2sum_low + $mxh, + (StableHLO_SubtractOp $_add_fast2sum_high_2_, $constant_fneg1)), + (StableHLO_SubtractOp:$_add_fast2sum_low_0_ + $mnh, + (StableHLO_SubtractOp $_add_fast2sum_high_1_, $_add_fast2sum_high_2_))), + (StableHLO_SubtractOp:$_add_fast2sum_low_1_ + $square_dekker_low, + (StableHLO_SubtractOp $_add_fast2sum_high_0_, $_add_fast2sum_high_1_))), + (StableHLO_SubtractOp:$_add_fast2sum_low_2_ + $_square_dekker_low_0_, + (StableHLO_SubtractOp $add_fast2sum_high, $_add_fast2sum_high_0_))))), + (StableHLO_ConstantLike<"0.5">:$half $x), + StableHLO_ComparisonDirectionValue<"LT">, + (STABLEHLO_DEFAULT_COMPARISON_TYPE)), + (StableHLO_MulOp + $half, + (StableHLO_Log1pOp $sum_fast2sum_high)), + (StableHLO_AddOp + (StableHLO_LogOp + (StableHLO_MaxOp:$mx + (StableHLO_AbsOp:$abs_x $x), + (StableHLO_AbsOp:$abs_y $y))), + (StableHLO_MulOp + $half, + (StableHLO_Log1pOp + (StableHLO_MulOp + (StableHLO_SelectOp:$mn_over_mx + (StableHLO_CompareOp + (StableHLO_MinOp:$mn $abs_x, $abs_y), + $mx, + StableHLO_ComparisonDirectionValue<"EQ">, + (STABLEHLO_DEFAULT_COMPARISON_TYPE)), + (StableHLO_ConstantLike<"1.0"> $x), + (StableHLO_DivOp $mn, $mx)), + $mn_over_mx))))), + (StableHLO_Atan2Op $y, $x))>;