Bug with af.select when using the OpenCL backend
shyams2 opened this issue · comments
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)
@ShyamSS-95 for now can you use the following as a work around
cond = (x[2:-2] >= 0).as(af.Dtype.s32)
x[2:-2] = (2 * cond - 1) * x[2:-2] #cond * x[2:-2] + (cond - 1) * x[2:-2]
btw this is a bug in arrayfire. I have reported it over here: arrayfire/arrayfire#1730
@ShyamSS-95 I fixed it in this PR: arrayfire/arrayfire#1731
You can pull those changes and rebuild arrayfire if you don't want to wait.
@ShyamSS-95 This is fixed in upstream arrayfire.