Skip to content

Complex

complex

ComplexTypeConstr = ComplexType.constr(AnyFloat) module-attribute

Complex = Dialect('complex', [AbsOp, AddOp, AngleOp, Atan2Op, BitcastOp, ConjOp, ConstantOp, CosOp, CreateOp, DivOp, EqualOp, ExpOp, Expm1Op, ImOp, LogOp, Log1pOp, MulOp, NegOp, NotEqualOp, PowOp, ReOp, RsqrtOp, SignOp, SinOp, SqrtOp, SubOp, TanOp, TanhOp], [ComplexNumberAttr], [ComplexConstantMaterializationInterface()]) module-attribute

ComplexNumberAttr dataclass

Bases: ParametrizedAttribute, Generic[_ComplexNumberElementType]

Source code in xdsl/dialects/complex.py
@irdl_attr_definition
class ComplexNumberAttr(ParametrizedAttribute, Generic[_ComplexNumberElementType]):
    name = "complex.number"

    real: FloatData = param_def(converter=FloatData.get)
    imag: FloatData = param_def(converter=FloatData.get)
    type: ComplexType[_ComplexNumberElementType]

    def print_parameters(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            printer.print_string(":")
            printer.print_attribute(self.type.element_type)
            printer.print_string(" ")
            printer.print_float(self.real.data, self.type.element_type)
            printer.print_string(", ")
            printer.print_float(self.imag.data, self.type.element_type)
        printer.print_string(" : ")
        printer.print_attribute(self.type)

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
        """
        Example:
        ```
        #complex.number<:f64 1.0, 2.0> : complex<f64>
        ```
        """
        with parser.in_angle_brackets():
            parser.parse_punctuation(":")
            pos = parser.pos
            element_type = parser.parse_type()
            if not isa(element_type, AnyFloat):
                parser.raise_error("Invalid element type", pos, parser.pos - 1)
            real = FloatData(parser.parse_float())
            parser.parse_punctuation(",")
            imag = FloatData(parser.parse_float())
        parser.parse_punctuation(":")
        pos = parser.pos
        complex_type = parser.parse_type()
        if not (
            isa(complex_type, ComplexType[AnyFloat])
            and (complex_type.element_type == element_type)
        ):
            parser.raise_error("Complex number type doesn't match element type", pos)
        return [
            real,
            imag,
            ComplexType(element_type),
        ]

name = 'complex.number' class-attribute instance-attribute

real: FloatData = param_def(converter=FloatData.get) class-attribute instance-attribute

imag: FloatData = param_def(converter=FloatData.get) class-attribute instance-attribute

type: ComplexType[_ComplexNumberElementType] instance-attribute

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/complex.py
def print_parameters(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        printer.print_string(":")
        printer.print_attribute(self.type.element_type)
        printer.print_string(" ")
        printer.print_float(self.real.data, self.type.element_type)
        printer.print_string(", ")
        printer.print_float(self.imag.data, self.type.element_type)
    printer.print_string(" : ")
    printer.print_attribute(self.type)

parse_parameters(parser: AttrParser) -> Sequence[Attribute] classmethod

Example:

#complex.number<:f64 1.0, 2.0> : complex<f64>

Source code in xdsl/dialects/complex.py
@classmethod
def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
    """
    Example:
    ```
    #complex.number<:f64 1.0, 2.0> : complex<f64>
    ```
    """
    with parser.in_angle_brackets():
        parser.parse_punctuation(":")
        pos = parser.pos
        element_type = parser.parse_type()
        if not isa(element_type, AnyFloat):
            parser.raise_error("Invalid element type", pos, parser.pos - 1)
        real = FloatData(parser.parse_float())
        parser.parse_punctuation(",")
        imag = FloatData(parser.parse_float())
    parser.parse_punctuation(":")
    pos = parser.pos
    complex_type = parser.parse_type()
    if not (
        isa(complex_type, ComplexType[AnyFloat])
        and (complex_type.element_type == element_type)
    ):
        parser.raise_error("Complex number type doesn't match element type", pos)
    return [
        real,
        imag,
        ComplexType(element_type),
    ]

ComplexUnaryComplexResultOperation

Bases: IRDLOperation, ABC

Base class for unary operations on complex numbers.

Source code in xdsl/dialects/complex.py
class ComplexUnaryComplexResultOperation(IRDLOperation, abc.ABC):
    """Base class for unary operations on complex numbers."""

    T: ClassVar = VarConstraint("T", ComplexTypeConstr)
    complex = operand_def(T)
    result = result_def(T)
    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))

    traits = traits_def(Pure())

    assembly_format = (
        "$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)"
    )

    def __init__(
        self,
        operand: OperandArg,
        fastmath: FastMathFlagsAttr | None = None,
    ):
        operand_ssa = SSAValue.get(operand)
        super().__init__(
            operands=[operand_ssa],
            result_types=[operand_ssa.type],
            properties={"fastmath": fastmath},
        )

