Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)}")