|
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 |
@@ -906,8 +906,19 @@ class QGF(QDType): |
906 | 906 |
|
907 | 907 | characteristic: SymbolicInt |
908 | 908 | degree: SymbolicInt |
909 | | - irreducible_poly: Optional['galois.Poly'] = None |
910 | | - element_repr: str = 'int' |
| 909 | + irreducible_poly: Optional['galois.Poly'] = attrs.field() |
| 910 | + element_repr: Literal["int", "poly", "power"] = attrs.field(default='int') |
| 911 | + |
| 912 | + @irreducible_poly.default |
| 913 | + def _irreducible_poly_default(self): |
| 914 | + if is_symbolic(self.characteristic, self.degree): |
| 915 | + return None |
| 916 | + |
| 917 | + from galois import GF |
| 918 | + |
| 919 | + return GF( # type: ignore[call-overload] |
| 920 | + int(self.characteristic), int(self.degree), compile='python-calculate' |
| 921 | + ).irreducible_poly |
911 | 922 |
|
912 | 923 | @cached_property |
913 | 924 | def order(self) -> SymbolicInt: |
@@ -936,10 +947,12 @@ def _quint_equivalent(self) -> QUInt: |
936 | 947 | def gf_type(self): |
937 | 948 | from galois import GF |
938 | 949 |
|
| 950 | + poly = self.irreducible_poly if self.degree > 1 else None |
| 951 | + |
939 | 952 | return GF( # type: ignore[call-overload] |
940 | 953 | int(self.characteristic), |
941 | 954 | int(self.degree), |
942 | | - irreducible_poly=self.irreducible_poly, |
| 955 | + irreducible_poly=poly, |
943 | 956 | repr=self.element_repr, |
944 | 957 | compile='python-calculate', |
945 | 958 | ) |
|
0 commit comments