Skip to content

Commit

Permalink
Merge pull request #127 from Quansight-Labs/fix-stuff
Browse files Browse the repository at this point in the history
Add register_backend docs and fix a bunch of bugs.
  • Loading branch information
hameerabbasi committed Apr 16, 2019
2 parents f824b89 + 25d9820 commit 707b6f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions uarray/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ def try_backend(self, method: MultiMethod, args: Tuple, kwargs: Dict, coerce: bo

def _backend_order() -> Iterable[BackendCoerceType]:
only = _only_backend.get()
skip = _skipped_backend.get()

if only is not None:
if only is not None and only not in skip:
return (only,)

pref = _preferred_backend.get()
skip = _skipped_backend.get()

return filter(lambda x: x[0] not in skip, itertools.chain(pref, itertools.product(_backends, (False,))))

Expand Down Expand Up @@ -493,6 +493,16 @@ def inner(method, args, kwargs, dispatchable_args):


def register_backend(backend: Backend):
"""
This utility method registers the backend for permanent use. It
will be tried in the list of backends automatically, unless the
``only`` flag is set on a backend.
Parameters
----------
backend : Backend
The backend to register.
"""
_backends.add(backend)


Expand Down
2 changes: 1 addition & 1 deletion unumpy/torch_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def reduce(self, a, axis=0, dtype=None, out=None, keepdims=False):
@register_torch(multimethods.asarray)
def asarray(a, dtype=None, order=None):
if torch.is_tensor(a):
if a.dtype != dtype:
if dtype is None or a.dtype != dtype:
ret = torch.tensor(a, dtype=dtype)
if a.requires_grad:
ret.requires_grad_()
Expand Down

0 comments on commit 707b6f4

Please sign in to comment.