From 24b9be29def76b05600c29c4faddfbf9565f1341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaman=20G=C3=BC=C3=A7l=C3=BC?= Date: Tue, 30 Jan 2024 19:02:50 +0100 Subject: [PATCH] Set off-diagonal blocks to zero in 'out' argument of diagonal() --- psydac/linalg/block.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/psydac/linalg/block.py b/psydac/linalg/block.py index 02552e4cc..e8a9c44d6 100644 --- a/psydac/linalg/block.py +++ b/psydac/linalg/block.py @@ -804,7 +804,11 @@ def diagonal(self, *, inverse = False, out = None): assert isinstance(out, BlockLinearOperator) assert out.domain is V assert out.codomain is W - assert all(i==j for i, j in out._blocks.keys()) # is this really needed? + + # Set any off-diagonal blocks to zero + for i, j in out.nonzero_block_indices: + if i != j: + out[i, j] = None else: out = BlockLinearOperator(V, W)