Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d723a72f
提交
d723a72f
authored
2月 22, 2013
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1210 from lamblin/check_inc_subtensor
Checks the dimensions and bcast in inc_subtensor
上级
42c16ccf
f6d418c2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
0 行删除
+37
-0
basic.py
theano/tensor/basic.py
+20
-0
test_inc_subtensor.py
theano/tensor/tests/test_inc_subtensor.py
+17
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
d723a72f
...
@@ -5040,6 +5040,26 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
...
@@ -5040,6 +5040,26 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
>>> new_r = inc_subtensor(r[10:], 5)
>>> new_r = inc_subtensor(r[10:], 5)
"""
"""
# First of all, y cannot have a higher dimension than x,
# nor have non-broadcastable dimensions where x is broadcastable.
x
=
as_tensor_variable
(
x
)
y
=
as_tensor_variable
(
y
)
if
y
.
ndim
>
x
.
ndim
:
raise
TypeError
((
"Trying to increment a
%
d-dimensional "
"subtensor with a
%
d-dimensional value."
)
%
(
x
.
ndim
,
y
.
ndim
))
for
dim
in
range
(
y
.
ndim
):
dim_offset
=
x
.
ndim
-
y
.
ndim
if
(
x
.
broadcastable
[
dim
+
dim_offset
]
and
not
y
.
broadcastable
[
dim
]):
raise
TypeError
((
"Trying to increment a subtensor with "
"broadcastable dimension
%
d, with a tensor not broadcastable "
"on corresponding dimension
%
d."
)
%
(
dim
+
dim_offset
,
dim
),
x
.
broadcastable
,
y
.
broadcastable
)
if
not
x
.
owner
:
raise
TypeError
(
'x must be result of a subtensor operation'
)
# retrieve idx_list from x.owner
# retrieve idx_list from x.owner
if
isinstance
(
x
.
owner
.
op
,
Subtensor
):
if
isinstance
(
x
.
owner
.
op
,
Subtensor
):
if
tolerate_inplace_aliasing
:
if
tolerate_inplace_aliasing
:
...
...
theano/tensor/tests/test_inc_subtensor.py
浏览文件 @
d723a72f
...
@@ -56,6 +56,23 @@ class Test_inc_subtensor(unittest.TestCase):
...
@@ -56,6 +56,23 @@ class Test_inc_subtensor(unittest.TestCase):
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
expected_result
))
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
expected_result
))
def
test_wrong_dims
(
self
):
a
=
tt
.
matrix
()
increment
=
tt
.
matrix
()
index
=
0
self
.
assertRaises
(
TypeError
,
tt
.
set_subtensor
,
a
[
index
],
increment
)
self
.
assertRaises
(
TypeError
,
tt
.
inc_subtensor
,
a
[
index
],
increment
)
def
test_wrong_broadcast
(
self
):
a
=
tt
.
col
()
increment
=
tt
.
vector
()
self
.
assertRaises
(
TypeError
,
tt
.
set_subtensor
,
a
[:],
increment
)
self
.
assertRaises
(
TypeError
,
tt
.
set_subtensor
,
a
[
0
],
increment
)
self
.
assertRaises
(
TypeError
,
tt
.
inc_subtensor
,
a
[:],
increment
)
self
.
assertRaises
(
TypeError
,
tt
.
inc_subtensor
,
a
[
0
],
increment
)
def
test_simple_3d
(
self
):
def
test_simple_3d
(
self
):
"""Increments or sets part of a tensor by a scalar using full slice and
"""Increments or sets part of a tensor by a scalar using full slice and
a partial slice depending on a scalar.
a partial slice depending on a scalar.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论