Skip to content

Commit

Permalink
Support big endian platform by providing new ops implementation (#559)
Browse files Browse the repository at this point in the history
* add bigendian op support

* add test to mirror appleops test

* removed explicit bigendian check in get_ops

* update use_ops

* remove use_ops check

* commit suggested changes

* Format

* Format

Co-authored-by: Adriane Boyd <[email protected]>
  • Loading branch information
andrewsi-z and adrianeboyd authored Dec 21, 2021
1 parent 98dfd51 commit 7b54f72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions thinc/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def _import_extra_cpu_backends():
from thinc_apple_ops import AppleOps
except ImportError:
pass
try:
from thinc_bigendian_ops import BigEndianOps
except ImportError:
pass


def get_ops(name: str, **kwargs) -> Ops:
Expand All @@ -90,8 +94,10 @@ def get_ops(name: str, **kwargs) -> Ops:

cls: Optional[Callable[..., Ops]] = None
if name == "cpu":
_import_extra_cpu_backends()
cls = ops_by_name.get("apple", ops_by_name.get("numpy"))
_import_extra_cpu_backends()
cls = ops_by_name.get("numpy")
cls = ops_by_name.get("apple", cls)
cls = ops_by_name.get("bigendian", cls)
else:
cls = ops_by_name.get(name)

Expand Down
7 changes: 7 additions & 0 deletions thinc/tests/backends/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ def test_get_ops():
assert isinstance(get_ops("cpu"), AppleOps)
except ImportError:
assert isinstance(get_ops("cpu"), NumpyOps)
# If BigEndian ops are available, "cpu" should return BigEndianOps or
# NumpyOps otherwise.
try:
from thinc_bigendian_ops import BigEndianOps
assert isinstance(get_ops("cpu"), BigEndianOps)
except ImportError:
assert isinstance(get_ops("cpu"), NumpyOps)
with pytest.raises(ValueError):
get_ops("blah")
ops = Ops(numpy)
Expand Down

0 comments on commit 7b54f72

Please sign in to comment.