|
51 | 51 | import abc
|
52 | 52 | from enum import Enum
|
53 | 53 | from functools import cached_property
|
54 |
| -from typing import Any, Iterable, List, Optional, Sequence, TYPE_CHECKING, Union |
| 54 | +from typing import Any, Iterable, List, Literal, Optional, Sequence, TYPE_CHECKING, Union |
55 | 55 |
|
56 | 56 | import attrs
|
57 | 57 | import numpy as np
|
@@ -908,8 +908,19 @@ class QGF(QDType):
|
908 | 908 |
|
909 | 909 | characteristic: SymbolicInt
|
910 | 910 | degree: SymbolicInt
|
911 |
| - irreducible_poly: Optional['galois.Poly'] = None |
912 |
| - element_repr: str = 'int' |
| 911 | + irreducible_poly: Optional['galois.Poly'] = attrs.field() |
| 912 | + element_repr: Literal["int", "poly", "power"] = attrs.field(default='int') |
| 913 | + |
| 914 | + @irreducible_poly.default |
| 915 | + def _irreducible_poly_default(self): |
| 916 | + if is_symbolic(self.characteristic, self.degree): |
| 917 | + return None |
| 918 | + |
| 919 | + from galois import GF |
| 920 | + |
| 921 | + return GF( # type: ignore[call-overload] |
| 922 | + int(self.characteristic), int(self.degree), compile='python-calculate' |
| 923 | + ).irreducible_poly |
913 | 924 |
|
914 | 925 | @cached_property
|
915 | 926 | def order(self) -> SymbolicInt:
|
@@ -938,10 +949,12 @@ def _quint_equivalent(self) -> QUInt:
|
938 | 949 | def gf_type(self):
|
939 | 950 | from galois import GF
|
940 | 951 |
|
| 952 | + poly = self.irreducible_poly if self.degree > 1 else None |
| 953 | + |
941 | 954 | return GF( # type: ignore[call-overload]
|
942 | 955 | int(self.characteristic),
|
943 | 956 | int(self.degree),
|
944 |
| - irreducible_poly=self.irreducible_poly, |
| 957 | + irreducible_poly=poly, |
945 | 958 | repr=self.element_repr,
|
946 | 959 | compile='python-calculate',
|
947 | 960 | )
|
|
0 commit comments