Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster extrema on abstract arrays when there is no functions or selected dims #34790

Open
longemen3000 opened this issue Feb 17, 2020 · 3 comments
Labels
arrays [a, r, r, a, y, s] performance Must go faster

Comments

@longemen3000
Copy link
Contributor

longemen3000 commented Feb 17, 2020

for reference, see this discourse thread:
https://discourse.julialang.org/t/perf-improvement-suggestion-for-simple-extrema/34776/2
the key is just writing a simple loop in the case of extrema(x::AbstractArray). the post uses an standard indexing, but i think this can be changed?

@longemen3000 longemen3000 changed the title Faster extrema Faster extrema on abstract arrays when there is no functions or selected dims Feb 17, 2020
@longemen3000
Copy link
Contributor Author

longemen3000 commented Feb 17, 2020

a prototype

function extrema(x::AbstractArray)
  a = b = first(x)
  @inbounds @simd for i in eachindex(x)
    if x[i] > b 
      b = x[i]
    elseif x[i] < a 
      a = x[i]
    end
  end
  a, b
end

@tkf
Copy link
Member

tkf commented Feb 18, 2020

Isn't it more or less a dup of #31442?

@longemen3000
Copy link
Contributor Author

not technically, but it seems so

@brenhinkeller brenhinkeller added performance Must go faster arrays [a, r, r, a, y, s] labels Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

No branches or pull requests

3 participants