Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5cfc5b1d
提交
5cfc5b1d
authored
3月 12, 2015
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the broadcastable pattern of tensordot's output
上级
05378c82
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
1 行删除
+28
-1
basic.py
theano/tensor/basic.py
+5
-1
test_basic.py
theano/tensor/tests/test_basic.py
+23
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
5cfc5b1d
...
...
@@ -4997,6 +4997,7 @@ def tensordot(a, b, axes=2):
'of b (b.ndim=
%
i, axes=
%
i)'
%
(
b
.
ndim
,
axes
))
outshape
=
concatenate
([
a
.
shape
[:
a
.
ndim
-
axes
],
b
.
shape
[
axes
:]])
outbcast
=
a
.
broadcastable
[:
a
.
ndim
-
axes
]
+
b
.
broadcastable
[
axes
:]
outndim
=
a
.
ndim
+
b
.
ndim
-
(
2
*
axes
)
a_shape_0
=
b_shape_0
=
a_shape_1
=
b_shape_1
=
1
...
...
@@ -5012,7 +5013,10 @@ def tensordot(a, b, axes=2):
a_reshaped
=
a
.
reshape
((
a_shape_0
,
a_shape_1
),
ndim
=
2
)
b_reshaped
=
b
.
reshape
((
b_shape_0
,
b_shape_1
),
ndim
=
2
)
return
_dot
(
a_reshaped
,
b_reshaped
)
.
reshape
(
outshape
,
outndim
)
out
=
_dot
(
a_reshaped
,
b_reshaped
)
.
reshape
(
outshape
,
outndim
)
# Make sure the broadcastable pattern of the result is correct,
# since some shape information can be lost in the reshapes.
return
patternbroadcast
(
out
,
outbcast
)
# if 'axes' is a list, transpose a and b such that the summed axes of a
# are last and the summed axes of b are first.
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
5cfc5b1d
...
...
@@ -5529,6 +5529,29 @@ class test_tensordot(unittest.TestCase):
f3
(
aval
,
bval
)))
utt
.
verify_grad
(
self
.
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_broadcastable1
(
self
):
x
=
TensorType
(
dtype
=
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
'x'
)
y
=
tensor3
(
'y'
)
z
=
tensordot
(
x
,
y
)
assert
z
.
broadcastable
==
(
True
,
False
)
f
=
inplace_func
([
x
,
y
],
z
)
xv
=
rand
(
1
,
3
,
4
)
yv
=
rand
(
3
,
4
,
5
)
zv
=
f
(
xv
,
yv
)
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
xv
,
yv
),
zv
))
def
test_broadcastable2
(
self
):
x
=
TensorType
(
dtype
=
floatX
,
broadcastable
=
(
True
,
False
,
False
))(
'x'
)
y
=
tensor3
(
'y'
)
axes
=
[[
2
,
1
],
[
0
,
1
]]
z
=
tensordot
(
x
,
y
,
axes
=
axes
)
assert
z
.
broadcastable
==
(
True
,
False
)
f
=
inplace_func
([
x
,
y
],
z
)
xv
=
rand
(
1
,
3
,
4
)
yv
=
rand
(
4
,
3
,
5
)
zv
=
f
(
xv
,
yv
)
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
xv
,
yv
,
axes
=
axes
),
zv
))
def
test_smallest_stack
():
sx
,
sy
=
dscalar
(),
dscalar
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论