diff --git a/qlasskit/types/qint.py b/qlasskit/types/qint.py index 4ee521d6..2215c686 100644 --- a/qlasskit/types/qint.py +++ b/qlasskit/types/qint.py @@ -21,7 +21,7 @@ from .qtype import Qtype, TExp, bin_to_bool_list, bool_list_to_bin -class Qint(int, Qtype): +class QintImp(int, Qtype): BIT_SIZE = 8 def __init__(self, value): @@ -122,17 +122,20 @@ def gt(tleft: TExp, tcomp: TExp) -> TExp: @staticmethod def lt(tleft: TExp, tcomp: TExp) -> TExp: """Compare two Qint for lower than""" - return (bool, And(Not(Qint.gt(tleft, tcomp)[1]), Not(Qint.eq(tleft, tcomp)[1]))) + return ( + bool, + And(Not(QintImp.gt(tleft, tcomp)[1]), Not(QintImp.eq(tleft, tcomp)[1])), + ) @staticmethod def lte(tleft: TExp, tcomp: TExp) -> TExp: """Compare two Qint for lower than - equal""" - return (bool, Not(Qint.gt(tleft, tcomp)[1])) + return (bool, Not(QintImp.gt(tleft, tcomp)[1])) @staticmethod def gte(tleft: TExp, tcomp: TExp) -> TExp: """Compare two Qint for greater than - equal""" - return (bool, Not(Qint.lt(tleft, tcomp)[1])) + return (bool, Not(QintImp.lt(tleft, tcomp)[1])) # Operations @@ -234,40 +237,52 @@ def bitwise_or(cls, tleft: TExp, tright: TExp) -> TExp: return cls.bitwise_generic(Or, tleft, tright) -class Qint2(Qint): +class Qint2(QintImp): BIT_SIZE = 2 -class Qint3(Qint): +class Qint3(QintImp): BIT_SIZE = 3 -class Qint4(Qint): +class Qint4(QintImp): BIT_SIZE = 4 -class Qint5(Qint): +class Qint5(QintImp): BIT_SIZE = 5 -class Qint6(Qint): +class Qint6(QintImp): BIT_SIZE = 6 -class Qint7(Qint): +class Qint7(QintImp): BIT_SIZE = 7 -class Qint8(Qint): +class Qint8(QintImp): BIT_SIZE = 8 -class Qint12(Qint): +class Qint12(QintImp): BIT_SIZE = 12 -class Qint16(Qint): +class Qint16(QintImp): BIT_SIZE = 16 QINT_TYPES = [Qint2, Qint3, Qint4, Qint5, Qint6, Qint7, Qint8, Qint12, Qint16] + + +class QintMeta(type): + def __getitem__(cls, params): + if isinstance(params, tuple) and len(params) == 1: + i = params + if isinstance(i, int) and i >= 2: + return f"Qint{i}" # TODO: transform to type + + +class Qint(metaclass=QintMeta): + pass