eve::algo::max_element on a slice of an array #1712
-
I've got lost in template metaprogramming madness trying to find an answer. I have an array |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 7 replies
-
Hi! Thank you for trying I am not sure I 100% understand the question, so my best attempt. NOTE: max_element is the LAST biggest elements amoung equals, Opt 1. You have a contigious range and you just used array<int, 4> as an example This is the code (https://godbolt.org/z/3qfsYYoEx) :
Opt 2. You just have 4 ints. For explicitly 4 ints you are probably better of writing something scalar with If you were to use simd, it'd be https://godbolt.org/z/3Tde55dhd
Please let me know if this is what you were asking. P.S.
|
Beta Was this translation helpful? Give feedback.
-
Thank you for answering. I was asking about a simpler syntax issue. Given:
I would like to apply |
Beta Was this translation helpful? Give feedback.
-
You need span to be a const value. Otherwise you might be in trouble. https://godbolt.org/z/Y3Tf9Kd3n
see std::ranges borrowed range for context https://en.cppreference.com/w/cpp/ranges/borrowed_range |
Beta Was this translation helpful? Give feedback.
-
Fyi: you don't need eve to vectorize max value. Compiler can, if you use std:: reduce with max as your op. I will write you an example later today |
Beta Was this translation helpful? Give feedback.
-
std max element is slower then std reduce because it returns position. Do you want a iterator (position) or just value? If you want iterator you should use element. If you want value you use value. |
Beta Was this translation helpful? Give feedback.
-
My numbers (I measured min) This is all the algorithms you can do to get min std::min_element is 5 tmes slower then slowest from other, let's remove it We are left with 2 You can ahieve this without eve like this (https://godbolt.org/z/nhEj46c9P):
|
Beta Was this translation helpful? Give feedback.
-
BTW, the benchmarks I've run are in https://github.com/pauljurczak/simd-benchmarks/blob/main/main-2-eve.cpp. Eve performs very well:
but produces a wrong result, which is most likely my error, see |
Beta Was this translation helpful? Give feedback.
You need span to be a const value. Otherwise you might be in trouble.
https://godbolt.org/z/Y3Tf9Kd3n
see std::ranges borrowed range for context https://en.cppreference.com/w/cpp/ranges/borrowed_range