How to perform an argmax / argmin on a subset of a vector?

oof, embarrasing error from my part. i misunderstood the meaning of the start argument on findnext.the function that should do what op wants is along the lines of:

function findmax_view(x,b)
    c = argmax(view(x,b))
    i0 = findfirst(identity,b) #find the first value
    for _ in 1:c-1 #findnext iteratively c-1 times 
        i0 = findnext(identity,b,i0+1)
    end
    return i0
end

Proposing one more lamp to the store with a slight twist:

function argmax_parentindex(x,b)
    v = view(x,b)
    first(parentindices(v))[argmax(v)]
end

NB: updated benchmark plots in post further above

2 Likes