Is alwaysBeen
from the MTL module inefficient?
#569
Unanswered
ivanperez-keera
asked this question in
Q&A
Replies: 1 comment
-
I wonder if it's be more efficient to do the following. This is a simplification for the case where the bounds are from n steps ago to 0 steps ago: alwaysBeen n s = constant n == numTruesInWindow
where
-- Number of true values from 0 samples ago to n samples ago
numTruesInWindow :: Stream Word64
numTruesInWindow = count s - count sNAgo
-- Stream s, but n samples ago. We introduce Falses since we are counting
-- the Trues
sNAgo :: Stream Bool
sNAgo = replicate n False ++ s
count :: Stream Bool -> Stream Word64
count = integrate . toInt
integrate :: Stream Word64 -> Stream Word64
integrate s = g
where
g = s + ([0] ++ g)
toInt :: Stream Bool -> Stream Int
toInt s = ifThenElse s 1 0 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm doing some tests, and the amount of code generated for an
alwaysBeen
is huge. Is there a way to make this shorter?What would the ideal look like in C?
Beta Was this translation helpful? Give feedback.
All reactions