From 85b02b9e41d687c2bd3adbb5edca0d0bd2961462 Mon Sep 17 00:00:00 2001 From: Angel Ezquerra Date: Tue, 26 Mar 2024 18:09:51 +0100 Subject: [PATCH] Update impulse/lfsr.nim Improve handling of seqs. Co-authored-by: Vindaar --- impulse/lfsr.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/impulse/lfsr.nim b/impulse/lfsr.nim index 73aed85..9ca39ac 100644 --- a/impulse/lfsr.nim +++ b/impulse/lfsr.nim @@ -69,10 +69,9 @@ proc initLFSR*(taps: Tensor[int] | seq[int], ## - Ready to use LFSR object # Remove the last value from taps if it is a zero - when typeof(taps) is Tensor: - let taps = if taps[taps.size - 1] == 0: taps[_..^2] else: taps - else: - let taps = if taps[taps.size - 1] == 0: taps.toTensor[_..^2] else: taps.toTensor + var taps = when typeof(taps) is Tensor: taps else: taps.toTensor + if taps[taps.size - 1] == 0: + taps = taps[_..^2] if taps.size > 1 and not taps.toSeq1D.isSorted(order = SortOrder.Descending): raise newException(ValueError, &"The LFSR polynomial must be ordered in descending exponent order, but it is not:\n{taps=}")