Skip to content

Commit

Permalink
Move placeholder factory functions into _factory.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Apr 27, 2022
1 parent eefce37 commit e9d6806
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
15 changes: 1 addition & 14 deletions galois/_domains/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import contextlib
import random
from typing import Optional, Union, Type
from typing import Optional, Union
from typing_extensions import Literal

import numpy as np
Expand Down Expand Up @@ -493,16 +493,3 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True):
if dtype not in type(self)._dtypes:
raise TypeError(f"{type(self)._name} arrays can only be cast as integer dtypes in {type(self)._dtypes}, not {dtype}.")
return super().astype(dtype, order=order, casting=casting, subok=subok, copy=copy)


def FIELD_FACTORY(*args, **kwargs) -> Type[Array]: # pylint: disable=unused-argument
"""
This will be monkey-patched to be `galois.GF()` in __init__.py.
"""
return Array


DEFAULT_FIELD_ARRAY = Array
"""
This will be monkey-patched to be `galois.GF2` in __init__.py.
"""
20 changes: 20 additions & 0 deletions galois/_domains/_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
A module for for creating Array subclasses. These functions are provided to prevent circular dependencies.
They will be monkey-patched into the _polys module.
"""
from typing import Type

from ._array import Array


def FIELD_FACTORY(*args, **kwargs) -> Type[Array]: # pylint: disable=unused-argument
"""
This will be monkey-patched to be `galois.GF()` in __init__.py.
"""
return Array


DEFAULT_FIELD_ARRAY = Array
"""
This will be monkey-patched to be `galois.GF2` in __init__.py.
"""
2 changes: 1 addition & 1 deletion galois/_polys/_irreducible.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

from .._domains._array import FIELD_FACTORY
from .._domains._factory import FIELD_FACTORY
from .._overrides import set_module
from .._prime import factors, is_prime_power

Expand Down
3 changes: 2 additions & 1 deletion galois/_polys/_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import numpy as np

from .._domains._array import Array, DEFAULT_FIELD_ARRAY
from .._domains import Array
from .._domains._factory import DEFAULT_FIELD_ARRAY
from .._overrides import set_module
from ..typing import ElementLike, ArrayLike, PolyLike

Expand Down
2 changes: 1 addition & 1 deletion galois/_polys/_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

from .._domains._array import FIELD_FACTORY
from .._domains._factory import FIELD_FACTORY
from .._databases import ConwayPolyDatabase
from .._overrides import set_module
from .._prime import factors, is_prime, is_prime_power
Expand Down

0 comments on commit e9d6806

Please sign in to comment.