提交 556627a1 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Use a ufunc without identity for older versions of numpy

上级 3bb8f7f4
...@@ -21,6 +21,9 @@ from theano.misc.frozendict import frozendict ...@@ -21,6 +21,9 @@ from theano.misc.frozendict import frozendict
config = theano.config config = theano.config
_numpy_ver = [int(n) for n in numpy.__version__.split('.')[:2]]
# tensor depends on elemwise to provide definitions for several ops # tensor depends on elemwise to provide definitions for several ops
# but elemwise needs to make TensorType instances, so we have these as # but elemwise needs to make TensorType instances, so we have these as
# placeholders and the tensor module fills them # placeholders and the tensor module fills them
...@@ -1315,7 +1318,12 @@ class CAReduce(Op): ...@@ -1315,7 +1318,12 @@ class CAReduce(Op):
self.ufunc = numpy.maximum self.ufunc = numpy.maximum
elif isinstance(scalar_op, theano.scalar.basic.Minimum): elif isinstance(scalar_op, theano.scalar.basic.Minimum):
self.ufunc = numpy.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 self.ufunc = numpy.bitwise_and
elif isinstance(scalar_op, theano.scalar.basic.OR): elif isinstance(scalar_op, theano.scalar.basic.OR):
self.ufunc = numpy.bitwise_or self.ufunc = numpy.bitwise_or
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论