#10846·numba

Accumulator bit-width for `np.sum` does not match NumPy

Author: escCreated Sep 21, 2026Updated Sep 23, 2026
Labelsnumpybug - incorrect behaviorbug - regression

Description

The Numba implementation for np.sum shows an accumulator-bit width for unsigned integers less than 64 bits in width that does not match NumPy. np.cumsum is also likely to be affected.

Reproducer

python
import numpy as np
from numba import jit


@jit
def f(a):
    return np.sum(a)


dtypes = [np.int8, np.int16, np.int32, np.int64,
          np.uint8, np.uint16, np.uint32, np.uint64]

print(f"{'input':8s} {'numpy':8s} numba")
for dt in dtypes:
    input_array = np.array([23, 42], dtype=dt)
    numpy_dtype = np.sum(input_array).dtype
    f(input_array)
    numba_dtype = f.nopython_signatures[-1].return_type
    print(f"{np.dtype(dt).name:8s} {str(numpy_dtype):8s} {numba_dtype}")

Results

Running on main at 4b3e8fb92f886b199434a74c7aec9fecfeb834b8 on a Mac Book Pro M4 (osx-arm64):

$ numba -s | grep "Numba Version"
Numba Version                                 : 0.69.0dev0+41.g4b3e8fb92f
$ python bug.py
input    numpy    numba
int8     int64    int64
int16    int64    int64
int32    int64    int64
int64    int64    int64
uint8    uint64   int64
uint16   uint64   int64
uint32   uint64   int64
uint64   uint64   uint64

As you can see the dtypes [int8, int16, int32] are accumulated as int64 by Numba but should be uint64 as in NumPy.

Running on faf66df31b44231f99fcf231b251ddd5314bf3bf (commit before merging #10625) with the same hardware:

$ numba -s | grep "Numba Version"
Numba Version                                 : 0.67.0dev1+6.gfaf66df31b
$ python bug.py
input    numpy    numba
int8     int64    int64
int16    int64    int64
int32    int64    int64
int64    int64    int64
uint8    uint64   uint64
uint16   uint64   uint64
uint32   uint64   uint64
uint64   uint64   uint64

The accumulator bit-width is fine on this commit, hence this is classified as regression.

Affected Versions

Numba 0.67 is affected, 0.66 is fine. The issue still exists on main today as outlined above.

Running on 0.67.0 tag:

$ numba -s | grep "Numba Version"
Numba Version                                 : 0.67.0
$ python bug.py
input    numpy    numba
int8     int64    int64
int16    int64    int64
int32    int64    int64
int64    int64    int64
uint8    uint64   int64
uint16   uint64   int64
uint32   uint64   int64
uint64   uint64   uint64

And on 0.66.0:

$ numba -s | grep "Numba Version"
Numba Version                                 : 0.66.0
$ python bug.py
input    numpy    numba
int8     int64    int64
int16    int64    int64
int32    int64    int64
int64    int64    int64
uint8    uint64   uint64
uint16   uint64   uint64
uint32   uint64   uint64
uint64   uint64   uint64

Root Cause and Origin

The root cause is in the line:

https://github.com/numba/numba/blob/1ea0c35ebf93050185524c12359d33fb0d03f4cd/numba/np/arraymath.py#L425-L431

This was first introduced in #10625 in two places:

And then refactored in #10657

https://github.com/numba/numba/pull/10657/changes#diff-2cf44e1bdf814c86f9d83bfd6594166f550c5d1796c4ae2cff93705cfd105befR439

Suggested Fix

A fix was first proposed in #10794:

https://github.com/numba/numba/pull/10794#discussion_r4045956769

But note that the tests for sum and also cumsum (which may also be affected) need to be revisited.

AI Attribution

Assisted-by: Kilo(moonshotai/kimi-k3) for debugging and reproducer Assisted-by: Claude Desktop (anthropic/claude-opus-5) for debugging and reproducer

Checklist