# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.

import hypothesis.extra.numpy as npst
import numpy
from hypothesis import given, strategies as st


@given(
    data=st.data(),
    shapes=npst.mutually_broadcastable_shapes(signature="(n?,k),(k,m?)->(n?,m?)"),
    types=st.sampled_from(numpy.matmul.types).filter(lambda sig: "O" not in sig),
)
def test_gufunc_matmul(data, shapes, types):
    input_shapes, expected_shape = shapes
    input_dtypes, expected_dtype = types.split("->")
    array_st = [npst.arrays(d, s) for d, s in zip(input_dtypes, input_shapes)]

    a, b = data.draw(st.tuples(*array_st))
    result = numpy.matmul(a, b)

    assert result.shape == expected_shape
    assert result.dtype.char == expected_dtype
