提交 80a3a4dc authored 作者: Nicolas Pinto's avatar Nicolas Pinto

MISC: pep8

上级 ceb31338
"""Define the tensor toplevel""" """Define the tensor toplevel"""
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import warnings import warnings
from basic import * from basic import *
...@@ -31,6 +30,7 @@ import sharedvar # adds shared-variable constructors ...@@ -31,6 +30,7 @@ import sharedvar # adds shared-variable constructors
# `theano.shared` and `tensor._shared`. # `theano.shared` and `tensor._shared`.
from sharedvar import tensor_constructor as _shared from sharedvar import tensor_constructor as _shared
def shared(*args, **kw): def shared(*args, **kw):
""" """
Backward-compatibility wrapper around `tensor._shared`. Backward-compatibility wrapper around `tensor._shared`.
......
...@@ -433,7 +433,7 @@ def makeBroadcastTester(op, expected, checks=None, name=None, **kwargs): ...@@ -433,7 +433,7 @@ def makeBroadcastTester(op, expected, checks=None, name=None, **kwargs):
# cases we need to add it manually. # cases we need to add it manually.
if not name.endswith('Tester'): if not name.endswith('Tester'):
name += "Tester" name += "Tester"
if kwargs.has_key('inplace'): if 'inplace' in kwargs:
if kwargs['inplace']: if kwargs['inplace']:
_expected = expected _expected = expected
if not isinstance(_expected, dict): if not isinstance(_expected, dict):
...@@ -451,37 +451,42 @@ def makeBroadcastTester(op, expected, checks=None, name=None, **kwargs): ...@@ -451,37 +451,42 @@ def makeBroadcastTester(op, expected, checks=None, name=None, **kwargs):
return makeTester(name, op, expected, checks, **kwargs) return makeTester(name, op, expected, checks, **kwargs)
_good_broadcast_binary_normal = dict(same_shapes=(rand(2, 3), rand(2, 3)), _good_broadcast_binary_normal = dict(
not_same_dimensions=(rand(2, 2), rand(2)), same_shapes=(rand(2, 3), rand(2, 3)),
scalar=(rand(2, 3), rand(1, 1)), not_same_dimensions=(rand(2, 2), rand(2)),
row=(rand(2, 3), rand(1, 3)), scalar=(rand(2, 3), rand(1, 1)),
column=(rand(2, 3), rand(2, 1)), row=(rand(2, 3), rand(1, 3)),
integers=(randint(2, 3), randint(2, 3)), column=(rand(2, 3), rand(2, 1)),
dtype_mixup_1=(rand(2, 3), randint(2, 3)), integers=(randint(2, 3), randint(2, 3)),
dtype_mixup_2=(randint(2, 3), rand(2, 3)), dtype_mixup_1=(rand(2, 3), randint(2, 3)),
complex1=(randcomplex(2, 3), randcomplex(2, 3)), dtype_mixup_2=(randint(2, 3), rand(2, 3)),
complex2=(randcomplex(2, 3), rand(2, 3)), complex1=(randcomplex(2, 3), randcomplex(2, 3)),
# Disabled as we test the case where we reuse the same output as the first inputs. complex2=(randcomplex(2, 3), rand(2, 3)),
# complex3=(rand(2,3),randcomplex(2,3)), # Disabled as we test the case where we reuse the same output as the
empty=(numpy.asarray([]), numpy.asarray([1])), # first inputs.
) # complex3=(rand(2,3),randcomplex(2,3)),
empty=(numpy.asarray([]), numpy.asarray([1])),
_bad_build_broadcast_binary_normal = dict() # not_same_dimensions = (rand(2), rand(2, 2))) )
_bad_runtime_broadcast_binary_normal = dict(bad_shapes=(rand(2, 3), rand(3, 2)), _bad_build_broadcast_binary_normal = dict()
bad_row=(rand(2, 3), rand(1, 2)))
_bad_runtime_broadcast_binary_normal = dict(
_grad_broadcast_binary_normal = dict(same_shapes=(rand(2, 3), rand(2, 3)), bad_shapes=(rand(2, 3), rand(3, 2)),
scalar=(rand(2, 3), rand(1, 1)), bad_row=(rand(2, 3), rand(1, 2)))
row=(rand(2, 3), rand(1, 3)),
column=(rand(2, 3), rand(2, 1)), _grad_broadcast_binary_normal = dict(
#This don't work as verify grad don't support that same_shapes=(rand(2, 3), rand(2, 3)),
#empty=(numpy.asarray([]), numpy.asarray([1])) scalar=(rand(2, 3), rand(1, 1)),
#complex1=(randcomplex(2,3),randcomplex(2,3)), row=(rand(2, 3), rand(1, 3)),
#complex2=(randcomplex(2,3),rand(2,3)), column=(rand(2, 3), rand(2, 1)),
# Disabled as we test the case where we reuse the same output as the first inputs. #This don't work as verify grad don't support that
#complex3=(rand(2,3),randcomplex(2,3)), #empty=(numpy.asarray([]), numpy.asarray([1]))
) #complex1=(randcomplex(2,3),randcomplex(2,3)),
#complex2=(randcomplex(2,3),rand(2,3)),
# Disabled as we test the case where we reuse the same output as the
# first inputs.
#complex3=(rand(2,3),randcomplex(2,3)),
)
def check_floatX(inputs, rval): def check_floatX(inputs, rval):
...@@ -507,28 +512,38 @@ def check_floatX(inputs, rval): ...@@ -507,28 +512,38 @@ def check_floatX(inputs, rval):
return rval return rval
AddTester = makeBroadcastTester(op = add, AddTester = makeBroadcastTester(
expected = lambda *inputs: check_floatX(inputs, reduce(lambda x, y: x + y, inputs)), op=add,
good = dict(three_inputs_same_shapes = (rand(2, 3), rand(2, 3), rand(2, 3)), expected = lambda *inputs: check_floatX(
four_inputs_broadcast = (rand(2, 3), rand(1, 3), rand(2, 1), rand(1, 1)), inputs, reduce(lambda x, y: x + y, inputs)),
**_good_broadcast_binary_normal), good = dict(
bad_build = _bad_build_broadcast_binary_normal, three_inputs_same_shapes=(rand(2, 3),
bad_runtime = _bad_runtime_broadcast_binary_normal) rand(2, 3),
rand(2, 3)),
four_inputs_broadcast=(rand(2, 3),
AddInplaceTester = makeBroadcastTester(op = inplace.add_inplace, rand(1, 3),
expected = lambda x, y: x + y, rand(2, 1),
good = _good_broadcast_binary_normal, rand(1, 1)),
bad_build = _bad_build_broadcast_binary_normal, **_good_broadcast_binary_normal),
bad_runtime = _bad_runtime_broadcast_binary_normal, bad_build = _bad_build_broadcast_binary_normal,
inplace = True) bad_runtime = _bad_runtime_broadcast_binary_normal)
SubTester = makeBroadcastTester(op = sub,
expected = lambda x, y: check_floatX((x, y), x - y), AddInplaceTester = makeBroadcastTester(
good = _good_broadcast_binary_normal, op = inplace.add_inplace,
bad_build = _bad_build_broadcast_binary_normal, expected = lambda x, y: x + y,
bad_runtime = _bad_runtime_broadcast_binary_normal, good = _good_broadcast_binary_normal,
grad = _grad_broadcast_binary_normal) bad_build = _bad_build_broadcast_binary_normal,
bad_runtime = _bad_runtime_broadcast_binary_normal,
inplace = True)
SubTester = makeBroadcastTester(
op = sub,
expected = lambda x, y: check_floatX((x, y), x - y),
good = _good_broadcast_binary_normal,
bad_build = _bad_build_broadcast_binary_normal,
bad_runtime = _bad_runtime_broadcast_binary_normal,
grad = _grad_broadcast_binary_normal)
SubInplaceTester = makeBroadcastTester(op = inplace.sub_inplace, SubInplaceTester = makeBroadcastTester(op = inplace.sub_inplace,
expected = lambda x, y: x - y, expected = lambda x, y: x - y,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论