Skip to content

Commit

Permalink
Merge pull request #22384 from charris/backport-22327
Browse files Browse the repository at this point in the history
BUG: Fix complex vector dot with more than NPY_CBLAS_CHUNK elements
  • Loading branch information
charris committed Oct 6, 2022
2 parents 93ab5d6 + ad81a80 commit 611fadc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion numpy/core/src/multiarray/arraytypes.c.src
Expand Up @@ -3581,7 +3581,8 @@ NPY_NO_EXPORT void
CBLAS_INT chunk = n < NPY_CBLAS_CHUNK ? n : NPY_CBLAS_CHUNK;
@type@ tmp[2];

CBLAS_FUNC(cblas_@prefix@dotu_sub)((CBLAS_INT)n, ip1, is1b, ip2, is2b, tmp);
CBLAS_FUNC(cblas_@prefix@dotu_sub)(
(CBLAS_INT)chunk, ip1, is1b, ip2, is2b, tmp);
sum[0] += (double)tmp[0];
sum[1] += (double)tmp[1];
/* use char strides here */
Expand Down
11 changes: 10 additions & 1 deletion numpy/core/tests/test_multiarray.py
Expand Up @@ -29,7 +29,7 @@
assert_allclose, IS_PYPY, IS_PYSTON, HAS_REFCOUNT, assert_array_less,
runstring, temppath, suppress_warnings, break_cycles,
)
from numpy.testing._private.utils import _no_tracing
from numpy.testing._private.utils import requires_memory, _no_tracing
from numpy.core.tests._locales import CommaDecimalPointLocale
from numpy.lib.recfunctions import repack_fields

Expand Down Expand Up @@ -6691,6 +6691,15 @@ def assert_dot_close(A, X, desired):
# Strides in A cols and X
assert_dot_close(A_f_12, X_f_2, desired)

@pytest.mark.slow
@pytest.mark.parametrize("dtype", [np.float64, np.complex128])
@requires_memory(free_bytes=9*10**9) # complex case needs 8GiB+
def test_huge_vectordot(self, dtype):
# Large vector multiplications are chunked with 32bit BLAS
# Test that the chunking does the right thing, see also gh-22262
data = np.ones(2**30+100, dtype=dtype)
res = np.dot(data, data)
assert res == 2**30+100


class MatmulCommon:
Expand Down

0 comments on commit 611fadc

Please sign in to comment.