Skip to content

Commit

Permalink
Update impulse/lfsr.nim
Browse files Browse the repository at this point in the history
Improve handling of seqs.

Co-authored-by: Vindaar <[email protected]>
  • Loading branch information
AngelEzquerra and Vindaar committed Apr 15, 2024
1 parent 9ec3450 commit 85b02b9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions impulse/lfsr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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=}")
Expand Down

0 comments on commit 85b02b9

Please sign in to comment.