From 1ceab58844bc82dcad5bdcfc99ee28baeb82c10f Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 16 Feb 2018 04:04:24 -0800 Subject: [PATCH] update 37 --- lib/sweeps.py | 9 +++++---- lib/util.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/sweeps.py b/lib/sweeps.py index 2051275..0fdbbff 100644 --- a/lib/sweeps.py +++ b/lib/sweeps.py @@ -1,4 +1,4 @@ -from . import tau +from . import tau, ceil2 import numpy as np @@ -37,15 +37,16 @@ def tsp(N, m=0.5): if N < 0: raise Exception("The number of length must be the positive number") - NN = int(2**np.floor(np.log2(N))) # nearest + NN = ceil2(N) NN2 = NN // 2 M = int(np.round(NN2 * m)) - nn2 = np.square(np.arange(NN2 + 1)) + # this has been tweaked to prevent overflow: + s = np.square(np.arange(NN2 + 1) / NN) j = np.complex(0, 1) - H = np.exp(j * 4 * M * np.pi * nn2 / np.square(NN)) + H = np.exp(j * 4 * M * np.pi * s) H2 = np.r_[H, np.conj(H[1:NN2][::-1])] x = np.fft.ifft(H2) diff --git a/lib/util.py b/lib/util.py index c9424a7..9262ead 100644 --- a/lib/util.py +++ b/lib/util.py @@ -36,7 +36,7 @@ def warp(w): def ceil2(x): - return np.power(2, np.ceil(np.log2(x))) + return np.power(2, np.ceil(np.log2(x)).astype(int)) def pad2(x):