From c9545ee03b7440b19422ed0c75493ec7f99ca73f Mon Sep 17 00:00:00 2001 From: Christoph Lehner Date: Tue, 31 Oct 2023 17:15:34 +0100 Subject: [PATCH] fix edge cases --- lib/gpt/core/component.py | 2 ++ lib/gpt/core/transform.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/gpt/core/component.py b/lib/gpt/core/component.py index a8e9cc27..10982499 100644 --- a/lib/gpt/core/component.py +++ b/lib/gpt/core/component.py @@ -23,6 +23,8 @@ def _simple_map(operator, numpy_operator=None, extra_params={}): def _mat(first, second=None): + if isinstance(first, list): + return [_mat(x) for x in first] if second is not None: dst = first src = gpt.eval(second) diff --git a/lib/gpt/core/transform.py b/lib/gpt/core/transform.py index 39a7ab38..de9e7e5d 100644 --- a/lib/gpt/core/transform.py +++ b/lib/gpt/core/transform.py @@ -89,15 +89,16 @@ def norm2(l): l = gpt.util.to_list(l) l_lattices = [(i, l[i]) for i in range(len(l)) if isinstance(l[i], gpt.lattice)] l_tensors = [(i, l[i]) for i in range(len(l)) if isinstance(l[i], gpt.tensor)] - ip_l = ( - l_lattices[0][1] - .grid.globalsum( - numpy.array([rank_inner_product(x, x) for i, x in l_lattices], dtype=numpy.complex128) + if len(l_lattices) > 0: + ip_l = ( + l_lattices[0][1] + .grid.globalsum( + numpy.array([rank_inner_product(x, x) for i, x in l_lattices], dtype=numpy.complex128) + ) + .real ) - .real - ) - ip_t = [x.norm2() for i, x in l_tensors] - ip = numpy.ndarray(dtype=numpy.complex128, shape=(len(l),)) + ip_t = [x.norm2().real for i, x in l_tensors] + ip = numpy.ndarray(dtype=numpy.float64, shape=(len(l),)) for i, j in enumerate(l_lattices): ip[j[0]] = ip_l[i] for i, j in enumerate(l_tensors):