Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1e507512
提交
1e507512
authored
12月 08, 2014
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4 from nouiz/lamblin-fix_inc_set_subtensor1
Remove useless warning and make the graph more optimized in old supported cases.
上级
e53129ba
7f0cdfd2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
16 行删除
+14
-16
subtensor.py
theano/tensor/subtensor.py
+7
-2
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+7
-14
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
1e507512
...
...
@@ -1119,8 +1119,13 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
# We also explicitly duplicate y to its broadcasted shape
# before we partially flatten it to inner_x dimension. This is
# not strictly needed in all cases, but it is easier this way.
expanded_y
=
alloc
(
y
,
*
[
x
.
shape
[
i
]
for
i
in
range
(
x
.
ndim
)])
flattened_y
=
expanded_y
.
flatten
(
inner_x
.
ndim
)
if
y
.
ndim
>
0
:
# This if is needed to prevent some useless warning about
# old code bug.
expanded_y
=
alloc
(
y
,
*
[
x
.
shape
[
i
]
for
i
in
range
(
x
.
ndim
)])
flattened_y
=
expanded_y
.
flatten
(
inner_x
.
ndim
)
else
:
flattened_y
=
y
# Warn if this code path would have produced wrong results in the past
if
config
.
warn
.
inc_set_subtensor1
:
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
1e507512
...
...
@@ -1035,15 +1035,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
m
=
matrix
(
'm'
)
i
=
lmatrix
(
'i'
)
# That test actually gave correct results, the warning is
# a bit too broad
orig_warn
=
config
.
warn
.
inc_set_subtensor1
try
:
config
.
warn
.
inc_set_subtensor1
=
False
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
finally
:
config
.
warn
.
inc_set_subtensor1
=
orig_warn
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
])
...
...
@@ -1060,10 +1053,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
assert
numpy
.
allclose
(
m1_val
,
m1_ref
),
(
m1_val
,
m1_ref
)
assert
numpy
.
allclose
(
m2_val
,
m2_ref
),
(
m2_val
,
m2_ref
)
def
test_adv1_inc_sub_notlastdim_1
dval
(
self
):
def
test_adv1_inc_sub_notlastdim_1
_2dval_broadcast
(
self
):
# Test that taking 1-dimensional advanced indexing
# over a dimension that's not the first (outer-most),
# and incrementing/setting
a 1D value works.
# and incrementing/setting
with broadcast
m
=
matrix
(
'm'
)
# Test for both vector and matrix as index
...
...
@@ -1097,16 +1090,16 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
finally
:
config
.
warn
.
inc_set_subtensor1
=
orig_warn
def
test_adv1_inc_sub_notlastdim_
2dval
(
self
):
def
test_adv1_inc_sub_notlastdim_
1_2dval_no_broadcast
(
self
):
# Test that taking 1-dimensional advanced indexing
# over a dimension that's not the first (outer-most),
# and incrementing/setting
a 2D value works.
# and incrementing/setting
without broadcast
m
=
matrix
(
'm'
)
# Test for both vector and matrix as index
sym_i
=
(
lvector
(
'i'
),
lmatrix
(
'i'
))
shape_i
=
((
4
,),
(
4
,
2
))
shape_val
=
((
3
,
1
),
(
3
,
1
,
1
))
shape_val
=
((
3
,
4
),
(
3
,
4
,
2
))
# Disable the warning emitted for that case
orig_warn
=
config
.
warn
.
inc_set_subtensor1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论