提交 3a2029b7 authored 作者: nouiz's avatar nouiz

Merge pull request #840 from lamblin/travis

Try to see which tests trigger build failure No NEST.txt, fix to new op since the last release.
......@@ -841,7 +841,7 @@ class T_Scan(unittest.TestCase):
(theano_x0, theano_x1) = f9(vu0, vu1, vu2, vx0, vx1)
# assert that theano does what it should
assert numpy.allclose(theano_x0, numpy_x0)
assert numpy.allclose(theano_x1, numpy_x1)
assert numpy.allclose(theano_x1, numpy_x1), (theano_x1, numpy_x1, theano_x1 - numpy_x1)
# assert that it was done in place
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
......
......@@ -3,7 +3,7 @@ import numpy
import theano
import basic
from theano import gof, tensor, function, scalar
from theano import gof, tensor, scalar
from theano.sandbox.linalg.ops import diag
......@@ -132,6 +132,21 @@ class BinCountOp(theano.Op):
if x.dtype not in BinCountOp.compatible_type:
raise TypeError("Inputs dtype must be an integer.")
# Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
int_bitwidth = theano.gof.cmodule.python_int_bitwidth()
if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
if x.dtype in numpy_unsupported_dtypes:
raise TypeError(
("Input dtypes %s are not supported by numpy.bincount, "
% numpy_unsupported_dtypes), x.dtype)
if x.ndim != 1:
raise TypeError("Inputs must be of dimension 1.")
......@@ -286,6 +301,25 @@ class RepeatOp(theano.Op):
def make_node(self, x, repeats):
x = basic.as_tensor_variable(x)
repeats = basic.as_tensor_variable(repeats)
if repeats.dtype not in tensor.discrete_dtypes:
raise TypeError("repeats.dtype must be an integer.")
# Some dtypes are not supported by numpy's implementation of repeat.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
int_bitwidth = theano.gof.cmodule.python_int_bitwidth()
if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
if repeats.dtype in numpy_unsupported_dtypes:
raise TypeError(
("dtypes %s are not supported by numpy.repeat "
"for the 'repeats' parameter, "
% numpy_unsupported_dtypes), repeats.dtype)
if self.axis is None:
out_type = theano.tensor.TensorType(dtype=x.dtype,
broadcastable=[False])
......
......@@ -970,7 +970,7 @@ class ShapeFeature(object):
# but this works with `local_useless_subtensor`, so for now we
# keep it this way. See #266 for a better long-term fix.
if getattr(d, 'dtype', 'int64') != 'int64':
assert d.dtype in theano.tensor.int_dtypes
assert d.dtype in theano.tensor.discrete_dtypes, d.dtype
new_shape += sh[len(new_shape):i + 1]
new_shape[i] = theano.tensor.cast(d, 'int64')
if new_shape:
......
......@@ -3,9 +3,11 @@ import numpy
import theano
from theano.tests import unittest_tools as utt
from theano.tensor.extra_ops import *
from theano.tensor.extra_ops import (BinCountOp, bincount, DiffOp, diff,
SqueezeOp, squeeze, RepeatOp, repeat, Bartlett, bartlett,
FillDiagonal, fill_diagonal)
from theano import tensor as T
from theano import config, tensor, function, scalar
from theano import config, tensor, function
class TestBinCountOp(utt.InferShapeTester):
......@@ -15,44 +17,81 @@ class TestBinCountOp(utt.InferShapeTester):
self.op = BinCountOp()
def test_bincountOp(self):
x = T.lvector('x')
w = T.vector('w')
a = np.random.random_integers(50, size=(25))
weights = np.random.random((25,)).astype(config.floatX)
f1 = theano.function([x], bincount(x))
f2 = theano.function([x, w], bincount(x, weights=w))
f3 = theano.function([x], bincount(x, minlength=23))
f4 = theano.function([x], bincount(x, minlength=5))
assert (np.bincount(a) == f1(a)).all()
assert np.allclose(np.bincount(a, weights=weights), f2(a, weights))
assert (np.bincount(a, minlength=23) == f3(a)).all()
assert (np.bincount(a, minlength=5) == f3(a)).all()
for dtype in ('int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64'):
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth()
if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
x = T.vector('x', dtype=dtype)
if dtype in numpy_unsupported_dtypes:
self.assertRaises(TypeError, bincount, x)
else:
a = np.random.random_integers(50, size=(25)).astype(dtype)
weights = np.random.random((25,)).astype(config.floatX)
f1 = theano.function([x], bincount(x))
f2 = theano.function([x, w], bincount(x, weights=w))
f3 = theano.function([x], bincount(x, minlength=23))
f4 = theano.function([x], bincount(x, minlength=5))
assert (np.bincount(a) == f1(a)).all()
assert np.allclose(np.bincount(a, weights=weights),
f2(a, weights))
assert (np.bincount(a, minlength=23) == f3(a)).all()
assert (np.bincount(a, minlength=5) == f4(a)).all()
def test_infer_shape(self):
x = T.lvector('x')
self._compile_and_check([x],
[bincount(x)],
[np.random.random_integers(50, size=(25,))],
self.op_class)
weights = np.random.random((25,)).astype(config.floatX)
self._compile_and_check([x],
[bincount(x, weights=weights)],
[np.random.random_integers(50, size=(25,))],
self.op_class)
self._compile_and_check([x],
[bincount(x, minlength=60)],
[np.random.random_integers(50, size=(25,))],
self.op_class)
self._compile_and_check([x],
[bincount(x, minlength=5)],
[np.random.random_integers(50, size=(25,))],
self.op_class)
for dtype in tensor.discrete_dtypes:
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth()
if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
x = T.vector('x', dtype=dtype)
if dtype in numpy_unsupported_dtypes:
self.assertRaises(TypeError, bincount, x)
else:
self._compile_and_check(
[x],
[bincount(x)],
[np.random.random_integers(
50, size=(25,)).astype(dtype)],
self.op_class)
weights = np.random.random((25,)).astype(config.floatX)
self._compile_and_check(
[x],
[bincount(x, weights=weights)],
[np.random.random_integers(
50, size=(25,)).astype(dtype)],
self.op_class)
self._compile_and_check(
[x],
[bincount(x, minlength=60)],
[np.random.random_integers(
50, size=(25,)).astype(dtype)],
self.op_class)
self._compile_and_check(
[x],
[bincount(x, minlength=5)],
[np.random.random_integers(
50, size=(25,)).astype(dtype)],
self.op_class)
class TestDiffOp(utt.InferShapeTester):
......@@ -95,11 +134,11 @@ class TestDiffOp(utt.InferShapeTester):
x = T.vector('x')
a = np.random.random(50).astype(config.floatX)
gf = theano.function([x], T.grad(T.sum(diff(x)), x))
theano.function([x], T.grad(T.sum(diff(x)), x))
utt.verify_grad(self.op, [a])
for k in range(TestDiffOp.nb):
dg = theano.function([x], T.grad(T.sum(diff(x, n=k)), x))
theano.function([x], T.grad(T.sum(diff(x, n=k)), x))
utt.verify_grad(DiffOp(n=k), [a], eps=7e-3)
......@@ -132,7 +171,7 @@ class TestSqueezeOp(utt.InferShapeTester):
x = T.tensor4('x')
a = np.random.random((1, 1, 3, 4)).astype(config.floatX)
gf = theano.function([x], T.grad(T.sum(squeeze(x, out_nd=1)), x))
theano.function([x], T.grad(T.sum(squeeze(x, out_nd=1)), x))
utt.verify_grad(SqueezeOp(out_nd=2), [a])
......@@ -144,6 +183,13 @@ class TestRepeatOp(utt.InferShapeTester):
super(TestRepeatOp, self).setUp()
self.op_class = RepeatOp
self.op = RepeatOp()
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.cmodule.python_int_bitwidth()
if int_bitwidth == 64:
self.numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
self.numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
def test_repeatOp(self):
for ndim in range(3):
......@@ -151,19 +197,30 @@ class TestRepeatOp(utt.InferShapeTester):
a = np.random.random((10, ) * ndim).astype(config.floatX)
for axis in self._possible_axis(ndim):
r_var = T.lscalar()
r = 3
f = theano.function([x, r_var], repeat(x, r_var, axis=axis))
assert np.allclose(np.repeat(a, r, axis=axis), f(a, r))
r_var = T.lvector()
if axis is None:
r = np.random.random_integers(5, size=a.size)
else:
r = np.random.random_integers(5, size=(10,))
f = theano.function([x, r_var], repeat(x, r_var, axis=axis))
assert np.allclose(np.repeat(a, r, axis=axis), f(a, r))
for dtype in tensor.discrete_dtypes:
r_var = T.scalar(dtype=dtype)
r = numpy.asarray(3, dtype=dtype)
if dtype in self.numpy_unsupported_dtypes:
self.assertRaises(TypeError,
repeat, x, r_var, axis=axis)
else:
f = theano.function([x, r_var],
repeat(x, r_var, axis=axis))
assert np.allclose(np.repeat(a, r, axis=axis),
f(a, r))
r_var = T.vector(dtype=dtype)
if axis is None:
r = np.random.random_integers(
5, size=a.size).astype(dtype)
else:
r = np.random.random_integers(
5, size=(10,)).astype(dtype)
f = theano.function([x, r_var],
repeat(x, r_var, axis=axis))
assert np.allclose(np.repeat(a, r, axis=axis),
f(a, r))
def test_infer_shape(self):
for ndim in range(4):
......@@ -171,23 +228,31 @@ class TestRepeatOp(utt.InferShapeTester):
a = np.random.random((10, ) * ndim).astype(config.floatX)
for axis in self._possible_axis(ndim):
r_var = T.lscalar()
r = 3
self._compile_and_check([x, r_var],
[RepeatOp(axis=axis)(x, r_var)],
[a, r],
self.op_class)
r_var = T.lvector()
if axis is None:
r = np.random.random_integers(5, size=a.size)
else:
r = np.random.random_integers(5, size=(10,))
for dtype in tensor.discrete_dtypes:
r_var = T.scalar(dtype=dtype)
r = numpy.asarray(3, dtype=dtype)
if dtype in self.numpy_unsupported_dtypes:
self.assertRaises(TypeError, repeat, x, r_var)
else:
self._compile_and_check(
[x, r_var],
[RepeatOp(axis=axis)(x, r_var)],
[a, r],
self.op_class)
self._compile_and_check([x, r_var],
[RepeatOp(axis=axis)(x, r_var)],
[a, r],
self.op_class)
r_var = T.vector(dtype=dtype)
if axis is None:
r = np.random.random_integers(
5, size=a.size).astype(dtype)
else:
r = np.random.random_integers(
5, size=(10,)).astype(dtype)
self._compile_and_check(
[x, r_var],
[RepeatOp(axis=axis)(x, r_var)],
[a, r],
self.op_class)
def test_grad(self):
for ndim in range(3):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论