提交 e829ba4f authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: GitHub

Merge pull request #5527 from lamblin/ccw_numpy_travis

validate numpy1.12 compatibility changes
......@@ -48,7 +48,8 @@ env:
- PART="-e test_flake8.py theano/compat theano/compile theano/d3viz theano/gof theano/misc theano/sandbox theano/scalar theano/scan_module theano/sparse theano/tests theano/typed_list"
- PART="theano/tensor -e test_basic.py --exclude-dir=theano/tensor/nnet"
- PART="theano/tensor/tests/test_basic.py"
- PART="theano/tensor/nnet"
- PART="theano/tensor/nnet -e test_abstract_conv.py"
- PART="theano/tensor/nnet/tests/test_abstract_conv.py"
matrix:
fast_finish: true
......
......@@ -34,7 +34,7 @@ oscillates due to the box function being shifted to the middle of the array.
N = 1024
box = np.zeros((1, N), dtype='float64')
box[:, N/2-10: N/2+10] = 1
box[:, N//2-10: N//2+10] = 1
out = f_rfft(box)
c_out = np.asarray(out[0, :, 0] + 1j*out[0, :, 1])
......
......@@ -1412,11 +1412,8 @@ class CLinker(link.Linker):
version = []
for node_pos, node in enumerate(order):
try:
# Pure Ops do not have a c_code_cache_version_apply ...
if hasattr(node.op, 'c_code_cache_version_apply'):
version.append(node.op.c_code_cache_version_apply(node))
except AttributeError:
pass
for i in node.inputs:
version.append(i.type.c_code_cache_version())
for o in node.outputs:
......
......@@ -2885,8 +2885,8 @@ class GpuCAReduceCPY(GpuKernelBase, HideC, CAReduceDtype):
return code
def c_code_cache_version(self):
return (2, self.GpuKernelBase_version)
def c_code_cache_version_apply(self, node):
return (2, self.kernel_version(node))
def generate_kernel(self, node, odtype, redux):
if isinstance(self.scalar_op, scalar.basic.Add):
......
......@@ -1543,7 +1543,7 @@ xor = XOR()
class AND(BinaryBitOp):
identity = 1
identity = -1
commutative = True
associative = True
nfunc_spec = ('bitwise_and', 2, 1)
......@@ -1555,6 +1555,10 @@ class AND(BinaryBitOp):
(x, y) = inputs
(z,) = outputs
return "%(z)s = (%(x)s & %(y)s);" % locals()
def c_code_cache_version(self):
super_version = super(AND, self).c_code_cache_version()
return super_version + (3,)
and_ = AND()
......
......@@ -1232,7 +1232,10 @@ class MaxAndArgmax(Op):
transposed_x = numpy.transpose(x, numpy.concatenate((keep_axes, axes)))
kept_shape = transposed_x.shape[:len(keep_axes)]
reduced_shape = transposed_x.shape[len(keep_axes):]
new_shape = kept_shape + (numpy.prod(reduced_shape),)
# Numpy.prod returns 1.0 when arg is empty, so we cast it to int64
# Otherwise reshape would complain citing float arg
new_shape = kept_shape + (numpy.prod(reduced_shape, dtype='int64'),)
reshaped_x = transposed_x.reshape(new_shape)
max_idx[0] = theano._asarray(numpy.argmax(reshaped_x, axis=-1),
......
......@@ -21,6 +21,9 @@ from theano.misc.frozendict import frozendict
config = theano.config
_numpy_ver = [int(n) for n in numpy.__version__.split('.')[:2]]
# tensor depends on elemwise to provide definitions for several ops
# but elemwise needs to make TensorType instances, so we have these as
# placeholders and the tensor module fills them
......@@ -1315,7 +1318,12 @@ class CAReduce(Op):
self.ufunc = numpy.maximum
elif isinstance(scalar_op, theano.scalar.basic.Minimum):
self.ufunc = numpy.minimum
elif isinstance(scalar_op, theano.scalar.basic.AND):
elif (isinstance(scalar_op, theano.scalar.basic.AND) and
_numpy_ver >= [1, 12]):
# numpy.bitwise_and.identity was incorrect for versions before
# 1.12 (it was 1 instead of -1), so we skip it in that case.
# We will fall back to the "else:" case, which defines a
# ufunc without identity.
self.ufunc = numpy.bitwise_and
elif isinstance(scalar_op, theano.scalar.basic.OR):
self.ufunc = numpy.bitwise_or
......@@ -1615,7 +1623,8 @@ for(int i=0;i<PyArray_NDIM(%(iname)s);i++){
return ['<vector>', '<algorithm>']
def c_code_cache_version_apply(self, node):
version = (6,) # the version corresponding to the c code in this Op
# the version corresponding to the c code in this Op
version = [6]
# now we insert versions for the ops on which we depend...
scalar_node = Apply(
......
......@@ -330,6 +330,22 @@ class test_Broadcast(unittest.TestCase):
assert (f(xv) == zv).all()
def reduce_bitwise_and(x, axis=-1, dtype='int8'):
identity = numpy.array((-1,), dtype=dtype)[0]
shape_without_axis = tuple([s for i, s in enumerate(x.shape) if i != axis])
if 0 in shape_without_axis:
return numpy.empty(shape=shape_without_axis, dtype=x.dtype)
def custom_reduce(a):
out = identity
for i in range(a.size):
out = numpy.bitwise_and(a[i], out)
return out
return numpy.apply_along_axis(custom_reduce, axis, x)
class test_CAReduce(unittest_tools.InferShapeTester):
op = CAReduce
cases = [((5, 6), None),
......@@ -430,7 +446,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
zv = numpy.bitwise_or.reduce(zv, axis)
elif scalar_op == scalar.and_:
for axis in reversed(sorted(tosum)):
zv = numpy.bitwise_and.reduce(zv, axis)
zv = reduce_bitwise_and(zv, axis, dtype=dtype)
elif scalar_op == scalar.xor:
# There is no identity value for the xor function
# So we can't support shape of dimensions 0.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论