| 1 |
# This test code was written by the `hypothesis.extra.ghostwriter` module |
| 2 |
# and is provided under the Creative Commons Zero public domain dedication. |
| 3 |
|
| 4 |
import numpy |
| 5 |
from hypothesis import given, strategies as st |
| 6 |
from hypothesis.extra.numpy import arrays, mutually_broadcastable_shapes |
| 7 |
|
| 8 |
|
| 9 |
@given( |
| 10 |
data=st.data(), |
| 11 |
shapes=mutually_broadcastable_shapes(signature="(n?,k),(k,m?)->(n?,m?)"), |
| 12 |
types=st.sampled_from([sig for sig in numpy.matmul.types if "O" not in sig]), |
| 13 |
) |
| 14 |
def test_gufunc_matmul(data, shapes, types): |
| 15 |
input_shapes, expected_shape = shapes |
| 16 |
input_dtypes, expected_dtype = types.split("->") |
| 17 |
array_strats = [ |
| 18 |
arrays(dtype=dtp, shape=shp, elements={"allow_nan": True}) |
| 19 |
for dtp, shp in zip(input_dtypes, input_shapes) |
| 20 |
] |
| 21 |
|
| 22 |
a, b = data.draw(st.tuples(*array_strats)) |
| 23 |
result = numpy.matmul(a, b) |
| 24 |
|
| 25 |
assert result.shape == expected_shape |
| 26 |
assert result.dtype.char == expected_dtype |