Skip to content

Commit

Permalink
use infer_backend instead of isinstance
Browse files Browse the repository at this point in the history
removes numpy import and fixes bug with some conversion backens
  • Loading branch information
jcmgray committed Nov 2, 2020
1 parent df7073c commit 8562951
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions opt_einsum/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from collections import namedtuple
from decimal import Decimal

import numpy as np

from . import backends, blas, helpers, parser, paths, sharing

__all__ = ["contract_path", "contract", "format_const_einsum_str", "ContractExpression", "shape_only"]
Expand Down Expand Up @@ -760,7 +758,7 @@ def __call__(self, *arrays, **kwargs):
try:
# Check if the backend requires special preparation / calling
# but also ignore non-numpy arrays -> assume user wants same type back
if backends.has_backend(backend) and all(isinstance(x, np.ndarray) for x in arrays):
if backends.has_backend(backend) and all(infer_backend(x) == 'numpy' for x in arrays):
return self._contract_with_conversion(ops, out, backend, evaluate_constants=evaluate_constants)

return self._contract(ops, out, backend, evaluate_constants=evaluate_constants)
Expand Down

0 comments on commit 8562951

Please sign in to comment.