Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
ce93eea8
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ce93eea8
编写于
1月 19, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine unit test
上级
0468422d
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
45 addition
and
27 deletion
+45
-27
python/paddle/v2/fluid/tests/test_matmul_op.py
python/paddle/v2/fluid/tests/test_matmul_op.py
+45
-27
未找到文件。
python/paddle/v2/fluid/tests/test_matmul_op.py
浏览文件 @
ce93eea8
...
@@ -59,19 +59,18 @@ def reference_matmul(X, Y, transpose_X=False, transpose_Y=False):
...
@@ -59,19 +59,18 @@ def reference_matmul(X, Y, transpose_X=False, transpose_Y=False):
X
=
X
.
reshape
((
X
.
size
,
1
))
X
=
X
.
reshape
((
X
.
size
,
1
))
elif
X
.
ndim
==
2
:
elif
X
.
ndim
==
2
:
X
=
X
.
T
X
=
X
.
T
elif
X
.
ndim
==
3
:
X
=
np
.
transpose
(
X
,
(
0
,
2
,
1
))
else
:
else
:
raise
ValueError
(
'X must have between 1 and 3 dimensions'
)
dim
=
[
i
for
i
in
range
(
len
(
X
.
shape
))]
dim
[
-
1
],
dim
[
len
(
X
.
shape
)
-
2
]
=
dim
[
len
(
X
.
shape
)
-
2
],
dim
[
-
1
]
X
=
np
.
transpose
(
X
,
tuple
(
dim
))
if
transpose_Y
:
if
transpose_Y
:
if
Y
.
ndim
==
1
:
if
Y
.
ndim
==
1
:
Y
=
Y
.
reshape
((
1
,
Y
.
size
))
Y
=
Y
.
reshape
((
1
,
Y
.
size
))
elif
Y
.
ndim
==
2
:
Y
=
Y
.
T
elif
Y
.
ndim
==
3
:
Y
=
np
.
transpose
(
Y
,
(
0
,
2
,
1
))
else
:
else
:
raise
ValueError
(
'Y must have between 1 and 3 dimensions'
)
dim
=
[
i
for
i
in
range
(
len
(
Y
.
shape
))]
dim
[
-
1
],
dim
[
len
(
Y
.
shape
)
-
2
]
=
dim
[
len
(
Y
.
shape
)
-
2
],
dim
[
-
1
]
Y
=
np
.
transpose
(
Y
,
tuple
(
dim
))
Out
=
np
.
matmul
(
X
,
Y
)
Out
=
np
.
matmul
(
X
,
Y
)
if
not
Out
.
shape
:
if
not
Out
.
shape
:
# We do not support 0-dimensional Tensors (scalars). So where
# We do not support 0-dimensional Tensors (scalars). So where
...
@@ -120,30 +119,49 @@ for dim_X in [1, 2, 3]:
...
@@ -120,30 +119,49 @@ for dim_X in [1, 2, 3]:
dim_X
,
dim_Y
,
transpose_X
,
transpose_Y
))
dim_X
,
dim_Y
,
transpose_X
,
transpose_Y
))
shape_X
,
shape_Y
=
generate_compatible_shapes
(
shape_X
,
shape_Y
=
generate_compatible_shapes
(
dim_X
,
dim_Y
,
transpose_X
,
transpose_Y
)
dim_X
,
dim_Y
,
transpose_X
,
transpose_Y
)
test_class
=
type
(
test_name
,
(
Generator
,
OpTest
),
{
globals
()[
test_name
]
=
type
(
test_name
,
(
Generator
,
OpTest
),
{
'shape_X'
:
shape_X
,
'shape_X'
:
shape_X
,
'shape_Y'
:
shape_Y
,
'shape_Y'
:
shape_Y
,
'transpose_X'
:
transpose_X
,
'transpose_X'
:
transpose_X
,
'transpose_Y'
:
transpose_Y
,
'transpose_Y'
:
transpose_Y
,
})
})
globals
()[
test_name
]
=
test_class
# Test case 4-dim
dim_X
=
4
dim_Y
=
4
transpose_X
=
False
transpose_Y
=
False
test_name
=
(
'TestMatMulOp_dimX_{}_dim_Y_{}_transX_{}_transY_{}'
.
format
(
dim_X
,
dim_Y
,
transpose_X
,
transpose_Y
))
shape_X
=
[
2
,
2
,
2
,
3
]
shape_Y
=
[
2
,
2
,
3
,
4
]
def
generate_compatible_shapes
(
dim
,
transpose_X
,
transpose_Y
):
test_class
=
type
(
test_name
,
(
Generator
,
OpTest
),
{
M
=
2
N
=
4
K
=
3
shape_X
=
[
2
for
_
in
range
(
dim
-
2
)]
shape_Y
=
[
2
for
_
in
range
(
dim
-
2
)]
if
transpose_X
:
shape_X
=
shape_X
+
[
K
,
M
]
else
:
shape_X
=
shape_X
+
[
M
,
K
]
if
transpose_Y
:
shape_Y
=
shape_Y
+
[
N
,
K
]
else
:
shape_Y
=
shape_Y
+
[
K
,
N
]
return
shape_X
,
shape_Y
# Test case n-dim
for
dim
in
[
4
]:
for
transpose_X
in
[
False
,
True
]:
for
transpose_Y
in
[
False
,
True
]:
test_name
=
(
'TestMatMulOp_dimX_{}_dim_Y_{}_transX_{}_transY_{}'
.
format
(
dim
,
dim
,
transpose_X
,
transpose_Y
))
shape_X
,
shape_Y
=
generate_compatible_shapes
(
dim
,
transpose_X
,
transpose_Y
)
globals
()[
test_name
]
=
type
(
test_name
,
(
Generator
,
OpTest
),
{
'shape_X'
:
shape_X
,
'shape_X'
:
shape_X
,
'shape_Y'
:
shape_Y
,
'shape_Y'
:
shape_Y
,
'transpose_X'
:
transpose_X
,
'transpose_X'
:
transpose_X
,
'transpose_Y'
:
transpose_Y
,
'transpose_Y'
:
transpose_Y
,
})
})
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录