From 94c1f184e277acb95e3d29f2186b3ceabb8a4e01 Mon Sep 17 00:00:00 2001 From: Christoph Boeddeker Date: Thu, 13 Jun 2024 14:17:26 +0200 Subject: [PATCH] contrib: lazy import of torch_complex --- padertorch/contrib/cb/complex.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/padertorch/contrib/cb/complex.py b/padertorch/contrib/cb/complex.py index 8c45eb63..475ab04f 100644 --- a/padertorch/contrib/cb/complex.py +++ b/padertorch/contrib/cb/complex.py @@ -1,10 +1,7 @@ import numpy as np import torch -import torch_complex -from torch_complex import ComplexTensor __all__ = { - 'ComplexTensor', } @@ -19,8 +16,11 @@ def is_torch(obj): >>> is_torch(ComplexTensor(np.zeros(3))) True """ - if torch.is_tensor(obj) or isinstance(obj, ComplexTensor): + if torch.is_tensor(obj): return True - else: - return False + if type(obj).__name__ == 'ComplexTensor': + from torch_complex import ComplexTensor + if isinstance(obj, ComplexTensor): + return True + return False