Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
95b896ce
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
95b896ce
编写于
1月 19, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update python interface
上级
259858b4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
9 deletion
+12
-9
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+12
-9
未找到文件。
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
95b896ce
...
@@ -1702,10 +1702,11 @@ def l2_normalize(x, axis, epsilon=1e-12, name=None):
...
@@ -1702,10 +1702,11 @@ def l2_normalize(x, axis, epsilon=1e-12, name=None):
def
matmul
(
x
,
y
,
transpose_x
=
False
,
transpose_y
=
False
,
name
=
None
):
def
matmul
(
x
,
y
,
transpose_x
=
False
,
transpose_y
=
False
,
name
=
None
):
"""
"""
Applies matrix multipication to two tensors. Currently only rank 1 to rank
Applies matrix multiplication to two tensors. Currently, the input
3 input tensors are supported.
tensors' rank can be any, but when the rank of anyone inputs is
bigger than 3, this two inputs' rank should be equal.
The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
- If a transpose flag is specified, the last two dimensions of the tensor
- If a transpose flag is specified, the last two dimensions of the tensor
...
@@ -1715,17 +1716,17 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
...
@@ -1715,17 +1716,17 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
opposite: It is treated as :math:`[D, 1]` in nontransposed form and as
opposite: It is treated as :math:`[D, 1]` in nontransposed form and as
:math:`[1, D]` in transposed form.
:math:`[1, D]` in transposed form.
- After transpose, the two tensors are 2-D or
3-D and matrix multipication
- After transpose, the two tensors are 2-D or
n-D and matrix multiplication
performs in the following way.
performs in the following way.
- If both are 2-D, they are multiplied like conventional matrices.
- If both are 2-D, they are multiplied like conventional matrices.
- If either is
3-D, it is treated as a stack of matrices residing in the
- If either is
n-D, it is treated as a stack of matrices residing in the
last two dimensions and a batched matrix multiply supporting broadcast
last two dimensions and a batched matrix multiply supporting broadcast
applies on the two tensors.
applies on the two tensors.
Also note that if the raw tensor :math:`x` or :math:`y` is rank-1 and
Also note that if the raw tensor :math:`x` or :math:`y` is rank-1 and
nontransposed, the prepended or appended dimension :math:`1` will be
nontransposed, the prepended or appended dimension :math:`1` will be
removed after matrix multipication.
removed after matrix multip
l
ication.
Args:
Args:
x (Variable): The input variable which is a Tensor or LoDTensor.
x (Variable): The input variable which is a Tensor or LoDTensor.
...
@@ -1742,6 +1743,8 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
...
@@ -1742,6 +1743,8 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
.. code-block:: python
.. code-block:: python
# Examples to clarify shapes of the inputs and output
# Examples to clarify shapes of the inputs and output
# x: [B, ..., M, K], y: [B, ..., K, N]
fluid.layers.matmul(x, y) # out: [B, ..., M, N]
# x: [B, M, K], y: [B, K, N]
# x: [B, M, K], y: [B, K, N]
fluid.layers.matmul(x, y) # out: [B, M, N]
fluid.layers.matmul(x, y) # out: [B, M, N]
# x: [B, M, K], y: [K, N]
# x: [B, M, K], y: [K, N]
...
@@ -1757,9 +1760,9 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
...
@@ -1757,9 +1760,9 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
fluid.layers.matmul(x, y, True, True) # out: [M, N]
fluid.layers.matmul(x, y, True, True) # out: [M, N]
"""
"""
helper
=
LayerHelper
(
'matmul'
,
**
locals
())
helper
=
LayerHelper
(
'matmul'
,
**
locals
())
assert
max
(
assert
max
(
len
(
x
.
shape
),
len
(
y
.
shape
))
<=
3
or
len
(
x
.
shape
)
==
len
(
len
(
x
.
shape
),
len
(
y
.
shape
)
y
.
)
<=
3
,
'Currently only rank 1 to rank 3 input tensors are supported
.'
shape
),
'Inputs
\'
rank should be equal or their rank should be less 4
.'
out
=
helper
.
create_tmp_variable
(
dtype
=
helper
.
input_dtype
())
out
=
helper
.
create_tmp_variable
(
dtype
=
helper
.
input_dtype
())
helper
.
append_op
(
helper
.
append_op
(
type
=
'matmul'
,
type
=
'matmul'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录