Skip to content

mapreduce failure with CartesianIndex values #259

@maleadt

Description

@maleadt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkernelsThings about kernels and how they are compiled.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions