How to use the eagerpy.PyTorchTensor 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 / astensor.py View on Github external
def astensor(x):
    if hasattr(x, "tensor"):
        return x
    # we use the module name instead of isinstance
    # to avoid importing all the frameworks
    module = _get_module_name(x)
    if module == "torch":
        return PyTorchTensor(x)
    if module == "tensorflow":
        return TensorFlowTensor(x)
    if module == "jax":
        return JAXTensor(x)
    if module == "numpy":
        return NumPyTensor(x)
    raise ValueError(f"Unknown type: {type(x)}")

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