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

flake8 for fourier.py

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