Skip to content

BUG: inaccurate 8-bit unsigned integer division when the divisor is a scalar #20168

@seiko2plus

Description

@seiko2plus

Describe the issue:

The bug appears when the divisor is a scalar, ceil(log2(divisor)) == 8 and the dividend length >= 64 or 32 or 16 depend on the enabled SIMD extension e.g. on AVX2 length >= 32

Reproduce the code example:

>>> import numpy as np
>>> np.arange(0, 32, dtype=np.uint8) // 132 # ceil(log2(132)) == 8
array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 0, 1, 0, 1, 0, 1, 0, 1, 0], dtype=uint8)
>>> # while it should return the following instead
>>> np.arange(0, 32, dtype=np.uint16) // 132
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], dtype=uint16)

Error message:

No response

NumPy/Python version information:

1.21.3 3.9.5 (default, May 19 2021, 11:32:47)
[GCC 10.2.0]

related to #20025, #18766, #18178

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bugcomponent: SIMDIssues in SIMD (fast instruction sets) code or machinery

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions