Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def istensor(x):
return isinstance(x, AbstractBaseTensor)
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
args = [arg.tensor if isinstance(arg, self.__class__) else arg for arg in args]
return f(self, *args, **kwargs)
return wrapper
class AbstractBaseTensor(ABC):
__array_ufunc__ = None
def __init__(self, tensor):
self.tensor = tensor
class AbstractTensor(AbstractBaseTensor, ABC):
def __repr__(self):
return f"{self.__class__.__name__}({self.tensor.__repr__()})"
def __format__(self, *args, **kwargs):
return self.tensor.__format__(*args, **kwargs)
@unwrapin
@wrapout
def __getitem__(self, index):
if isinstance(index, tuple):
index = tuple(
x.tensor if isinstance(x, self.__class__) else x for x in index
)
return self.tensor.__getitem__(index)
@property