提交 f7ec76b7 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

change if to check using isinstance

Before we used to use the variables `using_list`, `using_tuple`, but I feel is much more clean if we do not rely on those variables that are meant only for re-formating the output
上级 572c7878
...@@ -211,8 +211,7 @@ def Lop(f, wrt, eval_points, consider_constant=None, warn_type=False, ...@@ -211,8 +211,7 @@ def Lop(f, wrt, eval_points, consider_constant=None, warn_type=False,
# such subtle cases can be fixed by a more careful implementation of the # such subtle cases can be fixed by a more careful implementation of the
# gradient, but for now Theano needs to throw an exception, and make the # gradient, but for now Theano needs to throw an exception, and make the
# user aware that it does not know how to compute that gradient # user aware that it does not know how to compute that gradient
if not isinstance(wrt, (list, tuple)):
if not (using_list or using_tuple):
wrt = [wrt] wrt = [wrt]
ret = [] ret = []
for p in wrt: for p in wrt:
...@@ -319,7 +318,8 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False, ...@@ -319,7 +318,8 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
# user aware that it does not know how to compute that gradient # user aware that it does not know how to compute that gradient
using_list = isinstance(wrt, list) using_list = isinstance(wrt, list)
using_tuple = isinstance(wrt, tuple) using_tuple = isinstance(wrt, tuple)
if not (using_list or using_tuple):
if not isinstance(wrt, (list, tuple)):
wrt = [wrt] wrt = [wrt]
ret = [] ret = []
for p in wrt: for p in wrt:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论