提交 67783f2e authored 作者: abergeron's avatar abergeron

Merge pull request #2824 from nouiz/numpy19

[BUG, TEST] Fix bug in numpy 1.9 and test in DebugMode
...@@ -5123,6 +5123,12 @@ def all(x, axis=None, keepdims=False): ...@@ -5123,6 +5123,12 @@ def all(x, axis=None, keepdims=False):
return out return out
# Some NumPy version like 1.9.2 return a view for numpy.diagonal
x = numpy.zeros((4, 4))
numpy_diagonal_return_view = numpy.may_share_memory(numpy.diagonal(x), x)
del x
class Diagonal(Op): class Diagonal(Op):
"""Return specified diagonals. """Return specified diagonals.
...@@ -5132,6 +5138,8 @@ class Diagonal(Op): ...@@ -5132,6 +5138,8 @@ class Diagonal(Op):
""" """
def __init__(self, offset=0, axis1=0, axis2=1): def __init__(self, offset=0, axis1=0, axis2=1):
if numpy_diagonal_return_view:
self.view_map = {0: [0]}
self.offset = offset self.offset = offset
self.axis1 = axis1 self.axis1 = axis1
self.axis2 = axis2 self.axis2 = axis2
......
...@@ -870,6 +870,13 @@ class Elemwise(OpenMPOp): ...@@ -870,6 +870,13 @@ class Elemwise(OpenMPOp):
elif (not isinstance(variable, numpy.ndarray) or elif (not isinstance(variable, numpy.ndarray) or
variable.dtype != nout.dtype): variable.dtype != nout.dtype):
variable = numpy.asarray(variable, nout.dtype) variable = numpy.asarray(variable, nout.dtype)
# The next line is needed for numpy 1.9. Otherwise
# there are tests that fail in DebugMode.
# Normally we would call theano.misc._asarray, but it
# is faster to inline the code. We know that the dtype
# are the same string, just different typenum.
if numpy.dtype(nout.dtype).num != variable.dtype.num:
variable = variable.view(dtype=nout.dtype)
storage[0] = variable storage[0] = variable
# numpy.real return a view! # numpy.real return a view!
elif not variable.flags.owndata: elif not variable.flags.owndata:
......
...@@ -459,14 +459,16 @@ class QRFull(Op): ...@@ -459,14 +459,16 @@ class QRFull(Op):
x = as_tensor_variable(x) x = as_tensor_variable(x)
assert x.ndim == 2, "The input of qr function should be a matrix." assert x.ndim == 2, "The input of qr function should be a matrix."
q = theano.tensor.matrix(dtype=x.dtype) q = theano.tensor.matrix(dtype=x.dtype)
r = theano.tensor.matrix(dtype=x.dtype) if self.mode != 'raw':
r = theano.tensor.matrix(dtype=x.dtype)
else:
r = theano.tensor.vector(dtype=x.dtype)
return Apply(self, [x], [q, r]) return Apply(self, [x], [q, r])
def perform(self, node, (x,), (q, r)): def perform(self, node, (x,), (q, r)):
assert x.ndim == 2, "The input of qr function should be a matrix." assert x.ndim == 2, "The input of qr function should be a matrix."
q[0], r[0] = self._numop(x, self.mode)
q[0], r[0] = self._numop(x,
self.mode)
class QRIncomplete(Op): class QRIncomplete(Op):
......
...@@ -1699,7 +1699,8 @@ ErfcInplaceTester = makeBroadcastTester( ...@@ -1699,7 +1699,8 @@ ErfcInplaceTester = makeBroadcastTester(
ErfinvTester = makeBroadcastTester( ErfinvTester = makeBroadcastTester(
op=tensor.erfinv, op=tensor.erfinv,
expected=expected_erfinv, expected=expected_erfinv,
good=_good_broadcast_unary_normal_float_no_complex, good={'normal': [rand_ranged(-.9, .9, (2, 3))],
'empty': [numpy.asarray([], dtype=config.floatX)]},
grad=_grad_broadcast_unary_abs1_no_complex, grad=_grad_broadcast_unary_abs1_no_complex,
eps=2e-10, eps=2e-10,
mode=mode_no_scipy, mode=mode_no_scipy,
...@@ -1708,7 +1709,8 @@ ErfinvTester = makeBroadcastTester( ...@@ -1708,7 +1709,8 @@ ErfinvTester = makeBroadcastTester(
ErfcinvTester = makeBroadcastTester( ErfcinvTester = makeBroadcastTester(
op=tensor.erfcinv, op=tensor.erfcinv,
expected=expected_erfcinv, expected=expected_erfcinv,
good=_good_broadcast_unary_normal_float_no_complex, good={'normal': [rand_ranged(0.001, 1.9, (2, 3))],
'empty': [numpy.asarray([], dtype=config.floatX)]},
grad=_grad_broadcast_unary_0_2_no_complex, grad=_grad_broadcast_unary_0_2_no_complex,
eps=2e-10, eps=2e-10,
mode=mode_no_scipy, mode=mode_no_scipy,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论