GeezerVison is showing github.com — BUG: matvec(A, b, out=b) zeros out b · Issue #31144 · numpy/numpy
BUG: matvec(A, b, out=b) zeros out b #31144DescriptionDescribe the issue:
I expected np.matvec(A, b, out=b) to behave more or less like np.einsum('...ij,...j', A, b, out=b), but instead b is set to all zeros
It seems to work fine if the output vector is not the same as the input vector.
Reproduce the code example:
>>> import numpy as np
>>> M, N = 100000, 10
... A = np.random.normal(size=(M, N, N))
... b = np.random.normal(size=(M, N))
>>> np.matvec(A, b, out=b)
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]], shape=(100000, 10))
Error message:
Python and NumPy Versions:
2.4.4
3.14.3 (main, Feb 15 2026, 00:49:34) [GCC 15.2.1 20260209]
Runtime Environment:
[{'numpy_version': '2.4.4',
'python': '3.14.3 (main, Feb 15 2026, 00:49:34) [GCC 15.2.1 20260209]',
'uname': uname_result(system='Linux', node='...', release='6.19.10-artix1-1', version='#1 SMP PREEMPT_DYNAMIC Thu, 26 Mar 2026 22:46:44 +0000', machine='x86_64')},
{'simd_extensions': {'baseline': [],
'found': ['X86_V2', 'X86_V3'],
'not_found': ['X86_V4', 'AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'filepath': '/usr/lib/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 12,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None}]
How does this issue affect you or how did you find it:
I needed to apply a linear transformation to many vectors in-place, and it didn't work. Activityadded a commit that references this issue on Apr 4, 2026This issue will close once commit 89f6cd0 is merged into the 'main' branch.89f6cd0 Ijtihed commented on Apr 4, 2026 I believe matvec and vecmat are missing the same overlap-handling flag that matmul already has so when out aliases an inputt, BLAS zeros the buffer before reading it. we can fix it if we clear OVERLAP_ASSUME_ELEMENTWISE on their output operand like matmul does it
#31150 tylerjereddy commented on Apr 4, 2026 I can't reproduce the original problem locally on latest main branch on ARM Mac. Maybe I'll try on x86_64 Linux next just in case...
>>> import numpy as np
>>> M, N = 100000, 10
>>> A = np.random.normal(size=(M, N, N))
>>> b = np.random.normal(size=(M, N))
>>> np.matvec(A, b, out=b)
array([[-4.27910098, 0.72496376, -4.57306406, ..., -3.30022262,
-6.61555153, -7.48743835],
[ 2.71045097, -2.0806753 , -5.4879226 , ..., -2.09790416,
-2.90238571, -1.60047482],
[ 0.50323991, 2.6632049 , 2.08760249, ..., -1.03016698,
1.8176871 , -1.77353083],
...,
[-0.91260162, 4.44175049, -0.76366474, ..., 1.16549763,
-3.66365006, 3.03244982],
[-1.96788363, -2.14235089, 2.93116224, ..., -0.24430625,
0.80722965, 4.79238694],
[-3.64083547, 1.32681639, -0.32963045, ..., 0.29729222,
-0.81767494, -0.90006859]], shape=(100000, 10))tylerjereddy commented on Apr 4, 2026 I can reproduce on x86_64 Linux with Python 3.14.0 (and presumably OpenBLAS vs. Accelerate if that matters).
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|