T: ClassVar = VarConstraint('T', ComplexTypeConstr) class-attribute instance-attribute

complex = operand_def(T) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none')) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)' class-attribute instance-attribute

__init__(operand: OperandArg, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
def __init__(
    self,
    operand: OperandArg,
    fastmath: FastMathFlagsAttr | None = None,
):
    operand_ssa = SSAValue.get(operand)
    super().__init__(
        operands=[operand_ssa],
        result_types=[operand_ssa.type],
        properties={"fastmath": fastmath},
    )

ComplexUnaryRealResultOperation

Bases: IRDLOperation, ABC

Base class for unary operations on complex numbers that return a float.

Source code in xdsl/dialects/complex.py
class ComplexUnaryRealResultOperation(IRDLOperation, abc.ABC):
    """Base class for unary operations on complex numbers that return a float."""

    T: ClassVar = VarConstraint.get("T", AnyFloat)

    complex = operand_def(ComplexType.constr(T))
    result = result_def(T)
    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))

    traits = traits_def(Pure())

    assembly_format = (
        "$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)"
    )

    def __init__(
        self,
        operand: OperandArg,
        fastmath: FastMathFlagsAttr | None = None,
    ):
        operand_ssa = SSAValue.get(operand)
        element_type = cast(ComplexType, operand_ssa.type).element_type
        super().__init__(
            operands=[operand_ssa],
            result_types=[element_type],
            properties={"fastmath": fastmath},
        )

    def verify_(self):
        element_type = cast(ComplexType, self.complex.type).element_type
        if self.result.type != element_type:
            raise VerifyException(
                f"result type {self.result.type} does not match "
                f"complex element type {element_type}"
            )

T: ClassVar = VarConstraint.get('T', AnyFloat) class-attribute instance-attribute

complex = operand_def(ComplexType.constr(T)) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none')) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)' class-attribute instance-attribute

__init__(operand: OperandArg, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
def __init__(
    self,
    operand: OperandArg,
    fastmath: FastMathFlagsAttr | None = None,
):
    operand_ssa = SSAValue.get(operand)
    element_type = cast(ComplexType, operand_ssa.type).element_type
    super().__init__(
        operands=[operand_ssa],
        result_types=[element_type],
        properties={"fastmath": fastmath},
    )

verify_()

Source code in xdsl/dialects/complex.py
def verify_(self):
    element_type = cast(ComplexType, self.complex.type).element_type
    if self.result.type != element_type:
        raise VerifyException(
            f"result type {self.result.type} does not match "
            f"complex element type {element_type}"
        )

ComplexBinaryOp

Bases: IRDLOperation, HasFolderInterface, ABC

Base class for binary operations on complex numbers.

Source code in xdsl/dialects/complex.py
class ComplexBinaryOp(IRDLOperation, HasFolderInterface, abc.ABC):
    """Base class for binary operations on complex numbers."""

    T: ClassVar = VarConstraint("T", ComplexTypeConstr)
    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(T)
    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))

    traits = traits_def(Pure())

    assembly_format = (
        "$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)"
    )

    def __init__(
        self,
        lhs: OperandArg,
        rhs: OperandArg,
        fastmath: FastMathFlagsAttr | None = None,
    ):
        lhs_ssa = SSAValue.get(lhs)
        super().__init__(
            operands=[lhs_ssa, rhs],
            result_types=[lhs_ssa.type],
            properties={"fastmath": fastmath},
        )

    @staticmethod
    def py_operation(
        lhs: tuple[float, float], rhs: tuple[float, float]
    ) -> tuple[float, float] | None:
        """
        Performs a python function corresponding to this operation.

        If `i := py_operation(lhs, rhs)` is an tuple[float, float], then this operation can be
        canonicalized to a constant with value `i` when the inputs are constants
        with values `lhs` and `rhs`.
        """

    def fold(self) -> tuple[ArrayAttr[FloatAttr[AnyFloat]]] | None:
        lhs = ConstantLike.get_constant_value(self.lhs)
        rhs = ConstantLike.get_constant_value(self.rhs)
        if (
            lhs is not None
            and rhs is not None
            and isa(lhs, ArrayAttr[FloatAttr])
            and isa(rhs, ArrayAttr[FloatAttr])
        ):
            assert lhs.data[0].type == rhs.data[0].type
            assert lhs.data[1].type == rhs.data[1].type
            re_lhs, im_lhs = lhs.data[0].value.data, lhs.data[1].value.data
            re_rhs, im_rhs = rhs.data[0].value.data, rhs.data[1].value.data
            res = self.py_operation((re_lhs, im_lhs), (re_rhs, im_rhs))
            if res is not None:
                type = lhs.data[0].type
                return (ArrayAttr([FloatAttr(res[0], type), FloatAttr(res[1], type)]),)

T: ClassVar = VarConstraint('T', ComplexTypeConstr) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none')) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)' class-attribute instance-attribute

__init__(lhs: OperandArg, rhs: OperandArg, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
def __init__(
    self,
    lhs: OperandArg,
    rhs: OperandArg,
    fastmath: FastMathFlagsAttr | None = None,
):
    lhs_ssa = SSAValue.get(lhs)
    super().__init__(
        operands=[lhs_ssa, rhs],
        result_types=[lhs_ssa.type],
        properties={"fastmath": fastmath},
    )

py_operation(lhs: tuple[float, float], rhs: tuple[float, float]) -> tuple[float, float] | None staticmethod

Performs a python function corresponding to this operation.

If i := py_operation(lhs, rhs) is an tuple[float, float], then this operation can be canonicalized to a constant with value i when the inputs are constants with values lhs and rhs.

Source code in xdsl/dialects/complex.py
@staticmethod
def py_operation(
    lhs: tuple[float, float], rhs: tuple[float, float]
) -> tuple[float, float] | None:
    """
    Performs a python function corresponding to this operation.

    If `i := py_operation(lhs, rhs)` is an tuple[float, float], then this operation can be
    canonicalized to a constant with value `i` when the inputs are constants
    with values `lhs` and `rhs`.
    """

fold() -> tuple[ArrayAttr[FloatAttr[AnyFloat]]] | None

Source code in xdsl/dialects/complex.py
def fold(self) -> tuple[ArrayAttr[FloatAttr[AnyFloat]]] | None:
    lhs = ConstantLike.get_constant_value(self.lhs)
    rhs = ConstantLike.get_constant_value(self.rhs)
    if (
        lhs is not None
        and rhs is not None
        and isa(lhs, ArrayAttr[FloatAttr])
        and isa(rhs, ArrayAttr[FloatAttr])
    ):
        assert lhs.data[0].type == rhs.data[0].type
        assert lhs.data[1].type == rhs.data[1].type
        re_lhs, im_lhs = lhs.data[0].value.data, lhs.data[1].value.data
        re_rhs, im_rhs = rhs.data[0].value.data, rhs.data[1].value.data
        res = self.py_operation((re_lhs, im_lhs), (re_rhs, im_rhs))
        if res is not None:
            type = lhs.data[0].type
            return (ArrayAttr([FloatAttr(res[0], type), FloatAttr(res[1], type)]),)

ComplexCompareOp

Bases: IRDLOperation, ABC

Base class for comparison operations on complex numbers.

Source code in xdsl/dialects/complex.py
class ComplexCompareOp(IRDLOperation, abc.ABC):
    """Base class for comparison operations on complex numbers."""

    T: ClassVar = VarConstraint("T", ComplexTypeConstr)
    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(IntegerType(1))

    traits = traits_def(Pure())

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($lhs)"

    def __init__(self, lhs: OperandArg, rhs: OperandArg):
        super().__init__(operands=[lhs, rhs], result_types=[IntegerType(1)])

T: ClassVar = VarConstraint('T', ComplexTypeConstr) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

result = result_def(IntegerType(1)) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs attr-dict `:` type($lhs)' class-attribute instance-attribute

__init__(lhs: OperandArg, rhs: OperandArg)

Source code in xdsl/dialects/complex.py
def __init__(self, lhs: OperandArg, rhs: OperandArg):
    super().__init__(operands=[lhs, rhs], result_types=[IntegerType(1)])

AbsOp dataclass

Bases: ComplexUnaryRealResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class AbsOp(ComplexUnaryRealResultOperation):
    name = "complex.abs"

name = 'complex.abs' class-attribute instance-attribute

AddOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class AddOp(ComplexBinaryOp):
    name = "complex.add"

    traits = traits_def(Pure(), Commutative())

    traits = traits_def(
        Pure(),
        Commutative(),
    )

    @staticmethod
    def py_operation(
        lhs: tuple[float, float], rhs: tuple[float, float]
    ) -> tuple[float, float]:
        return (lhs[0] + rhs[0], lhs[1] + rhs[1])

name = 'complex.add' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative()) class-attribute instance-attribute

