Skip to content

Commit 1f88f2d

Browse files
committed
Add a strategy for symmetric matrices
1 parent 0d08906 commit 1f88f2d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

array_api_tests/hypothesis_helpers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ def tuples(elements, *, min_size=0, max_size=None, unique_by=None, unique=False)
126126
.map(lambda S: S.input_shapes)\
127127
.filter(lambda S: all(prod(i for i in shape if i) < MAX_ARRAY_SIZE for shape in S))
128128

129+
# Note: This should become hermitian_matrices when complex dtypes are added
130+
@composite
131+
def symmetric_matrices(draw, dtypes=xps.floating_dtypes()):
132+
shape = draw(square_matrix_shapes)
133+
dtype = draw(dtypes)
134+
a = draw(xps.arrays(dtype=dtype, shape=shape))
135+
upper = xp.triu(a)
136+
lower = xp.triu(a, k=1).mT
137+
return upper + lower
138+
129139
@composite
130140
def positive_definite_matrices(draw, dtypes=xps.floating_dtypes()):
131141
# For now just generate stacks of identity matrices

0 commit comments

Comments
 (0)