As a continuation of my previous question, Simon's method to find the list product of a PackedArray is fast, but it does not work with negative values.
This can be "fixed" by Abs
with minimal time penalty, but the sign is lost, so I will need to find the product sign separately.
The fastest method that I tried is EvenQ @ Total @ UnitStep[-lst]
lst = RandomReal[{-2, 2}, 5000000];
Do[
EvenQ@Total@UnitStep[-lst],
{30}
] // Timing
Out[]= {3.062, Null}
Is there a faster way?
Count
but it was slow. I didn't get around to tryingTally
before I chose to post this question. This site and its helpful people could make me lazy. – Unmanned