提交 1050bcbe authored 作者: Iban Harlouchet's avatar Iban Harlouchet

flake8 for fourier.py

上级 87850539
"""Provides Ops for FFT and DCT.
"""
from theano.gof import Op, Apply, generic
from theano import tensor
import numpy.fft
import numpy
import numpy.fft
from six.moves import xrange
from theano import tensor
from theano.gof import Op, Apply, generic
class GradTodo(Op):
def make_node(self, x):
return Apply(self, [x], [x.type()])
def perform(self, node, inputs, outputs):
raise NotImplementedError('TODO')
grad_todo = GradTodo()
......@@ -45,8 +46,9 @@ class FFT(Op):
self.inverse = inverse
def __eq__(self, other):
return type(self) == type(other) and (self.half == other.half) and (self.inverse ==
other.inverse)
return (type(self) == type(other) and
self.half == other.half and
self.inverse == other.inverse)
def __hash__(self):
return hash(type(self)) ^ hash(self.half) ^ 9828743 ^ (self.inverse)
......@@ -77,21 +79,22 @@ class FFT(Op):
else:
fft_fn = numpy.fft.fft
fft = fft_fn(frames, int(n), int(axis))
fft = fft_fn(frames, int(n), int(axis))
if self.half:
M, N = fft.shape
if axis == 0:
if (M % 2):
raise ValueError('halfFFT on odd-length vectors is undefined')
spectrogram[0] = fft[0:M/2, :]
spectrogram[0] = fft[0:M / 2, :]
elif axis == 1:
if (N % 2):
raise ValueError('halfFFT on odd-length vectors is undefined')
spectrogram[0] = fft[:, 0:N/2]
spectrogram[0] = fft[:, 0:N / 2]
else:
raise NotImplementedError()
else:
spectrogram[0] = fft
def grad(self, inp, out):
frames, n, axis = inp
g_spectrogram, g_buf = out
......@@ -112,9 +115,9 @@ def dct_matrix(rows, cols, unitary=True):
"""
rval = numpy.zeros((rows, cols))
col_range = numpy.arange(cols)
scale = numpy.sqrt(2.0/cols)
scale = numpy.sqrt(2.0 / cols)
for i in xrange(rows):
rval[i] = numpy.cos(i * (col_range*2+1)/(2.0 * cols) * numpy.pi) * scale
rval[i] = numpy.cos(i * (col_range * 2 + 1) / (2.0 * cols) * numpy.pi) * scale
if unitary:
rval[0] *= numpy.sqrt(0.5)
......
......@@ -137,7 +137,6 @@ whitelist_flake8 = [
"sandbox/rng_mrg.py",
"sandbox/theano_object.py",
"sandbox/scan.py",
"sandbox/fourier.py",
"sandbox/test_multinomial.py",
"sandbox/minimal.py",
"sandbox/test_rng_mrg.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论