提交 385f7230 authored 作者: Benjamin Scellier's avatar Benjamin Scellier

file theano/gpuarray/tests/test_nnet.py

上级 fffa9076
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import numpy import numpy as np
import unittest import unittest
import theano import theano
...@@ -46,13 +46,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -46,13 +46,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
# Seed numpy.random with config.unittests.rseed # Seed numpy.random with config.unittests.rseed
utt.seed_rng() utt.seed_rng()
xx = numpy.asarray(numpy.random.rand(batch_size, n_in), xx = np.asarray(np.random.rand(batch_size, n_in),
dtype=numpy.float32) dtype=np.float32)
yy = numpy.ones((batch_size,), dtype='int32') yy = np.ones((batch_size,), dtype='int32')
b_values = numpy.zeros((n_out,), dtype='float32') b_values = np.zeros((n_out,), dtype='float32')
W_values = numpy.asarray(numpy.random.rand(n_in, n_out), dtype='float32') W_values = np.asarray(np.random.rand(n_in, n_out), dtype='float32')
dot_value = numpy.asarray(numpy.dot(xx, W_values), dtype='float32') dot_value = np.asarray(np.dot(xx, W_values), dtype='float32')
del W_values del W_values
p_y_given_x = T.nnet.softmax(dot_result + b) p_y_given_x = T.nnet.softmax(dot_result + b)
y_pred = T.argmax(p_y_given_x, axis=-1) y_pred = T.argmax(p_y_given_x, axis=-1)
...@@ -97,10 +97,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -97,10 +97,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
# Seed numpy.random with config.unittests.rseed # Seed numpy.random with config.unittests.rseed
utt.seed_rng() utt.seed_rng()
softmax_output_value = numpy.random.rand(batch_size, softmax_output_value = np.random.rand(batch_size,
n_out).astype('float32') n_out).astype('float32')
dnll_value = numpy.asarray(numpy.random.rand(batch_size), dtype='float32') dnll_value = np.asarray(np.random.rand(batch_size), dtype='float32')
y_idx_value = numpy.random.randint(low=0, high=5, size=batch_size) y_idx_value = np.random.randint(low=0, high=5, size=batch_size)
softmax_output = T.fmatrix() softmax_output = T.fmatrix()
softmax_output /= softmax_output.sum(axis=1).reshape( softmax_output /= softmax_output.sum(axis=1).reshape(
...@@ -174,8 +174,8 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias): ...@@ -174,8 +174,8 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
GpuSoftmaxWithBias) GpuSoftmaxWithBias)
def cmp(n, m): def cmp(n, m):
data = numpy.random.uniform(1e-7, 1, (n, m)).astype(dtype=dtypeInput) data = np.random.uniform(1e-7, 1, (n, m)).astype(dtype=dtypeInput)
b_data = numpy.random.uniform(1e-7, 1, (m,)).astype(dtype=dtypeBias) b_data = np.random.uniform(1e-7, 1, (m,)).astype(dtype=dtypeBias)
out = f(data, b_data) out = f(data, b_data)
gout = f_gpu(data, b_data) gout = f_gpu(data, b_data)
...@@ -227,7 +227,7 @@ def softmax_unittest_template(dtypeInput): ...@@ -227,7 +227,7 @@ def softmax_unittest_template(dtypeInput):
GpuSoftmax) GpuSoftmax)
def cmp(n, m): def cmp(n, m):
data = numpy.random.uniform(0, 1, (n, m)).astype(dtype=dtypeInput) data = np.random.uniform(0, 1, (n, m)).astype(dtype=dtypeInput)
out = f(data) out = f(data)
gout = f_gpu(data) gout = f_gpu(data)
...@@ -301,7 +301,7 @@ class test_SoftMax(unittest.TestCase): ...@@ -301,7 +301,7 @@ class test_SoftMax(unittest.TestCase):
return f, f_gpu return f, f_gpu
def _cmp(self, n, m, f, f_gpu): def _cmp(self, n, m, f, f_gpu):
data = numpy.arange(n * m, dtype='float32').reshape(n, m) data = np.arange(n * m, dtype='float32').reshape(n, m)
out = f(data) out = f(data)
gout = f_gpu(data) gout = f_gpu(data)
utt.assert_allclose(out, gout) utt.assert_allclose(out, gout)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论