py_operation(lhs: tuple[float, float], rhs: tuple[float, float]) -> tuple[float, float] staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def py_operation(
    lhs: tuple[float, float], rhs: tuple[float, float]
) -> tuple[float, float]:
    return (lhs[0] + rhs[0], lhs[1] + rhs[1])

AngleOp dataclass

Bases: ComplexUnaryRealResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class AngleOp(ComplexUnaryRealResultOperation):
    name = "complex.angle"

name = 'complex.angle' class-attribute instance-attribute

Atan2Op dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class Atan2Op(ComplexBinaryOp):
    name = "complex.atan2"

name = 'complex.atan2' class-attribute instance-attribute

BitcastOp

Bases: IRDLOperation

compute between complex and and equal arith types

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class BitcastOp(IRDLOperation):
    """
    compute between complex and and equal arith types
    """

    name = "complex.bitcast"
    operand = operand_def(ComplexType[AnyFloat] | AnyFloat | IntegerType)
    result = result_def(ComplexType[AnyFloat] | AnyFloat | IntegerType)

    traits = traits_def(Pure())

    assembly_format = "$operand attr-dict `:` type($operand) `to` type($result)"

    def __init__(self, operand: OperandArg, result_type: Attribute):
        super().__init__(operands=[operand], result_types=[result_type])

    def verify_(self) -> None:
        in_type = self.operand.type
        res_type = self.result.type

        # We allow this to be legal as it can be folded away
        if in_type == res_type:
            return

        if in_complex := isa(in_type, ComplexType[AnyFloat]):
            in_bitwidth = in_type.element_type.bitwidth * 2
        else:
            in_bitwidth = cast(FixedBitwidthType, in_type).bitwidth

        if out_complex := isa(res_type, ComplexType[AnyFloat]):
            out_bitwidth = res_type.element_type.bitwidth * 2
        else:
            out_bitwidth = cast(FixedBitwidthType, res_type).bitwidth

        if not ((in_bitwidth == out_bitwidth) and (in_complex != out_complex)):
            raise VerifyException(
                f"Expected ('{in_type}', '{res_type}') to be bitcast between complex and equal arith types"
            )

name = 'complex.bitcast' class-attribute instance-attribute

operand = operand_def(ComplexType[AnyFloat] | AnyFloat | IntegerType) class-attribute instance-attribute

result = result_def(ComplexType[AnyFloat] | AnyFloat | IntegerType) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$operand attr-dict `:` type($operand) `to` type($result)' class-attribute instance-attribute

__init__(operand: OperandArg, result_type: Attribute)

Source code in xdsl/dialects/complex.py
def __init__(self, operand: OperandArg, result_type: Attribute):
    super().__init__(operands=[operand], result_types=[result_type])

verify_() -> None

Source code in xdsl/dialects/complex.py
def verify_(self) -> None:
    in_type = self.operand.type
    res_type = self.result.type

    # We allow this to be legal as it can be folded away
    if in_type == res_type:
        return

    if in_complex := isa(in_type, ComplexType[AnyFloat]):
        in_bitwidth = in_type.element_type.bitwidth * 2
    else:
        in_bitwidth = cast(FixedBitwidthType, in_type).bitwidth

    if out_complex := isa(res_type, ComplexType[AnyFloat]):
        out_bitwidth = res_type.element_type.bitwidth * 2
    else:
        out_bitwidth = cast(FixedBitwidthType, res_type).bitwidth

    if not ((in_bitwidth == out_bitwidth) and (in_complex != out_complex)):
        raise VerifyException(
            f"Expected ('{in_type}', '{res_type}') to be bitcast between complex and equal arith types"
        )

ConjOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class ConjOp(ComplexUnaryComplexResultOperation):
    name = "complex.conj"

name = 'complex.conj' class-attribute instance-attribute

ConstantOp

Bases: IRDLOperation, HasFolderInterface

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class ConstantOp(IRDLOperation, HasFolderInterface):
    name = "complex.constant"
    T: ClassVar = VarConstraint.get("T", AnyFloat | IntegerType)
    value = prop_def(
        ArrayOfConstraint(
            RangeOf(
                AnyOf.get(
                    ParamAttrConstraint(IntegerAttr, (AnyAttr(), T)),
                    ParamAttrConstraint(FloatAttr, (AnyAttr(), T)),
                )
            ).of_length(EqIntConstraint(2))
        )
    )

    # In contrast to other operations, `complex.constant` can
    # have any complex result type, not just floating point:
    complex = result_def(ComplexType.constr(T))

    traits = traits_def(Pure(), ConstantLike())

    assembly_format = "$value attr-dict `:` type($complex)"

    def __init__(self, value: ArrayAttr, result_type: ComplexType):
        super().__init__(properties={"value": value}, result_types=[result_type])

    def fold(self) -> tuple[Attribute]:
        return (self.value,)

    @staticmethod
    def from_floats(value: tuple[float, float], type: AnyFloat) -> ConstantOp:
        return ConstantOp(
            ArrayAttr([FloatAttr(value[0], type), FloatAttr(value[1], type)]),
            ComplexType(type),
        )

    @staticmethod
    def from_ints(value: tuple[int, int], type: IntegerType) -> ConstantOp:
        return ConstantOp(
            ArrayAttr([IntegerAttr(value[0], type), IntegerAttr(value[1], type)]),
            ComplexType(type),
        )

name = 'complex.constant' class-attribute instance-attribute

T: ClassVar = VarConstraint.get('T', AnyFloat | IntegerType) class-attribute instance-attribute

value = prop_def(ArrayOfConstraint(RangeOf(AnyOf.get(ParamAttrConstraint(IntegerAttr, (AnyAttr(), T)), ParamAttrConstraint(FloatAttr, (AnyAttr(), T)))).of_length(EqIntConstraint(2)))) class-attribute instance-attribute

complex = result_def(ComplexType.constr(T)) class-attribute instance-attribute

traits = traits_def(Pure(), ConstantLike()) class-attribute instance-attribute

assembly_format = '$value attr-dict `:` type($complex)' class-attribute instance-attribute

__init__(value: ArrayAttr, result_type: ComplexType)

Source code in xdsl/dialects/complex.py
def __init__(self, value: ArrayAttr, result_type: ComplexType):
    super().__init__(properties={"value": value}, result_types=[result_type])

fold() -> tuple[Attribute]

Source code in xdsl/dialects/complex.py
def fold(self) -> tuple[Attribute]:
    return (self.value,)

from_floats(value: tuple[float, float], type: AnyFloat) -> ConstantOp staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def from_floats(value: tuple[float, float], type: AnyFloat) -> ConstantOp:
    return ConstantOp(
        ArrayAttr([FloatAttr(value[0], type), FloatAttr(value[1], type)]),
        ComplexType(type),
    )

from_ints(value: tuple[int, int], type: IntegerType) -> ConstantOp staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def from_ints(value: tuple[int, int], type: IntegerType) -> ConstantOp:
    return ConstantOp(
        ArrayAttr([IntegerAttr(value[0], type), IntegerAttr(value[1], type)]),
        ComplexType(type),
    )

CosOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class CosOp(ComplexUnaryComplexResultOperation):
    name = "complex.cos"

name = 'complex.cos' class-attribute instance-attribute

CreateOp

