Handle custom types without solve_sylvester
The following discussion from !71 (merged) should be addressed:
-
@Hugo started a discussion: (+2 comments) My use case was when the blocks are of a custom type. Even with these changes
is_diagonal
still raises an error if the type of the blocks is not a known type.To support any type, two things should be checked:
- Whether the object is diagonal. This can "fail" in two ways:
- a. We are not able to check whether the object is diagonal
- b. We are able to check, but the object is not diagonal
- Whether we can extract the diagonal
If (1a) or (1b) fails, we should show the warning already present in this MR. If (2) fails, we should raise an error.
To handle (1a) and (1b), I would propose to add this at the end of
is_diagonal
, replacing the error:if hasattr(A, "is_diagonal") and callable(A.is_diagonal): return A.is_diagonal() return False
To catch (2), in
_extract_diagonal
we should add the following check before callingblock.diagonal()
:if hasattr(block, "diagonal") and callable(block.diagonal): raise NotImplementedError("Cannot extract diagonal since ... etc")
- Whether the object is diagonal. This can "fail" in two ways:
Here's my take on this:
Effectively we'd be defining interface for custom objects to be able to rely on our default
solve_sylvester_diagonal
. I find it a bit dangerous, and therefore failing may be the appropriate course of action.