Skip to content

TST: additional tests for matmul with non-contiguous input and output #29197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7317,11 +7317,33 @@ def test_dot_equivalent(self, args):
r3 = np.matmul(args[0].copy(), args[1].copy())
assert_equal(r1, r3)

# matrix matrix, issue 29164
if [len(args[0].shape), len(args[1].shape)] == [2, 2]:
out_f = np.zeros((r2.shape[0] * 2, r2.shape[1] * 2), order='F')
r4 = np.matmul(*args, out=out_f[::2, ::2])
assert_equal(r2, r4)
# issue 29164 with extra checks
@pytest.mark.parametrize('dtype', (
np.float32, np.float64, np.complex64, np.complex128
))
def test_dot_equivalent_matrix_matrix_blastypes(self, dtype):
modes = list(itertools.product(['C', 'F'], [True, False]))

def apply_mode(m, mode):
order, is_contiguous = mode
if is_contiguous:
return m.copy() if order == 'C' else m.T.copy().T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy actually supports order :).


retval = np.zeros(
(m.shape[0] * 2, m.shape[1] * 2), dtype=m.dtype, order=order
)[::2, ::2]
retval[...] = m
return retval

is_complex = np.issubdtype(dtype, np.complexfloating)
m1 = self.m1.astype(dtype) + (1j if is_complex else 0)
m2 = self.m2.astype(dtype) + (1j if is_complex else 0)
dot_res = np.dot(m1, m2)
mo = np.zeros_like(dot_res)

for mode in itertools.product(*[modes]*3):
m1_, m2_, mo_ = [apply_mode(*x) for x in zip([m1, m2, mo], mode)]
assert_equal(np.matmul(m1_, m2_, out=mo_), dot_res)

def test_matmul_object(self):
import fractions
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy