Skip to content

Commit

Permalink
Set off-diagonal blocks to zero in 'out' argument of diagonal()
Browse files Browse the repository at this point in the history
  • Loading branch information
yguclu committed Jan 30, 2024
1 parent 54f4671 commit 24b9be2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion psydac/linalg/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@e-moral-sanchez

e-moral-sanchez Jan 31, 2024

Contributor

When doing this, does it also delete the keys (i,j) from out.nonzero_block_indices?

This comment has been minimized.

Copy link
@yguclu

yguclu Jan 31, 2024

Author Member

If you look at the property nonzero_block_indices, you will see that it returns a copy of the keys of the internal dictionary which stores the non-zero blocks. If you call this property again after this for loop you will see that the keys are updated.

else:
out = BlockLinearOperator(V, W)

Expand Down

0 comments on commit 24b9be2

Please sign in to comment.