Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
86cb447e
提交
86cb447e
authored
11月 17, 2016
作者:
Frédéric Bastien
提交者:
GitHub
11月 17, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5212 from lamblin/fix_subtensor_setsubtensor
Fix issue in local_subtensor_incsubtensor
上级
7fd891e9
f0d2b735
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
10 行删除
+24
-10
opt.py
theano/tensor/opt.py
+15
-7
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+9
-3
没有找到文件。
theano/tensor/opt.py
浏览文件 @
86cb447e
...
@@ -1910,14 +1910,22 @@ def local_subtensor_inc_subtensor(node):
...
@@ -1910,14 +1910,22 @@ def local_subtensor_inc_subtensor(node):
if
not
x
.
owner
.
op
.
set_instead_of_inc
:
if
not
x
.
owner
.
op
.
set_instead_of_inc
:
return
return
if
x
.
owner
.
inputs
[
2
:]
==
node
.
inputs
[
1
:]
and
tuple
(
x
.
owner
.
op
.
idx_list
)
==
tuple
(
node
.
op
.
idx_list
):
if
(
x
.
owner
.
inputs
[
2
:]
==
node
.
inputs
[
1
:]
and
# if x[idx] and y have the same ndim (and shape), directly return y
tuple
(
x
.
owner
.
op
.
idx_list
)
==
tuple
(
node
.
op
.
idx_list
)):
if
x
.
owner
.
inputs
[
0
]
.
ndim
-
(
len
(
node
.
op
.
idx_list
)
-
sum
([
isinstance
(
idx
,
slice
)
for
idx
in
node
.
op
.
idx_list
]))
==
x
.
owner
.
inputs
[
1
]
.
ndim
:
out
=
node
.
outputs
[
0
]
return
[
x
.
owner
.
inputs
[
1
]]
y
=
x
.
owner
.
inputs
[
1
]
# else y is broadcastable, return alloc of broadcastable y
# If the dtypes differ, cast y into x.dtype
else
:
if
x
.
dtype
!=
y
.
dtype
:
y
=
y
.
astype
(
x
.
dtype
)
if
out
.
type
==
y
.
type
:
# if x[idx] and y have the same type, directly return y
return
[
y
]
else
:
# The difference is related to broadcasting pattern
assert
out
.
broadcastable
!=
y
.
broadcastable
# We have to alloc y to the shape of x[idx]
x_subtensor
=
node
.
op
(
x
.
owner
.
inputs
[
0
],
*
x
.
owner
.
inputs
[
2
:])
x_subtensor
=
node
.
op
(
x
.
owner
.
inputs
[
0
],
*
x
.
owner
.
inputs
[
2
:])
return
[
T
.
alloc
(
x
.
owner
.
inputs
[
1
]
,
*
x_subtensor
.
shape
)]
return
[
T
.
alloc
(
y
,
*
x_subtensor
.
shape
)]
else
:
else
:
return
return
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
86cb447e
...
@@ -989,6 +989,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -989,6 +989,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
all_inputs_num
=
[]
all_inputs_num
=
[]
all_outputs_var
=
[]
all_outputs_var
=
[]
all_outputs_num
=
[]
all_outputs_num
=
[]
all_params
=
[]
for
set_instead_of_inc
in
(
False
,
True
):
for
set_instead_of_inc
in
(
False
,
True
):
for
inplace
in
(
False
,
True
):
for
inplace
in
(
False
,
True
):
for
data_shape
in
((
10
,),
(
4
,
5
),
(
1
,
2
,
3
),
(
4
,
5
,
6
,
7
)):
for
data_shape
in
((
10
,),
(
4
,
5
),
(
1
,
2
,
3
),
(
4
,
5
,
6
,
7
)):
...
@@ -1021,7 +1022,11 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1021,7 +1022,11 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
data_shape
[
0
]
>
1
):
data_shape
[
0
]
>
1
):
n_to_inc
=
2
n_to_inc
=
2
# Corresponding numeric variable.
# Corresponding numeric variable.
idx_num
=
rng
.
randint
(
0
,
data_shape
[
0
],
n_to_inc
)
# If set_instead_of_inc, we want to avoid repeating
# indices, as the order is not guaranteed.
idx_num
=
rng
.
choice
(
numpy
.
arange
(
data_shape
[
0
]),
n_to_inc
,
replace
=
(
not
set_instead_of_inc
))
idx_num
=
idx_num
.
astype
(
'int64'
)
idx_num
=
idx_num
.
astype
(
'int64'
)
# Symbolic variable with increment value.
# Symbolic variable with increment value.
inc_var
=
self
.
type
(
inc_var
=
self
.
type
(
...
@@ -1079,6 +1084,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1079,6 +1084,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
all_inputs_num
+=
[
data_num
,
idx_num
,
inc_num
]
all_inputs_num
+=
[
data_num
,
idx_num
,
inc_num
]
all_outputs_var
.
append
(
output
)
all_outputs_var
.
append
(
output
)
all_outputs_num
.
append
(
data_copy
)
all_outputs_num
.
append
(
data_copy
)
all_params
.
append
((
set_instead_of_inc
,
inplace
,
data_shape
,
inc_shape
))
if
False
:
# Enable for debugging purpose.
if
False
:
# Enable for debugging purpose.
f
=
self
.
function
([
data_var
,
idx_var
,
inc_var
],
f
=
self
.
function
([
data_var
,
idx_var
,
inc_var
],
output
,
accept_inplace
=
inplace
,
output
,
accept_inplace
=
inplace
,
...
@@ -1105,10 +1111,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1105,10 +1111,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
f_outs
=
f
(
*
all_inputs_num
)
f_outs
=
f
(
*
all_inputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
for
f_out
,
output_num
in
izip
(
f_outs
,
all_outputs_num
):
for
params
,
f_out
,
output_num
in
izip
(
all_params
,
f_outs
,
all_outputs_num
):
# NB: if this assert fails, it will probably be easier to debug if
# NB: if this assert fails, it will probably be easier to debug if
# you enable the debug code above.
# you enable the debug code above.
assert
numpy
.
allclose
(
f_out
,
output_num
)
assert
numpy
.
allclose
(
f_out
,
output_num
)
,
(
params
,
f_out
,
output_num
)
def
test_adv_constant_arg
(
self
):
def
test_adv_constant_arg
(
self
):
# Test case provided (and bug detected, gh-607) by John Salvatier
# Test case provided (and bug detected, gh-607) by John Salvatier
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论