Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0ef4d76e
提交
0ef4d76e
authored
7月 06, 2012
作者:
Eric Larsen
提交者:
Frederic
8月 15, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updates to TensorDotGrad and TensorDot
上级
e9c3bf4e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
142 行增加
和
5 行删除
+142
-5
basic.py
theano/tensor/basic.py
+2
-5
test_basic.py
theano/tensor/tests/test_basic.py
+140
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
0ef4d76e
...
@@ -6428,7 +6428,6 @@ class TensorDotGrad(Op):
...
@@ -6428,7 +6428,6 @@ class TensorDotGrad(Op):
for
i
in
range
(
node
.
inputs
[
1
]
.
ndim
)]
for
i
in
range
(
node
.
inputs
[
1
]
.
ndim
)]
return
[
inp0_shp
,
inp1_shp
]
return
[
inp0_shp
,
inp1_shp
]
tensordot_grad
=
TensorDotGrad
tensordot_grad
=
TensorDotGrad
...
@@ -6508,12 +6507,10 @@ class TensorDot(Op):
...
@@ -6508,12 +6507,10 @@ class TensorDot(Op):
shape_x
,
shape_y
=
in_shapes
shape_x
,
shape_y
=
in_shapes
out_shape
=
[]
out_shape
=
[]
if
isinstance
(
self
.
axes
,
(
list
,
tuple
)):
if
isinstance
(
self
.
axes
,
(
list
,
tuple
)):
iter
=
(
i
for
i
in
range
(
len
(
shape_x
))
iter
=
(
i
for
i
in
range
(
len
(
shape_x
))
if
i
not
in
self
.
axes
[
0
])
for
j
in
self
.
axes
[
0
]
if
i
!=
j
)
for
i
in
iter
:
for
i
in
iter
:
out_shape
.
append
(
shape_x
[
i
])
out_shape
.
append
(
shape_x
[
i
])
iter
=
(
i
for
i
in
range
(
len
(
shape_y
))
iter
=
(
i
for
i
in
range
(
len
(
shape_y
))
if
i
not
in
self
.
axes
[
1
])
for
j
in
self
.
axes
[
1
]
if
i
!=
j
)
for
i
in
iter
:
for
i
in
iter
:
out_shape
.
append
(
shape_y
[
i
])
out_shape
.
append
(
shape_y
[
i
])
else
:
else
:
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
0ef4d76e
...
@@ -6034,22 +6034,162 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -6034,22 +6034,162 @@ class TestInferShape(utt.InferShapeTester):
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
5
,
4
)
gzdscal
=
dscalar
()
gzdscal_val
=
rand
()
axes
=
2
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdscal
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdscal
),
[
admat_val
,
bdmat_val
,
gzdscal_val
],
tensordot_grad
)
admat_val
=
rand
(
4
,
5
)
bdmat_val
=
rand
(
5
,
3
)
gzdmat_val
=
rand
(
4
,
3
)
axes
=
((
1
,
),
(
0
,
))
axes
=
((
1
,
),
(
0
,
))
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
axes
=
((
1
,
0
))
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
admat_val
=
rand
(
4
,
5
)
bdmat_val
=
rand
(
3
,
4
)
gzdmat_val
=
rand
(
5
,
3
)
axes
=
((
0
,
),
(
1
,
))
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdmat
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdmat
),
[
admat_val
,
bdmat_val
,
gzdmat_val
],
tensordot_grad
)
gzdscal
=
dscalar
()
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
5
,
4
)
gzdscal_val
=
rand
()
axes
=
((
0
,
1
),
(
0
,
1
))
self
.
_compile_and_check
([
admat
,
bdmat
,
gzdscal
],
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdscal
),
[
admat_val
,
bdmat_val
,
gzdscal_val
],
tensordot_grad
)
# Note: The two following tests currently fail and should unlikely be
# for the shape of a grad is very simple and similar to that of the inputs.
# Additional tests involving 3-tensors and 4-tensors will be included once
# this is resolved. Suggestion: first solve issues with 'tensordot' next.
"""
gzdscal = dscalar()
admat_val = rand(5, 4)
bdmat_val = rand(4, 5)
gzdscal_val = rand()
axes = ((0, 1), (1, 0))
self._compile_and_check([admat, bdmat, gzdscal],
tensordot_grad(axes)(admat, bdmat, gzdscal),
[admat_val, bdmat_val, gzdscal_val], tensordot_grad)
gzdscal = dscalar()
admat_val = rand(5, 4)
bdmat_val = rand(5, 4)
gzdscal_val = rand()
axes = ((1, 0 ), (1, 0))
self._compile_and_check([admat, bdmat, gzdscal],
tensordot_grad(axes)(admat, bdmat, gzdscal),
[admat_val, bdmat_val, gzdscal_val], tensordot_grad)
"""
# tensordot
# tensordot
admat
=
dmatrix
()
bdmat
=
dmatrix
()
admat_val
=
rand
(
4
,
5
)
bdmat_val
=
rand
(
5
,
3
)
axes
=
1
axes
=
1
self
.
_compile_and_check
([
admat
,
bdmat
],
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
5
,
4
)
axes
=
2
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
4
,
5
)
bdmat_val
=
rand
(
5
,
3
)
axes
=
((
1
,
),
(
0
,
))
axes
=
((
1
,
),
(
0
,
))
self
.
_compile_and_check
([
admat
,
bdmat
],
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
[
admat_val
,
bdmat_val
],
TensorDot
)
axes
=
((
1
,
0
))
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
4
,
5
)
bdmat_val
=
rand
(
3
,
4
)
axes
=
((
0
,
),
(
1
,
))
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
4
,
5
)
axes
=
((
1
,),
(
0
,))
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
5
,
4
)
axes
=
((
0
,
1
),
(
0
,
1
))
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
admat_val
=
rand
(
5
,
4
)
bdmat_val
=
rand
(
4
,
5
)
axes
=
((
1
,
0
),
(
0
,
1
))
self
.
_compile_and_check
([
admat
,
bdmat
],
[
TensorDot
(
axes
)(
admat
,
bdmat
)],
[
admat_val
,
bdmat_val
],
TensorDot
)
adtens3
=
dtensor3
()
admat_val
=
rand
(
5
,
4
)
adtens3_val
=
rand
(
5
,
4
,
3
)
axes
=
2
self
.
_compile_and_check
([
admat
,
adtens3
],
[
TensorDot
(
axes
)(
admat
,
adtens3
)],
[
admat_val
,
adtens3_val
],
TensorDot
)
adtens3_val
=
rand
(
4
,
5
,
3
)
axes
=
((
1
,
0
),
(
0
,
1
))
self
.
_compile_and_check
([
admat
,
adtens3
],
[
TensorDot
(
axes
)(
admat
,
adtens3
)],
[
admat_val
,
adtens3_val
],
TensorDot
)
adtens3_val
=
rand
(
4
,
3
,
5
)
axes
=
((
1
,
0
),
(
0
,
2
))
self
.
_compile_and_check
([
admat
,
adtens3
],
[
TensorDot
(
axes
)(
admat
,
adtens3
)],
[
admat_val
,
adtens3_val
],
TensorDot
)
adtens4
=
dtensor4
()
admat_val
=
rand
(
5
,
4
)
adtens4_val
=
rand
(
5
,
4
,
3
,
2
)
axes
=
2
self
.
_compile_and_check
([
admat
,
adtens4
],
[
TensorDot
(
axes
)(
admat
,
adtens4
)],
[
admat_val
,
adtens4_val
],
TensorDot
)
adtens4_val
=
rand
(
4
,
3
,
2
,
5
)
axes
=
((
1
,
0
),
(
0
,
3
))
self
.
_compile_and_check
([
admat
,
adtens4
],
[
TensorDot
(
axes
)(
admat
,
adtens4
)],
[
admat_val
,
adtens4_val
],
TensorDot
)
# Flatten
# Flatten
adtens
=
tensor3
()
adtens
=
tensor3
()
adtens_val
=
rand
(
4
,
5
,
3
)
adtens_val
=
rand
(
4
,
5
,
3
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论