diff --git a/thinc/backends/__init__.py b/thinc/backends/__init__.py index 3376f54e0..ba4daaa8a 100644 --- a/thinc/backends/__init__.py +++ b/thinc/backends/__init__.py @@ -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: @@ -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) diff --git a/thinc/tests/backends/test_ops.py b/thinc/tests/backends/test_ops.py index 44752334e..975f144f5 100644 --- a/thinc/tests/backends/test_ops.py +++ b/thinc/tests/backends/test_ops.py @@ -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)