llvm-project/mlir/test/python/dialects/complex_dialect.py
Tobias Hieta f9008e6366
[NFC][Py Reformat] Reformat python files in mlir subdir
This is an ongoing series of commits that are reformatting our
Python code.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Differential Revision: https://reviews.llvm.org/D150782
2023-05-26 08:05:40 +02:00

33 lines
979 B
Python

# RUN: %PYTHON %s | FileCheck %s
# Naming this file with a `_dialect` suffix to avoid a naming conflict with
# python package's math module (coming in from random.py).
from mlir.ir import *
import mlir.dialects.func as func
import mlir.dialects.complex as mlir_complex
def run(f):
print("\nTEST:", f.__name__)
f()
# CHECK-LABEL: TEST: testComplexOps
@run
def testComplexOps():
with Context() as ctx, Location.unknown():
module = Module.create()
with InsertionPoint(module.body):
@func.FuncOp.from_py_func(ComplexType.get(F32Type.get()))
def emit_add(arg):
return mlir_complex.AddOp(arg, arg)
# CHECK-LABEL: func @emit_add(
# CHECK-SAME: %[[ARG:.*]]: complex<f32>) -> complex<f32> {
# CHECK: %[[RES:.*]] = complex.add %[[ARG]], %[[ARG]] : complex<f32>
# CHECK: return %[[RES]] : complex<f32>
# CHECK: }
print(module)