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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@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
76
77
78
79
80
81
82
83
84
85
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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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: SSAValue | Operation,
        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: SSAValue | Operation, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
133
134
135
136
137
138
139
140
141
142
143
def __init__(
    self,
    operand: SSAValue | Operation,
    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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
class ComplexUnaryRealResultOperation(IRDLOperation, abc.ABC):
    """Base class for unary operations on complex numbers that return a float."""

    T: ClassVar = VarConstraint("T", AnyFloatConstr)

    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: SSAValue | Operation,
        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('T', AnyFloatConstr) 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: SSAValue | Operation, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
161
162
163
164
165
166
167
168
169
170
171
172
def __init__(
    self,
    operand: SSAValue | Operation,
    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
174
175
176
177
178
179
180
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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: SSAValue | Operation,
        rhs: SSAValue | Operation,
        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: SSAValue | Operation, rhs: SSAValue | Operation, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/complex.py
198
199
200
201
202
203
204
205
206
207
208
209
def __init__(
    self,
    lhs: SSAValue | Operation,
    rhs: SSAValue | Operation,
    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
211
212
213
214
215
216
217
218
219
220
221
@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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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: SSAValue | Operation, rhs: SSAValue | Operation):
        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: SSAValue | Operation, rhs: SSAValue | Operation)

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

AbsOp dataclass

Bases: ComplexUnaryRealResultOperation

Source code in xdsl/dialects/complex.py
258
259
260
@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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
@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
274
275
276
277
278
@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
281
282
283
@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
286
287
288
@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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
@irdl_op_definition
class BitcastOp(IRDLOperation):
    """
    compute between complex and and equal arith types
    """

    name = "complex.bitcast"
    operand = operand_def(
        ComplexType.constr(AnyFloatConstr) | AnyFloatConstr | BaseAttr(IntegerType)
    )
    result = result_def(
        ComplexType.constr(AnyFloatConstr) | AnyFloatConstr | BaseAttr(IntegerType)
    )

    traits = traits_def(Pure())

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

    def __init__(self, operand: SSAValue | Operation, 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.constr(AnyFloatConstr) | AnyFloatConstr | BaseAttr(IntegerType)) class-attribute instance-attribute

result = result_def(ComplexType.constr(AnyFloatConstr) | AnyFloatConstr | BaseAttr(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: SSAValue | Operation, result_type: Attribute)

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

verify_() -> None

Source code in xdsl/dialects/complex.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
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
336
337
338
@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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
@irdl_op_definition
class ConstantOp(IRDLOperation, HasFolderInterface):
    name = "complex.constant"
    T: ClassVar = VarConstraint("T", AnyFloatConstr | base(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('T', AnyFloatConstr | base(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
364
365
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
367
368
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
370
371
372
373
374
375
@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
377
378
379
380
381
382
@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
385
386
387
@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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
@irdl_op_definition
class CreateOp(IRDLOperation):
    name = "complex.create"
    T: ClassVar = VarConstraint("T", AnyFloatConstr)
    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: SSAValue | Operation,
        imaginary: SSAValue | Operation,
        result_type: ComplexType,
    ):
        super().__init__(operands=[real, imaginary], result_types=[result_type])

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

T: ClassVar = VarConstraint('T', AnyFloatConstr) 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: SSAValue | Operation, imaginary: SSAValue | Operation, result_type: ComplexType)

Source code in xdsl/dialects/complex.py
402
403
404
405
406
407
408
def __init__(
    self,
    real: SSAValue | Operation,
    imaginary: SSAValue | Operation,
    result_type: ComplexType,
):
    super().__init__(operands=[real, imaginary], result_types=[result_type])

DivOp dataclass

Bases: ComplexBinaryOp

Source code in xdsl/dialects/complex.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
@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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
@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
443
444
445
@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
448
449
450
@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
453
454
455
@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
458
459
460
@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
463
464
465
@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
468
469
470
@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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
@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
482
483
484
485
486
487
488
@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
491
492
493
@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
496
497
498
@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
501
502
503
@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
506
507
508
@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
511
512
513
@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
516
517
518
@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
521
522
523
@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
526
527
528
@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
531
532
533
534
535
536
537
538
539
540
541
542
543
@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
539
540
541
542
543
@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
546
547
548
@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
551
552
553
@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
556
557
558
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
557
558
def materialize_constant(self, value: Attribute, type: Attribute) -> Operation:
    return ConstantOp.build(properties={"value": value}, result_types=(type,))