How to use the eagerpy.tensor.base.AbstractBaseTensor function in eagerpy

To help you get started, we’ve selected a few eagerpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonasrauber / eagerpy / eagerpy / tensor / base.py View on Github external
def istensor(x):
    return isinstance(x, AbstractBaseTensor)
github jonasrauber / eagerpy / eagerpy / tensor / base.py View on Github external
    @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

eagerpy

EagerPy is a thin wrapper around PyTorch, TensorFlow Eager, JAX and NumPy that unifies their interface and thus allows writing code that works natively across all of them.

MIT
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis