Skip to content

Commit

Permalink
Add error checking on input types
Browse files Browse the repository at this point in the history
  • Loading branch information
bwohlberg committed Oct 5, 2023
1 parent b3ecc75 commit cd4c14b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scico/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,27 @@ def __init__(
"""
if isinstance(A, MatrixOperator):
A = A.to_array()
elif not isinstance(A, Array):
raise TypeError(
f"Operator A is required to be a MatrixOperator or an array; got a {type(A)}."
)
if isinstance(D, MatrixOperator):
D = D.to_array()
elif isinstance(D, Diagonal):
D = D.diagonal
elif not isinstance(D, Array):
raise TypeError(
"Operator D is required to be a MatrixOperator, Diagonal, or an array; "
f"got a {type(D)}."
)
if W is None:
W = snp.ones(A.shape[0], dtype=A.dtype)
elif isinstance(W, Diagonal):
W = W.diagonal
elif not isinstance(W, Array):
raise TypeError(
f"Operator W is required to be None, a Diagonal, or an array; got a {type(W)}."
)
self.A = A
self.D = D
self.W = W
Expand Down

0 comments on commit cd4c14b

Please sign in to comment.