提交 2ef1058b authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #1613 from nouiz/crash_fixes

Crash fixes
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
language: python language: python
python: python:
- "2.5" - "2.6"
# - "2.7" # - "2.7"
# - "3.2" # - "3.2"
# command to install dependencies # command to install dependencies
......
差异被折叠。
import os, sys, traceback, warnings import os
import sys
import traceback
import warnings
import numpy import numpy
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
...@@ -46,34 +49,33 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -46,34 +49,33 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4).astype(config.floatX) x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5).astype(config.floatX) y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
# should work # should work
z = T.dot(x,y) z = T.dot(x, y)
assert hasattr(z.tag, 'test_value') assert hasattr(z.tag, 'test_value')
f = theano.function([x,y], z) f = theano.function([x, y], z)
assert _allclose(f(x.tag.test_value, y.tag.test_value), assert _allclose(f(x.tag.test_value, y.tag.test_value),
z.tag.test_value) z.tag.test_value)
# this test should fail # this test should fail
y.tag.test_value = numpy.random.rand(6,5).astype(config.floatX) y.tag.test_value = numpy.random.rand(6, 5).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
def test_compute_flag(self): def test_compute_flag(self):
orig_compute_test_value = theano.config.compute_test_value orig_compute_test_value = theano.config.compute_test_value
try: try:
x = T.matrix('x') x = T.matrix('x')
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5).astype(config.floatX) y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
# should skip computation of test value # should skip computation of test value
theano.config.compute_test_value = 'off' theano.config.compute_test_value = 'off'
z = T.dot(x,y) z = T.dot(x, y)
assert not hasattr(z.tag, 'test_value') assert not hasattr(z.tag, 'test_value')
# should fail when asked by user # should fail when asked by user
...@@ -99,25 +101,25 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -99,25 +101,25 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4).astype(config.floatX) x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5).astype(config.floatX) y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
z = theano.shared(numpy.random.rand(5,6).astype(config.floatX)) z = theano.shared(numpy.random.rand(5, 6).astype(config.floatX))
# should work # should work
out = T.dot(T.dot(x,y), z) out = T.dot(T.dot(x, y), z)
assert hasattr(out.tag, 'test_value') assert hasattr(out.tag, 'test_value')
tf = theano.function([x,y], out) tf = theano.function([x, y], out)
assert _allclose( assert _allclose(
tf(x.tag.test_value, y.tag.test_value), tf(x.tag.test_value, y.tag.test_value),
out.tag.test_value) out.tag.test_value)
def f(x,y,z): def f(x, y, z):
return T.dot(T.dot(x,y),z) return T.dot(T.dot(x, y), z)
# this test should fail # this test should fail
z.set_value(numpy.random.rand(7,6).astype(config.floatX)) z.set_value(numpy.random.rand(7, 6).astype(config.floatX))
self.assertRaises(ValueError, f, x, y, z) self.assertRaises(ValueError, f, x, y, z)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -128,17 +130,18 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -128,17 +130,18 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4).astype(config.floatX) x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
y = theano.shared(numpy.random.rand(4,6).astype(config.floatX), 'y') y = theano.shared(numpy.random.rand(4, 6).astype(config.floatX),
'y')
# should work # should work
z = T.dot(x,y) z = T.dot(x, y)
assert hasattr(z.tag, 'test_value') assert hasattr(z.tag, 'test_value')
f = theano.function([x], z) f = theano.function([x], z)
assert _allclose(f(x.tag.test_value), z.tag.test_value) assert _allclose(f(x.tag.test_value), z.tag.test_value)
# this test should fail # this test should fail
y.set_value(numpy.random.rand(5,6).astype(config.floatX)) y.set_value(numpy.random.rand(5, 6).astype(config.floatX))
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -148,17 +151,18 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -148,17 +151,18 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = numpy.random.rand(2,3).astype(config.floatX) x = numpy.random.rand(2, 3).astype(config.floatX)
y = theano.shared(numpy.random.rand(3,6).astype(config.floatX), 'y') y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX),
'y')
# should work # should work
z = T.dot(x,y) z = T.dot(x, y)
assert hasattr(z.tag, 'test_value') assert hasattr(z.tag, 'test_value')
f = theano.function([], z) f = theano.function([], z)
assert _allclose(f(), z.tag.test_value) assert _allclose(f(), z.tag.test_value)
# this test should fail # this test should fail
x = numpy.random.rand(2,4).astype(config.floatX) x = numpy.random.rand(2, 4).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -168,17 +172,18 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -168,17 +172,18 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.constant(numpy.random.rand(2,3), dtype=config.floatX) x = T.constant(numpy.random.rand(2, 3), dtype=config.floatX)
y = theano.shared(numpy.random.rand(3,6).astype(config.floatX), 'y') y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX),
'y')
# should work # should work
z = T.dot(x,y) z = T.dot(x, y)
assert hasattr(z.tag, 'test_value') assert hasattr(z.tag, 'test_value')
f = theano.function([], z) f = theano.function([], z)
assert _allclose(f(), z.tag.test_value) assert _allclose(f(), z.tag.test_value)
# this test should fail # this test should fail
x = T.constant(numpy.random.rand(2,4), dtype=config.floatX) x = T.constant(numpy.random.rand(2, 4), dtype=config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -190,9 +195,9 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -190,9 +195,9 @@ class TestComputeTestValue(unittest.TestCase):
x = T.fmatrix('x') x = T.fmatrix('x')
# Incorrect dtype (float64) for test_value # Incorrect dtype (float64) for test_value
x.tag.test_value = numpy.random.rand(3,4) x.tag.test_value = numpy.random.rand(3, 4)
y = T.dmatrix('y') y = T.dmatrix('y')
y.tag.test_value = numpy.random.rand(4,5) y.tag.test_value = numpy.random.rand(4, 5)
self.assertRaises(TypeError, T.dot, x, y) self.assertRaises(TypeError, T.dot, x, y)
finally: finally:
...@@ -205,9 +210,9 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -205,9 +210,9 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
config.compute_test_value = "raise" config.compute_test_value = "raise"
x = T.matrix() x = T.matrix()
x.tag.test_value = numpy.zeros((2,3), dtype=config.floatX) x.tag.test_value = numpy.zeros((2, 3), dtype=config.floatX)
y = T.matrix() y = T.matrix()
y.tag.test_value = numpy.zeros((2,2), dtype=config.floatX) y.tag.test_value = numpy.zeros((2, 2), dtype=config.floatX)
self.assertRaises(ValueError, x.__mul__, y) self.assertRaises(ValueError, x.__mul__, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -250,7 +255,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -250,7 +255,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k") k = T.iscalar("k")
A = T.matrix("A") A = T.matrix("A")
k.tag.test_value = 3 k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5,3).astype(config.floatX) A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A): def fx(prior_result, A):
return T.dot(prior_result, A) return T.dot(prior_result, A)
...@@ -286,7 +291,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -286,7 +291,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k") k = T.iscalar("k")
A = T.matrix("A") A = T.matrix("A")
k.tag.test_value = 3 k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5,3).astype(config.floatX) A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A): def fx(prior_result, A):
return T.dot(prior_result, A) return T.dot(prior_result, A)
...@@ -338,7 +343,6 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -338,7 +343,6 @@ class TestComputeTestValue(unittest.TestCase):
output, = outputs output, = outputs
output[0] = input + 1 output[0] = input + 1
orig_compute_test_value = theano.config.compute_test_value orig_compute_test_value = theano.config.compute_test_value
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
...@@ -349,7 +353,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -349,7 +353,8 @@ class TestComputeTestValue(unittest.TestCase):
o = IncOnePython()(i) o = IncOnePython()(i)
# Check that the c_code function is not implemented # Check that the c_code function is not implemented
self.assertRaises((NotImplementedError, utils.MethodNotDefined), self.assertRaises(
(NotImplementedError, utils.MethodNotDefined),
o.owner.op.c_code, o.owner.op.c_code,
o.owner, 'o', ['x'], 'z', {'fail': ''}) o.owner, 'o', ['x'], 'z', {'fail': ''})
...@@ -391,7 +396,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -391,7 +396,8 @@ class TestComputeTestValue(unittest.TestCase):
orig_compute_test_value = theano.config.compute_test_value orig_compute_test_value = theano.config.compute_test_value
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
init_Mu1 = theano.shared(numpy.zeros((5,),dtype=config.floatX)).dimshuffle('x',0) init_Mu1 = theano.shared(
numpy.zeros((5,), dtype=config.floatX)).dimshuffle('x', 0)
f = theano.function([], outputs=[init_Mu1]) f = theano.function([], outputs=[init_Mu1])
finally: finally:
......
from itertools import izip from itertools import izip
import theano
import numpy import numpy
import scipy
import theano
from theano import gof, scalar, tensor from theano import gof, scalar, tensor
from theano.tensor import blas from theano.tensor import blas
from theano.sparse import (CSC, CSR, csm_properties, from theano.sparse import (CSC, CSR, csm_properties,
......
...@@ -631,21 +631,21 @@ class Subtensor(Op): ...@@ -631,21 +631,21 @@ class Subtensor(Op):
if view_ndim: if view_ndim:
rval = """ rval = """
// Argument of the view // Argument of the view
ssize_t xview_dims[%(view_ndim)s]; npy_intp xview_dims[%(view_ndim)s];
ssize_t xview_strides[%(view_ndim)s]; npy_intp xview_strides[%(view_ndim)s];
"""% locals() """% locals()
else: else:
rval = """ rval = """
// Argument of the view // Argument of the view
ssize_t* xview_dims = NULL; npy_intp* xview_dims = NULL;
ssize_t* xview_strides = NULL; npy_intp* xview_strides = NULL;
""" """
rval += """ rval += """
// One more argument of the view // One more argument of the view
ssize_t xview_offset = 0; npy_intp xview_offset = 0;
// The subtensor is created by iterating over the dimensions // The subtensor is created by iterating over the dimensions
// and updating stride, shape, and data pointers // and updating stride, shape, and data pointers
...@@ -776,7 +776,7 @@ class Subtensor(Op): ...@@ -776,7 +776,7 @@ class Subtensor(Op):
@staticmethod @staticmethod
def helper_c_code_cache_version(): def helper_c_code_cache_version():
return (7,) return (8,)
def c_code(self, node, name, inputs, outputs, sub): # DEBUG def c_code(self, node, name, inputs, outputs, sub): # DEBUG
if not isinstance(node.inputs[0].type, theano.tensor.TensorType): if not isinstance(node.inputs[0].type, theano.tensor.TensorType):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论