Skip to content

Commit

Permalink
in ytools.compmat: raise ValueError for arrays > 2 dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
twmacro committed Sep 2, 2023
1 parent e2c3056 commit f315abf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyyeti/tests/test_ytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,14 @@ def test_compmat():

with pytest.raises(ValueError):
ytools.compmat(A, A[:2, :2])

with pytest.raises(ValueError):
ytools.compmat(A, B, method="badmethod")

a = np.zeros((3, 3, 3))
with pytest.raises(ValueError):
ytools.compmat(a, a)


def test_max_complex_vector_sum():
x = [3.0, 1.0 + 2.0j]
Expand Down
5 changes: 5 additions & 0 deletions pyyeti/ytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,8 @@ def compmat(a, b, filterval=0.0, method="abs", pdiff_tol=0, verbose=5):
------
ValueError
If `a` and `b` are different sizes
ValueError
If number of dimensions of `a` and `b` > 2
Notes
-----
Expand Down Expand Up @@ -1645,6 +1647,9 @@ def compmat(a, b, filterval=0.0, method="abs", pdiff_tol=0, verbose=5):
f"matrix sizes do not match: a.shape={a.shape}, b.shape={b.shape}"
)

if a.ndim > 2:
raise ValueError(f"arrays have {a.ndim} dimensions; must be <= 2")

if np.iscomplexobj(a) ^ np.iscomplexobj(b):
# if only one is complex:
if np.isrealobj(a):
Expand Down

0 comments on commit f315abf

Please sign in to comment.