Skip to content

Multithreaded ne.evaluate() intermittently returns all-zero output on Windows / I7 14700K CPU (reproduces 2016 SO #36484326) #557

@Undi123

Description

@Undi123

numexpr.evaluate() with default multithreading occasionally writes an all-zero array into the output buffer, even when inputs are constant non-zero arrays. The same issue was reported on Stack Overflow in 2016 (https://stackoverflow.com/questions/36484326) and never resolved. Confirming it still reproduces on current numexpr.

Environment
Python 3.13.9 (Anaconda) on Windows 11
pandas 2.3.3 — pd.options.mode.copy_on_write = False, compute.use_numexpr = True, expressions._MIN_ELEMENTS = 1_000_000
numpy 2.3.5
numexpr 2.14.1 — detect_number_of_threads()=28, nthreads=16
pyarrow 21.0.0, bottleneck 1.4.2, numba 0.62.1

Minimal reproducer

import numpy as np
import numexpr as ne

x = np.ones(1000000)
y = np.ones(1000000)

for ii in range(1000):

    rr = ne.evaluate('x * y')
    test = np.all(rr == 0)
    if test:
        print('Gotcha! %d' % ii)

print('Complete!')

Observed

%runcell -i 0 F:/untitled0.py
Gotcha! 30
Gotcha! 38
Gotcha! 46
Gotcha! 52
Gotcha! 135
Gotcha! 197
Gotcha! 245
Gotcha! 285
Gotcha! 353
Gotcha! 505
Gotcha! 542
Gotcha! 543
Gotcha! 559
Gotcha! 612
Gotcha! 629
Gotcha! 678
Gotcha! 877
Gotcha! 899
Gotcha! 912
Gotcha! 938
Gotcha! 992
Complete!

Workaround confirmed
ne.set_num_threads(1)
0 all-zero outputs across 1000 iterations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions