Skip to content

Unexpected result from divide-like ufuncs with unsigned integer array and negative integer scalar as inputs #1711

@antonwolfy

Description

@antonwolfy

The below example demonstrates unexpected dpctl behavior for divide, floor_divide and remainder binary functions.
The issue is visible when one of the input has unsinged integer type, while another input is negative integer scalar.

Here is an example for divide:

import numpy, dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.18.0dev0+73.gc81735a928'

dpt.divide(dpt.asarray(3, dtype='u4'), -2)
# Out: usm_ndarray(6.9849193e-10, dtype=float32)

numpy.divide(numpy.asarray(3, dtype='u4'), -2)
# Out: -1.5

dpt.divide(-4, dpt.asarray(3, dtype='u4'))
# Out: usm_ndarray(1.4316558e+09, dtype=float32)

numpy.divide(-4, numpy.asarray(3, dtype='u4'))
# Out: -1.3333333333333333

similar with floor_divide:

dpt.floor_divide(dpt.asarray(7, dtype='u4'), -2)
# Out: usm_ndarray(0, dtype=uint32)

numpy.floor_divide(numpy.asarray(7, dtype='u4'), -2)
# Out: -4

and remainder:

dpt.remainder(dpt.asarray(7, dtype='u4'), -2)
# Out: usm_ndarray(7, dtype=uint32)

numpy.remainder(numpy.asarray(7, dtype='u4'), -2)
# Out: -1

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