Bases: IRDLOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class CreateOp(IRDLOperation):
    name = "complex.create"
    T: ClassVar = VarConstraint.get("T", AnyFloat)
    real = operand_def(T)
    imaginary = operand_def(T)
    complex = result_def(ComplexType.constr(T))

    traits = traits_def(Pure())

    assembly_format = "$real `,` $imaginary attr-dict `:` type($complex)"

    def __init__(
        self,
        real: OperandArg,
        imaginary: OperandArg,
        result_type: ComplexType,
    ):
        super().__init__(operands=[real, imaginary], result_types=[result_type])

name = 'complex.create' class-attribute instance-attribute

T: ClassVar = VarConstraint.get('T', AnyFloat) class-attribute instance-attribute

real = operand_def(T) class-attribute instance-attribute

imaginary = operand_def(T) class-attribute instance-attribute

complex = result_def(ComplexType.constr(T)) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$real `,` $imaginary attr-dict `:` type($complex)' class-attribute instance-attribute

__init__(real: OperandArg, imaginary: OperandArg, result_type: ComplexType)

Source code in xdsl/dialects/complex.py
def __init__(
    self,
    real: OperandArg,
    imaginary: OperandArg,
    result_type: ComplexType,
):
    super().__init__(operands=[real, imaginary], result_types=[result_type])

DivOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class DivOp(ComplexBinaryOp):
    name = "complex.div"

    traits = traits_def(
        Pure(),
    )

    @staticmethod
    def py_operation(
        lhs: tuple[float, float], rhs: tuple[float, float]
    ) -> tuple[float, float]:
        re_lhs, im_lhs = lhs
        re_rhs, im_rhs = rhs
        # 0.0 == -0.0 -> True
        if re_rhs == 0.0 and im_rhs == 0.0:
            inf = float("inf")
            if re_lhs == 0.0:
                real = float("nan")
            else:
                real = math.copysign(inf, re_lhs) / math.copysign(1.0, re_rhs)
            if im_lhs == 0.0:
                imag = float("nan")
            else:
                # Positive infinity if signs match, negative otherwise
                imag = math.copysign(inf, im_lhs) / math.copysign(1.0, im_rhs)
        else:
            real = (re_lhs * re_rhs + im_lhs * im_rhs) / (re_rhs**2 + im_rhs**2)
            imag = (im_lhs * re_rhs - re_lhs * im_rhs) / (re_rhs**2 + im_rhs**2)
        return (real, imag)

name = 'complex.div' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

py_operation(lhs: tuple[float, float], rhs: tuple[float, float]) -> tuple[float, float] staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def py_operation(
    lhs: tuple[float, float], rhs: tuple[float, float]
) -> tuple[float, float]:
    re_lhs, im_lhs = lhs
    re_rhs, im_rhs = rhs
    # 0.0 == -0.0 -> True
    if re_rhs == 0.0 and im_rhs == 0.0:
        inf = float("inf")
        if re_lhs == 0.0:
            real = float("nan")
        else:
            real = math.copysign(inf, re_lhs) / math.copysign(1.0, re_rhs)
        if im_lhs == 0.0:
            imag = float("nan")
        else:
            # Positive infinity if signs match, negative otherwise
            imag = math.copysign(inf, im_lhs) / math.copysign(1.0, im_rhs)
    else:
        real = (re_lhs * re_rhs + im_lhs * im_rhs) / (re_rhs**2 + im_rhs**2)
        imag = (im_lhs * re_rhs - re_lhs * im_rhs) / (re_rhs**2 + im_rhs**2)
    return (real, imag)

EqualOp dataclass

Bases: ComplexCompareOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class EqualOp(ComplexCompareOp):
    name = "complex.eq"

name = 'complex.eq' class-attribute instance-attribute

ExpOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class ExpOp(ComplexUnaryComplexResultOperation):
    name = "complex.exp"

name = 'complex.exp' class-attribute instance-attribute

Expm1Op dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class Expm1Op(ComplexUnaryComplexResultOperation):
    name = "complex.expm1"

name = 'complex.expm1' class-attribute instance-attribute

ImOp dataclass

Bases: ComplexUnaryRealResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class ImOp(ComplexUnaryRealResultOperation):
    name = "complex.im"

name = 'complex.im' class-attribute instance-attribute

LogOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class LogOp(ComplexUnaryComplexResultOperation):
    name = "complex.log"

name = 'complex.log' class-attribute instance-attribute

Log1pOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class Log1pOp(ComplexUnaryComplexResultOperation):
    name = "complex.log1p"

