提交 54e518d3 authored 作者: Frederic's avatar Frederic

pep8

上级 4849e4bb
...@@ -10,7 +10,7 @@ from theano import tensor ...@@ -10,7 +10,7 @@ from theano import tensor
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
import theano.sandbox.cuda as cuda_ndarray import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False: if not cuda_ndarray.cuda_available:
raise SkipTest('Optional package cuda disabled') raise SkipTest('Optional package cuda disabled')
from theano.sandbox.cuda.basic_ops import (GpuDimShuffle, from theano.sandbox.cuda.basic_ops import (GpuDimShuffle,
...@@ -31,6 +31,7 @@ else: ...@@ -31,6 +31,7 @@ else:
def setup(): def setup():
utt.seed_rng() utt.seed_rng()
def blocksparse_data(): def blocksparse_data():
nInputBlock = 128 nInputBlock = 128
nOutputBlock = 64 nOutputBlock = 64
...@@ -41,13 +42,18 @@ def blocksparse_data(): ...@@ -41,13 +42,18 @@ def blocksparse_data():
batchSize = 2 batchSize = 2
input = randn(batchSize, inputWindowSize, inputSize).astype('float32') input = randn(batchSize, inputWindowSize, inputSize).astype('float32')
inputIndice = numpy.vstack(numpy.random.permutation(nInputBlock)[:inputWindowSize] for _ in range(batchSize)) permutation = numpy.random.permutation
outputIndice = numpy.vstack(numpy.random.permutation(nOutputBlock)[:outputWindowSize] for _ in range(batchSize)) inputIndice = numpy.vstack(permutation(nInputBlock)[:inputWindowSize]
weight = randn(nInputBlock, nOutputBlock, inputSize, outputSize).astype('float32') for _ in range(batchSize))
outputIndice = numpy.vstack(permutation(nOutputBlock)[:outputWindowSize]
for _ in range(batchSize))
weight = randn(nInputBlock, nOutputBlock,
inputSize, outputSize).astype('float32')
bias = randn(nOutputBlock, outputSize).astype('float32') bias = randn(nOutputBlock, outputSize).astype('float32')
return weight, input, inputIndice, bias, outputIndice return weight, input, inputIndice, bias, outputIndice
def blocksparse(W, h, iIdx, b, oIdx): def blocksparse(W, h, iIdx, b, oIdx):
o = b.take(oIdx, axis=0) o = b.take(oIdx, axis=0)
...@@ -122,6 +128,7 @@ def test_blocksparse_grad(): ...@@ -122,6 +128,7 @@ def test_blocksparse_grad():
utt.verify_grad(f, [b_val, h_val, W_val]) utt.verify_grad(f, [b_val, h_val, W_val])
def test_blocksparse_grad_1(): def test_blocksparse_grad_1():
# This tests that we correctly handle cases where dimensions are 1. # This tests that we correctly handle cases where dimensions are 1.
h_val = randn(1, 1, 1).astype('float32') h_val = randn(1, 1, 1).astype('float32')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论