Skip to content

Reductions on arrays containing nan give unexpected results #583

Description

@majosm

Describe the bug
Array reductions such as min and max produce unexpected results when nans are present in the input array.

To Reproduce

import pyopencl as cl
import pyopencl.array as cla
import numpy as np

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

a = np.full(10, np.nan)
a_dev = cla.to_device(queue, a)

print(f"{cla.max(a_dev)=}")

b = np.full(10, np.nan)
b[0] = 1.
b_dev = cla.to_device(queue, b)

print(f"{cla.max(b_dev)=}")

Output:

cla.max(a_dev)=cl.Array(-inf)
cla.max(b_dev)=cl.Array(1.)

Expected behavior
Ideally these should both return cl.Array(nan)?

Environment (please complete the following information):

  • OS: macOS Catalina
  • ICD Loader and version: whatever macOS uses (khronos-opencl-icd-loader?)
  • ICD and version: pocl 1.8
  • CPU/GPU: Intel i7
  • Python version: 3.9
  • PyOpenCL version: 2022.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions