def relaxed_matmul(m1, m2):
    """Numpy matmul where the summed-over dimensions may not match.

    Extra matrix entries are assumed to be zero."""
    promote2 = m2.ndim == 1
    min_dim = min(m1.shape[-1], m2.shape[-2 + promote2])
    if promote2:
        return m1[(...), :min_dim] @ m2[(...), :min_dim]
    return m1[(...), :min_dim] @ m2[(...), :min_dim, :]
