Open
Description
The following findfirst
-like kernel fails when using CartesianIndices:
using oneAPI
function doit(xs)
# works
indices, dummy_index = eachindex(xs), 1
# fails
#indices, dummy_index = CartesianIndices(xs), CartesianIndex{ndims(xs)}()
# given two pairs of (istrue, index), return the one with the smallest index
function findfirst_reduction(t1, t2)
(x, i), (y, j) = t1, t2
if i > j
t1, t2 = t2, t1
(x, i), (y, j) = t1, t2
end
x && return t1
y && return t2
return (false, dummy_index)
end
res = mapreduce(tuple, findfirst_reduction, xs, indices;
init = (false, dummy_index))
return res[1] ? res[2] : nothing
end
function main()
x = [false false; true false]
@show i = doit(oneArray(x))
@assert i !== nothing
@assert x[i]
end