Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b731111f
提交
b731111f
authored
8月 15, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make TensorDotGrad raise an NotImplementedError for the case it return wrong shape.
A reshape fix this problem, but return the wrong results.
上级
0a532cbd
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
18 行删除
+39
-18
basic.py
theano/tensor/basic.py
+9
-0
test_basic.py
theano/tensor/tests/test_basic.py
+30
-18
没有找到文件。
theano/tensor/basic.py
浏览文件 @
b731111f
...
@@ -6453,6 +6453,13 @@ pprint.assign(dot, printing.OperatorPrinter(printing.special['middle_dot'],
...
@@ -6453,6 +6453,13 @@ pprint.assign(dot, printing.OperatorPrinter(printing.special['middle_dot'],
class
TensorDotGrad
(
Op
):
class
TensorDotGrad
(
Op
):
def
__init__
(
self
,
axes
):
def
__init__
(
self
,
axes
):
self
.
axes
=
TensorDot
.
parse_axes
(
axes
)
self
.
axes
=
TensorDot
.
parse_axes
(
axes
)
if
isinstance
(
self
.
axes
,
(
tuple
,
list
))
and
len
(
self
.
axes
)
==
2
:
# The current perform don't implement correctly those cases
for
i
in
range
(
len
(
self
.
axes
[
0
])
-
1
):
if
self
.
axes
[
0
][
i
]
>
self
.
axes
[
0
][
i
+
1
]:
raise
NotImplementedError
()
if
self
.
axes
[
1
][
i
]
>
self
.
axes
[
1
][
i
+
1
]:
raise
NotImplementedError
()
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
axes
==
other
.
axes
return
type
(
self
)
==
type
(
other
)
and
self
.
axes
==
other
.
axes
...
@@ -6493,6 +6500,8 @@ class TensorDotGrad(Op):
...
@@ -6493,6 +6500,8 @@ class TensorDotGrad(Op):
newshapey
=
numpy
.
zeros
(
y
.
ndim
)
newshapey
=
numpy
.
zeros
(
y
.
ndim
)
newshapey
[[
newpos
for
newpos
in
idy
]]
=
range
(
y
.
ndim
)
newshapey
[[
newpos
for
newpos
in
idy
]]
=
range
(
y
.
ndim
)
gy
[
0
]
=
numpy
.
transpose
(
_gy
,
newshapey
)
gy
[
0
]
=
numpy
.
transpose
(
_gy
,
newshapey
)
assert
gy
[
0
]
.
shape
==
y
.
shape
assert
gx
[
0
]
.
shape
==
x
.
shape
def
infer_shape
(
self
,
node
,
in_shapes
):
def
infer_shape
(
self
,
node
,
in_shapes
):
inp0_shp
=
[
node
.
inputs
[
0
]
.
shape
[
i
]
inp0_shp
=
[
node
.
inputs
[
0
]
.
shape
[
i
]
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
b731111f
...
@@ -5124,25 +5124,40 @@ class test_tensordot(unittest.TestCase):
...
@@ -5124,25 +5124,40 @@ class test_tensordot(unittest.TestCase):
# Test matrix-matrix
# Test matrix-matrix
amat
=
matrix
()
amat
=
matrix
()
axes
=
((
1
,),(
0
,))
for
axes
,
shps
in
[[((
0
,),
(
0
,)),
[(
4
,
7
),
(
4
,
9
)]],
[((
0
,),
(
1
,)),
[(
4
,
7
),
(
9
,
4
)]],
[((
1
,),
(
0
,)),
[(
4
,
7
),
(
7
,
9
)]],
[((
1
,),
(
1
,)),
[(
4
,
7
),
(
9
,
7
)]],
[((
0
,
1
),
(
0
,
1
)),
[(
4
,
7
),
(
4
,
7
)]],
# [((0, 1), (1, 0)), [(4, 7), (7, 4)]],
# [((1, 0), (1, 0)), [(4, 7), (4, 7)]],
# [((1, 0), (0, 1)), [(4, 7), (7, 4)]],
]:
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
aval
=
rand
(
4
,
7
)
aval
=
rand
(
*
shps
[
0
]
)
bval
=
rand
(
7
,
9
)
bval
=
rand
(
*
shps
[
1
]
)
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
aval
,
bval
,
axes
),
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
aval
,
bval
,
axes
),
f3
(
aval
,
bval
)))
f3
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# Test ndarray-matrix, sum over one dim of matrix
# Test ndarray-matrix, sum over one dim of matrix
for
axes
,
shps
in
[[((
2
,),
(
1
,)),
[(
1
,
2
,
3
,
4
),
(
2
,
3
)]],
[((
0
,),
(
1
,)),
[(
1
,
2
,
3
,
4
),
(
3
,
1
)]],
[((
0
,),
(
0
,)),
[(
1
,
2
,
3
,
4
),
(
1
,
3
)]],
[((
3
,),
(
0
,)),
[(
1
,
2
,
3
,
4
),
(
4
,
1
)]],
# [((3, 1), (0, 1)), [(1, 2, 3, 4), (4, 2)]],
# [((0, 1), (1, 0)), [(1, 2, 3, 4), (2, 1)]],
# [((3, 1), (1, 0)), [(1, 2, 3, 4), (2, 4)]],
]:
atens
=
tensor4
()
atens
=
tensor4
()
axes
=
((
2
,),(
1
,))
c
=
tensordot
(
atens
,
bmat
,
axes
)
c
=
tensordot
(
atens
,
bmat
,
axes
)
f4
=
inplace_func
([
atens
,
bmat
],
c
)
f4
=
inplace_func
([
atens
,
bmat
],
c
)
aval
=
rand
(
1
,
2
,
3
,
4
)
aval
=
rand
(
*
shps
[
0
]
)
bval
=
rand
(
2
,
3
)
bval
=
rand
(
*
shps
[
1
]
)
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
aval
,
bval
,
axes
),
self
.
assertTrue
(
numpy
.
allclose
(
numpy
.
tensordot
(
aval
,
bval
,
axes
),
f4
(
aval
,
bval
)))
f4
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
# Test ndarray-ndarray
# Test ndarray-ndarray
atens
=
tensor4
()
atens
=
tensor4
()
...
@@ -6074,10 +6089,7 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -6074,10 +6089,7 @@ class TestInferShape(utt.InferShapeTester):
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdscal
),
tensordot_grad
(
axes
)(
admat
,
bdmat
,
gzdscal
),
[
admat_val
,
bdmat_val
,
gzdscal_val
],
tensordot_grad
)
[
admat_val
,
bdmat_val
,
gzdscal_val
],
tensordot_grad
)
# Note: The two following tests currently fail and should unlikely be,
# tensordot_grad currently do not support not ordered axes
# 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.
"""
"""
gzdscal = dscalar()
gzdscal = dscalar()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论