name = 'complex.log1p' class-attribute instance-attribute

MulOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class MulOp(ComplexBinaryOp):
    name = "complex.mul"

    traits = traits_def(
        Pure(),
        Commutative(),
    )

    @staticmethod
    def py_operation(
        lhs: tuple[float, float], rhs: tuple[float, float]
    ) -> tuple[float, float]:
        re_lhs, im_lhs = lhs
        re_rhs, im_rhs = rhs
        return (re_lhs * re_rhs - im_lhs * im_rhs, re_lhs * im_rhs + im_lhs * re_rhs)

name = 'complex.mul' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative()) class-attribute instance-attribute

py_operation(lhs: tuple[float, float], rhs: tuple[float, float]) -> tuple[float, float] staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def py_operation(
    lhs: tuple[float, float], rhs: tuple[float, float]
) -> tuple[float, float]:
    re_lhs, im_lhs = lhs
    re_rhs, im_rhs = rhs
    return (re_lhs * re_rhs - im_lhs * im_rhs, re_lhs * im_rhs + im_lhs * re_rhs)

NegOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class NegOp(ComplexUnaryComplexResultOperation):
    name = "complex.neg"

name = 'complex.neg' class-attribute instance-attribute

NotEqualOp dataclass

Bases: ComplexCompareOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class NotEqualOp(ComplexCompareOp):
    name = "complex.neq"

name = 'complex.neq' class-attribute instance-attribute

PowOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class PowOp(ComplexBinaryOp):
    name = "complex.pow"

name = 'complex.pow' class-attribute instance-attribute

ReOp dataclass

Bases: ComplexUnaryRealResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class ReOp(ComplexUnaryRealResultOperation):
    name = "complex.re"

name = 'complex.re' class-attribute instance-attribute

RsqrtOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class RsqrtOp(ComplexUnaryComplexResultOperation):
    name = "complex.rsqrt"

name = 'complex.rsqrt' class-attribute instance-attribute

SignOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class SignOp(ComplexUnaryComplexResultOperation):
    name = "complex.sign"

name = 'complex.sign' class-attribute instance-attribute

SinOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class SinOp(ComplexUnaryComplexResultOperation):
    name = "complex.sin"

name = 'complex.sin' class-attribute instance-attribute

SqrtOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class SqrtOp(ComplexUnaryComplexResultOperation):
    name = "complex.sqrt"

name = 'complex.sqrt' class-attribute instance-attribute

SubOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class SubOp(ComplexBinaryOp):
    name = "complex.sub"

    traits = traits_def(
        Pure(),
    )

    @staticmethod
    def py_operation(
        lhs: tuple[float, float], rhs: tuple[float, float]
    ) -> tuple[float, float]:
        return (lhs[0] - rhs[0], lhs[1] - rhs[1])

name = 'complex.sub' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

py_operation(lhs: tuple[float, float], rhs: tuple[float, float]) -> tuple[float, float] staticmethod

Source code in xdsl/dialects/complex.py
@staticmethod
def py_operation(
    lhs: tuple[float, float], rhs: tuple[float, float]
) -> tuple[float, float]:
    return (lhs[0] - rhs[0], lhs[1] - rhs[1])

TanOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class TanOp(ComplexUnaryComplexResultOperation):
    name = "complex.tan"

name = 'complex.tan' class-attribute instance-attribute

TanhOp dataclass

Bases: ComplexUnaryComplexResultOperation

Source code in xdsl/dialects/complex.py
@irdl_op_definition
class TanhOp(ComplexUnaryComplexResultOperation):
    name = "complex.tanh"

name = 'complex.tanh' class-attribute instance-attribute

ComplexConstantMaterializationInterface

Bases: ConstantMaterializationInterface

Source code in xdsl/dialects/complex.py
class ComplexConstantMaterializationInterface(ConstantMaterializationInterface):
    def materialize_constant(self, value: Attribute, type: Attribute) -> Operation:
        return ConstantOp.build(properties={"value": value}, result_types=(type,))

materialize_constant(value: Attribute, type: Attribute) -> Operation

Source code in xdsl/dialects/complex.py
def materialize_constant(self, value: Attribute, type: Attribute) -> Operation:
    return ConstantOp.build(properties={"value": value}, result_types=(type,))