Unverified 提交 24371c1d authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: GitHub

Merge pull request #9 from dfm/update-upstream

Update to head of upstream Theano master branch
...@@ -36,7 +36,8 @@ install: ...@@ -36,7 +36,8 @@ install:
- source activate pyenv - source activate pyenv
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install pydot; else pip install pydot-ng; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install pydot; else pip install pydot-ng; fi
- pip install . --no-deps --upgrade - pip install . --no-deps --upgrade
- pip install flake8-future-import parameterized sphinx_rtd_theme - pip install flake8-future-import parameterized
- if [[ $TRAVIS_PYTHON_VERSION != '3.4' ]]; then pip install sphinx_rtd_theme; fi
# nose-exclude plugin allow us to tell nosetests to exclude folder with --exclude-dir=path/to/directory. # nose-exclude plugin allow us to tell nosetests to exclude folder with --exclude-dir=path/to/directory.
- pip install nose-exclude nose-timer - pip install nose-exclude nose-timer
- if [[ $NUMPY_VERSION == '1.13.1' ]]; then conda install --yes -q scipy=0.19.1; else conda install --yes -q scipy=0.14; fi # Try to reinstall it to fix the problem - if [[ $NUMPY_VERSION == '1.13.1' ]]; then conda install --yes -q scipy=0.19.1; else conda install --yes -q scipy=0.14; fi # Try to reinstall it to fix the problem
...@@ -52,9 +53,9 @@ jobs: ...@@ -52,9 +53,9 @@ jobs:
- <<: *doctest - <<: *doctest
python: "2.7" python: "2.7"
env: NUMPY_VERSION=1.13.1 DOC=1 PART="theano/tests/test_flake8.py" env: NUMPY_VERSION=1.13.1 DOC=1 PART="theano/tests/test_flake8.py"
- <<: *doctest # - <<: *doctest
python: "3.4" # python: "3.4"
env: NUMPY_VERSION=1.9.1 DOC=1 PART="theano/tests/test_flake8.py" # env: NUMPY_VERSION=1.9.1 DOC=1 PART="theano/tests/test_flake8.py"
- <<: *doctest - <<: *doctest
python: "3.6" python: "3.6"
env: NUMPY_VERSION=1.13.1 DOC=1 PART="theano/tests/test_flake8.py" env: NUMPY_VERSION=1.13.1 DOC=1 PART="theano/tests/test_flake8.py"
......
...@@ -552,7 +552,7 @@ TensorVariable ...@@ -552,7 +552,7 @@ TensorVariable
.. method:: nonzero_values(self) .. method:: nonzero_values(self)
.. method:: sort(self, axis=-1, kind='quicksort', order=None) .. method:: sort(self, axis=-1, kind='quicksort', order=None)
.. method:: argsort(self, axis=-1, kind='quicksort', order=None) .. method:: argsort(self, axis=-1, kind='quicksort', order=None)
.. method:: clip(self, a_min, a_max) .. method:: clip(self, a_min, a_max) with a_min <= a_max
.. method:: conf() .. method:: conf()
.. method:: repeat(repeats, axis=None) .. method:: repeat(repeats, axis=None)
.. method:: round(mode="half_away_from_zero") .. method:: round(mode="half_away_from_zero")
...@@ -1350,6 +1350,9 @@ Condition ...@@ -1350,6 +1350,9 @@ Condition
Normal broadcasting rules apply to each of `x`, `min`, and `max`. Normal broadcasting rules apply to each of `x`, `min`, and `max`.
Note that there is no warning for inputs that are the wrong way round
(`min > max`), and that results in this case may differ from ``numpy.clip``.
Bit-wise Bit-wise
-------- --------
......
...@@ -70,7 +70,14 @@ if __name__ == '__main__': ...@@ -70,7 +70,14 @@ if __name__ == '__main__':
inopt = [docpath, workdir] inopt = [docpath, workdir]
if files is not None: if files is not None:
inopt.extend(files) inopt.extend(files)
ret = sphinx.build_main(['', '-b', builder] + extraopts + inopt) try:
import sphinx.cmd.build
ret = sphinx.cmd.build.build_main(
['-b', builder] + extraopts + inopt)
except ImportError:
# Sphinx < 1.7 - build_main drops first argument
ret = sphinx.build_main(
['', '-b', builder] + extraopts + inopt)
if ret != 0: if ret != 0:
sys.exit(ret) sys.exit(ret)
......
...@@ -261,7 +261,7 @@ class Mode(object): ...@@ -261,7 +261,7 @@ class Mode(object):
def __init__(self, linker=None, optimizer='default'): def __init__(self, linker=None, optimizer='default'):
if linker is None: if linker is None:
linker = config.linker linker = config.linker
if optimizer is 'default': if type(optimizer) == str and optimizer == 'default':
optimizer = config.optimizer optimizer = config.optimizer
Mode.__setstate__(self, (linker, optimizer)) Mode.__setstate__(self, (linker, optimizer))
......
...@@ -1540,12 +1540,12 @@ class COp(Op): ...@@ -1540,12 +1540,12 @@ class COp(Op):
undef_macros = [] undef_macros = []
for i, inp in enumerate(inputs): for i, inp in enumerate(inputs):
define_macros.append("#define INPUT_%d %s" (i, inp)) define_macros.append("#define INPUT_%d %s" % (i, inp))
undef_macros.append("#undef INPUT_%d", (i,)) undef_macros.append("#undef INPUT_%d" % (i,))
for i, out in enumerate(outputs): for i, out in enumerate(outputs):
define_macros.append("#define OUTPUT_%d %s" (i, inp)) define_macros.append("#define OUTPUT_%d %s" % (i, inp))
undef_macros.append("#undef OUTPUT_%d", (i,)) undef_macros.append("#undef OUTPUT_%d" % (i,))
def c_init_code_struct(self, node, name, sub): def c_init_code_struct(self, node, name, sub):
""" """
......
...@@ -1284,7 +1284,7 @@ def local_optimizer(tracks, inplace=False, requirements=()): ...@@ -1284,7 +1284,7 @@ def local_optimizer(tracks, inplace=False, requirements=()):
""" """
if tracks is not None: if tracks is not None:
if len(tracks) is 0: if len(tracks) == 0:
raise ValueError("Use None instead of an empty list to apply to all nodes.", f.__module__, f.__name__) raise ValueError("Use None instead of an empty list to apply to all nodes.", f.__module__, f.__name__)
for t in tracks: for t in tracks:
if not (isinstance(t, op.Op) or issubclass(t, op.PureOp)): if not (isinstance(t, op.Op) or issubclass(t, op.PureOp)):
......
...@@ -285,12 +285,13 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -285,12 +285,13 @@ class TestComputeTestValue(unittest.TestCase):
except ValueError: except ValueError:
# Get traceback # Get traceback
tb = sys.exc_info()[2] tb = sys.exc_info()[2]
# Get frame info 4 layers up frame_infos = traceback.extract_tb(tb)
frame_info = traceback.extract_tb(tb)[-5]
# We should be in the "fx" function defined above # We should be in the "fx" function defined above
expected = 'test_compute_test_value.py' expected = 'test_compute_test_value.py'
assert os.path.split(frame_info[0])[1] == expected, frame_info assert any((os.path.split(
assert frame_info[2] == 'fx' frame_info[0])[1] == expected and
frame_info[2] == 'fx') for frame_info in
frame_infos), frame_infos
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
......
...@@ -113,7 +113,7 @@ class TestPerformLinker(unittest.TestCase): ...@@ -113,7 +113,7 @@ class TestPerformLinker(unittest.TestCase):
def test_input_output_same(self): def test_input_output_same(self):
x, y, z = inputs() x, y, z = inputs()
fn = perform_linker(FunctionGraph([x], [x])).make_function() fn = perform_linker(FunctionGraph([x], [x])).make_function()
assert 1.0 is fn(1.0) assert 1.0 == fn(1.0)
def test_input_dependency0(self): def test_input_dependency0(self):
x, y, z = inputs() x, y, z = inputs()
......
...@@ -596,7 +596,7 @@ class GammaIncC(BinaryScalarOp): ...@@ -596,7 +596,7 @@ class GammaIncC(BinaryScalarOp):
if node.inputs[0].type in float_types: if node.inputs[0].type in float_types:
dtype = 'npy_' + node.outputs[0].dtype dtype = 'npy_' + node.outputs[0].dtype
return """%(z)s = return """%(z)s =
(%(dtype)s) gammaQ(%(k)s, %(x)s);""" % locals() (%(dtype)s) GammaQ(%(k)s, %(x)s);""" % locals()
raise NotImplementedError('only floatingpoint is implemented') raise NotImplementedError('only floatingpoint is implemented')
def __eq__(self, other): def __eq__(self, other):
......
...@@ -160,7 +160,15 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None, ...@@ -160,7 +160,15 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None,
if unsorted_indices: if unsorted_indices:
for idx in range(n): for idx in range(n):
d = data[idx] d = data[idx]
d = d[list(range(d.shape[0]))] # these flip the matrix, but it's random anyway
if format == 'csr':
d = scipy.sparse.csr_matrix(
(d.data, d.shape[1] - 1 - d.indices, d.indptr),
shape=d.shape)
if format == 'csc':
d = scipy.sparse.csc_matrix(
(d.data, d.shape[0] - 1 - d.indices, d.indptr),
shape=d.shape)
assert not d.has_sorted_indices assert not d.has_sorted_indices
data[idx] = d data[idx] = d
if explicit_zero: if explicit_zero:
......
...@@ -642,7 +642,7 @@ class AbstractBatchNormTrainGrad(Op): ...@@ -642,7 +642,7 @@ class AbstractBatchNormTrainGrad(Op):
# some inputs should be disconnected # some inputs should be disconnected
results = [g_wrt_x, g_wrt_dy, g_wrt_scale, g_wrt_x_mean, g_wrt_x_invstd, results = [g_wrt_x, g_wrt_dy, g_wrt_scale, g_wrt_x_mean, g_wrt_x_invstd,
theano.gradient.DisconnectedType()()] theano.gradient.DisconnectedType()()]
return [theano.gradient.DisconnectedType()() if r is 0 else r return [theano.gradient.DisconnectedType()() if (type(r) == int and r == 0) else r
for r in results] for r in results]
def connection_pattern(self, node): def connection_pattern(self, node):
......
...@@ -95,7 +95,7 @@ class TestConv2D(utt.InferShapeTester): ...@@ -95,7 +95,7 @@ class TestConv2D(utt.InferShapeTester):
# REFERENCE IMPLEMENTATION # REFERENCE IMPLEMENTATION
s = 1. s = 1.
orig_image_data = image_data orig_image_data = image_data
if border_mode is not 'full': if border_mode != 'full':
s = -1. s = -1.
out_shape2d = np.array(N_image_shape[-2:]) +\ out_shape2d = np.array(N_image_shape[-2:]) +\
s * np.array(N_filter_shape[-2:]) - s s * np.array(N_filter_shape[-2:]) - s
......
...@@ -45,6 +45,10 @@ class SortOp(theano.Op): ...@@ -45,6 +45,10 @@ class SortOp(theano.Op):
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
a = inputs[0] a = inputs[0]
axis = inputs[1] axis = inputs[1]
if axis is not None:
if axis != int(axis):
raise ValueError("sort axis must be an integer or None")
axis = int(axis)
z = output_storage[0] z = output_storage[0]
z[0] = np.sort(a, axis, self.kind, self.order) z[0] = np.sort(a, axis, self.kind, self.order)
...@@ -172,6 +176,10 @@ class ArgSortOp(theano.Op): ...@@ -172,6 +176,10 @@ class ArgSortOp(theano.Op):
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
a = inputs[0] a = inputs[0]
axis = inputs[1] axis = inputs[1]
if axis is not None:
if axis != int(axis):
raise ValueError("sort axis must be an integer or None")
axis = int(axis)
z = output_storage[0] z = output_storage[0]
z[0] = theano._asarray(np.argsort(a, axis, self.kind, self.order), z[0] = theano._asarray(np.argsort(a, axis, self.kind, self.order),
dtype=node.outputs[0].dtype) dtype=node.outputs[0].dtype)
......
...@@ -2835,11 +2835,7 @@ ClipTester = makeTester( ...@@ -2835,11 +2835,7 @@ ClipTester = makeTester(
correct6=(randint(5, 5).astype('int64'), correct6=(randint(5, 5).astype('int64'),
np.array(-1, dtype='int64'), np.array(-1, dtype='int64'),
np.array(1, dtype='int64')), np.array(1, dtype='int64')),
# min > max. messed up behaviour, but # min > max case moved below as numpy has changed
# should be same as NumPy's
correct7=((5 * rand(5, 5)).astype('float64'),
np.array(1, dtype='float64'),
np.array(-1, dtype='float64')),
correct8=(randint(0, 5).astype('uint8'), correct8=(randint(0, 5).astype('uint8'),
np.array(2, dtype='uint8'), np.array(2, dtype='uint8'),
np.array(4, dtype='uint8')), np.array(4, dtype='uint8')),
...@@ -2850,6 +2846,18 @@ ClipTester = makeTester( ...@@ -2850,6 +2846,18 @@ ClipTester = makeTester(
) )
# min > max case - numpy.clip has changed but we haven't
# https://github.com/Theano/Theano/issues/6715
BackwardsClipTester = makeTester(
name='BackwardsClipTester',
op=clip,
expected=lambda x, y, z: np.where(x < y, y, np.minimum(x, z)),
good=dict(correct7=((5 * rand(5, 5)).astype('float64'),
np.array(1, dtype='float64'),
np.array(-1, dtype='float64')),)
)
class T_Clip(unittest.TestCase): class T_Clip(unittest.TestCase):
def test_complex_value(self): def test_complex_value(self):
for dtype in ['complex64', 'complex128']: for dtype in ['complex64', 'complex128']:
......
...@@ -678,10 +678,10 @@ class T_random_function(utt.InferShapeTester): ...@@ -678,10 +678,10 @@ class T_random_function(utt.InferShapeTester):
numpy_val1c = as_floatX(numpy_rng.uniform(low=[-4.], high=[-1])) numpy_val1c = as_floatX(numpy_rng.uniform(low=[-4.], high=[-1]))
assert np.all(val0c == numpy_val0c) assert np.all(val0c == numpy_val0c)
assert np.all(val1c == numpy_val1c) assert np.all(val1c == numpy_val1c)
self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [1]) #self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [1])
self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [1, 2]) self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [1, 2])
self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [2, 1]) self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1, 0], [2, 1])
self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1], [1]) #self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1], [1])
# TODO: do we want that? # TODO: do we want that?
#self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1], [2]) #self.assertRaises(ValueError, fc, post1c, [-4., -2], [-1], [2])
......
...@@ -466,10 +466,10 @@ class T_SharedRandomStreams(unittest.TestCase): ...@@ -466,10 +466,10 @@ class T_SharedRandomStreams(unittest.TestCase):
numpy_val1c = numpy_rng.uniform(low=[-4.], high=[-1]) numpy_val1c = numpy_rng.uniform(low=[-4.], high=[-1])
assert np.all(val0c == numpy_val0c) assert np.all(val0c == numpy_val0c)
assert np.all(val1c == numpy_val1c) assert np.all(val1c == numpy_val1c)
self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1]) #self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1])
self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1, 2]) self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1, 2])
self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [2, 1]) self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [2, 1])
self.assertRaises(ValueError, fc, [-4., -2], [-1], [1]) #self.assertRaises(ValueError, fc, [-4., -2], [-1], [1])
# TODO: do we want that? # TODO: do we want that?
#self.assertRaises(ValueError, fc, [-4., -2], [-1], [2]) #self.assertRaises(ValueError, fc, [-4., -2], [-1], [2])
......
...@@ -247,6 +247,15 @@ class _tensor_py_operators(object): ...@@ -247,6 +247,15 @@ class _tensor_py_operators(object):
def __rpow__(self, other): def __rpow__(self, other):
return theano.tensor.basic.pow(other, self) return theano.tensor.basic.pow(other, self)
def __ceil__(self):
return theano.tensor.ceil(self)
def __floor__(self):
return theano.tensor.floor(self)
def __trunc__(self):
return theano.tensor.trunc(self)
# TRANSPOSE # TRANSPOSE
T = property(lambda self: theano.tensor.basic.transpose(self)) T = property(lambda self: theano.tensor.basic.transpose(self))
......
...@@ -57,7 +57,7 @@ def test_determinism_1(): ...@@ -57,7 +57,7 @@ def test_determinism_1():
updates.append((s, val)) updates.append((s, val))
for var in theano.gof.graph.ancestors(update for _, update in updates): for var in theano.gof.graph.ancestors(update for _, update in updates):
if var.name is not None and var.name is not 'b': if var.name is not None and var.name != 'b':
if var.name[0] != 's' or len(var.name) != 2: if var.name[0] != 's' or len(var.name) != 2:
var.name = None var.name = None
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论