Skip to content

Bug with af.select when using the OpenCL backend #129

Description

@shyams2

There seems to be a bug with the af.select() function operating on spliced 2D arrays, when using the OpenCL backend. I've illustrated this with the code below:

af.set_backend("opencl")

x = af.to_array(np.arange(-5,6))
x = af.tile(x, 1, 2)

x[2:-2] = af.select(x[2:-2]>=0, x[2:-2], -1*x[2:-2])

print(x)

This gives the output as:

arrayfire.Array()
Type: long int

[11 2 1 1]
        -5         -5 
        -4         -4 
         3          3 
         2          2 
         1          1 
         0         -4 
         1         -3 
         2         -2 
         3         -1 
         4          4 
         5          5 

Changing the backend to CPU, however gives the expected answer:

arrayfire.Array()
Type: long int

[11 2 1 1]
        -5         -5 
        -4         -4 
         3          3 
         2          2 
         1          1 
         0          0 
         1          1 
         2          2 
         3          3 
         4          4 
         5          5 

However if I copy the spliced values into a new array, the output generated by the OpenCL backend is also correct. That is:

af.set_backend("opencl")
x = af.to_array(np.arange(-5,6))
x = af.tile(x, 1, 2)

x_temp  = x[2:-2].copy()
x_temp  = af.select(x_temp>=0, x_temp, -1*x_temp)
x[2:-2] = x_temp

print(x)

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