galois.GF2m¶
-
class
galois.
GF2m
(*args, **kwargs)[source]¶ Bases:
galois.gf.GF
,galois.gf.GFArray
An abstract base class for all \(\mathrm{GF}(2^m)\) field array classes.
- Parameters
array (array_like) – The input array to be converted to a Galois field array. The input array is copied, so the original array is unmodified by changes to the Galois field array. Valid input array types are
numpy.ndarray
,list
,tuple
, orint
.dtype (numpy.dtype, optional) – The
numpy.dtype
of the array elements. The default isnumpy.int64
.
- Returns
The copied input array as a \(\mathrm{GF}(2^m)\) field array.
- Return type
Note
This is an abstract base class for all \(\mathrm{GF}(2^m)\) fields. It cannot be instantiated directly. \(\mathrm{GF}(2^m)\) field classes are created using
galois.GF_factory
.-
classmethod
Elements
(dtype=None)¶ Create a Galois field array of the field’s elements \(\{0, \dots, p^m-1\}\).
- Parameters
dtype (numpy.dtype, optional) – The
numpy.dtype
of the array elements. The default isNone
which represents the smallest valid dtype for this field class, i.e.cls.dtypes[0]
.
-
classmethod
Ones
(shape, dtype=None)¶ Create a Galois field array with all ones.
- Parameters
shape (tuple) – A numpy-compliant
shape
tuple, seenumpy.ndarray.shape
. An empty tuple()
represents a scalar. A single integer or 1-tuple, e.g.N
or(N,)
, represents the size of a 1-dim array. An n-tuple, e.g.(M,N)
, represents an n-dim array with each element indicating the size in each dimension.dtype (numpy.dtype, optional) – The
numpy.dtype
of the array elements. The default isNone
which represents the smallest valid dtype for this field class, i.e.cls.dtypes[0]
.
-
classmethod
Random
(shape=(), low=0, high=None, dtype=None)¶ Create a Galois field array with random field elements.
- Parameters
shape (tuple) – A numpy-compliant
shape
tuple, seenumpy.ndarray.shape
. An empty tuple()
represents a scalar. A single integer or 1-tuple, e.g.N
or(N,)
, represents the size of a 1-dim array. An n-tuple, e.g.(M,N)
, represents an n-dim array with each element indicating the size in each dimension.low (int, optional) – The lowest value (inclusive) of a random field element. The default is 0.
high (int, optional) – The highest value (exclusive) of a random field element. The default is
None
which represents the field’s order \(p^m\).dtype (numpy.dtype, optional) – The
numpy.dtype
of the array elements. The default isNone
which represents the smallest valid dtype for this field class, i.e.cls.dtypes[0]
.
-
classmethod
Zeros
(shape, dtype=None)¶ Create a Galois field array with all zeros.
- Parameters
shape (tuple) – A numpy-compliant
shape
tuple, seenumpy.ndarray.shape
. An empty tuple()
represents a scalar. A single integer or 1-tuple, e.g.N
or(N,)
, represents the size of a 1-dim array. An n-tuple, e.g.(M,N)
, represents an n-dim array with each element indicating the size in each dimension.dtype (numpy.dtype, optional) – The
numpy.dtype
of the array elements. The default isNone
which represents the smallest valid dtype for this field class, i.e.cls.dtypes[0]
.
-
classmethod
display
(mode='int', poly_var='x')¶ Sets the printing mode for arrays.
- Parameters
Examples
In [1]: GF = galois.GF_factory(2, 3) In [2]: a = GF.Random(4); a Out[2]: GF([5, 6, 5, 4], order=2^3) In [3]: GF.display("poly"); a Out[3]: GF([x^2 + 1, x^2 + x, x^2 + 1, x^2], order=2^3) In [4]: GF.display("poly", "r"); a Out[4]: GF([r^2 + 1, r^2 + r, r^2 + 1, r^2], order=2^3) # Reset the print mode In [5]: GF.display(); a Out[5]: GF([5, 6, 5, 4], order=2^3)
-
classmethod
target
(target, mode, rebuild=False)[source]¶ Retarget the just-in-time compiled numba ufuncs.
- Parameters
target (str) – The
target
keyword argument fromnumba.vectorize
, either"cpu"
,"parallel"
, or"cuda"
.mode (str) – The type of field computation, either
"lookup"
or"calculate"
. The “lookup” mode will use Zech log, log, and anti-log lookup tables for speed. The “calculate” mode will not store any lookup tables, but perform field arithmetic on the fly. The “calculate” mode is designed for large fields that cannot store lookup tables in RAM. Generally, “calculate” will be slower than “lookup”.rebuild (bool, optional) – Indicates whether to force a rebuild of the lookup tables. The default is
False
.
-
alpha
= None¶ The primitive element of the Galois field \(\mathrm{GF}(p^m)\). The primitive element is a root of the primitive polynomial \(p(x)\), such that \(p(\alpha) = 0\). The primitive element is also a multiplicative generator of the field, such that \(\mathrm{GF}(p^m) = \{0, 1, \alpha^1, \alpha^2, \dots, \alpha^{p^m - 2}\}\).
- Type
-
characteristic
= None¶ The prime characteristic \(p\) of the Galois field \(\mathrm{GF}(p^m)\). Adding \(p\) copies of any element will always result in \(0\).
- Type
-
degree
= None¶ The prime characteristic’s degree \(m\) of the Galois field \(\mathrm{GF}(p^m)\). The degree is a positive integer.
- Type
-
dtypes
= []¶ List of valid integer
numpy.dtype
objects that are compatible with this Galois field array class. Valid data types are signed and unsinged integers that can represent decimal values in \([0, p^m)\).- Type
-
order
= None¶ The order \(p^m\) of the Galois field \(\mathrm{GF}(p^m)\). The order of the field is also equal to the field’s size.
- Type
-
prim_poly
= None¶ The primitive polynomial \(p(x)\) of the Galois field \(\mathrm{GF}(p^m)\). The primitive polynomial is of degree \(m\) in \(\mathrm{GF}(p)[x]\).
- Type