Skip to content

Instantly share code, notes, and snippets.

@larsoner
Created May 18, 2020 17:57
Show Gist options
  • Save larsoner/c00e955215b6d12507163005dbb5179f to your computer and use it in GitHub Desktop.
Save larsoner/c00e955215b6d12507163005dbb5179f to your computer and use it in GitHub Desktop.
Testing length calculations for upfirdn
import numpy as np
def output_lens(len_h, in_len, up, down):
in_len_copy = in_len + (len_h + (-len_h % up)) // up - 1
nt = in_len_copy * up
need = nt // down
if nt % down > 0:
need += 1
# need2 = int(np.ceil((in_len * up + len_h - 1) / down))
need3 = int(np.ceil(((in_len - 1) * up + len_h) / down))
need4 = int(np.floor(((in_len - 1) * up + len_h) / down))
return (need, need3, need4)
results = []
count = 0
known_ratios = set()
known_lens = set()
for len_h in range(2, 33):
for in_len in range(2, 33):
for up in range(1, 7):
for down in range(1, 7):
this = output_lens(len_h, in_len, up, down)
if len(this) == len(np.unique(this)):
if (up, down) in known_ratios:
continue
if (len_h, in_len) in known_lens:
continue
known_ratios.add((up, down))
known_lens.add((len_h, in_len))
print(len_h, in_len, up, down)
count += 1
if count == 20:
raise RuntimeError()
results.append([len_h, in_len] + list(this))
results = np.array(results)
assert results.dtype == np.int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment