The comment "# This if block is unlikely to be run after we build sin/cos in __init__. Keep the logic here just in case." might be incorrect. From what I understand, the code following this comment calculates the scale value based on the actual length of the input. However, the value cached in __init__ is unscaled. Therefore, this branch should be executed frequently.
The new values for cos_cached and sin_cached shouldn't be cached. If they are, after encountering a long sample, all subsequent samples will use the scaled values, regardless of their length.
The comment "# This
if
block is unlikely to be run after we build sin/cos in__init__
. Keep the logic here just in case." might be incorrect. From what I understand, the code following this comment calculates the scale value based on the actual length of the input. However, the value cached in__init__
is unscaled. Therefore, this branch should be executed frequently.The new values for
cos_cached
andsin_cached
shouldn't be cached. If they are, after encountering a long sample, all subsequent samples will use the scaled values, regardless of their length.