Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
52b45007
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
52b45007
编写于
9月 26, 2021
作者:
Z
zhangkaihuo
提交者:
GitHub
9月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update multi_dot exposure rules (#36018)
上级
c330c3d9
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
80 addition
and
78 deletion
+80
-78
python/paddle/__init__.py
python/paddle/__init__.py
+0
-1
python/paddle/fluid/tests/unittests/test_multi_dot_op.py
python/paddle/fluid/tests/unittests/test_multi_dot_op.py
+10
-8
python/paddle/tensor/__init__.py
python/paddle/tensor/__init__.py
+1
-0
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+69
-69
未找到文件。
python/paddle/__init__.py
浏览文件 @
52b45007
...
...
@@ -103,7 +103,6 @@ from .tensor.linalg import histogram # noqa: F401
from
.tensor.linalg
import
mv
# noqa: F401
from
.tensor.linalg
import
det
# noqa: F401
from
.tensor.linalg
import
slogdet
# noqa: F401
from
.tensor.linalg
import
multi_dot
# noqa: F401
from
.tensor.linalg
import
matrix_power
# noqa: F401
from
.tensor.linalg
import
svd
# noqa: F401
from
.tensor.linalg
import
solve
# noqa: F401
...
...
python/paddle/fluid/tests/unittests/test_multi_dot_op.py
浏览文件 @
52b45007
...
...
@@ -198,32 +198,34 @@ class TestMultiDotOpError(unittest.TestCase):
paddle
.
static
.
Program
()):
# The inputs type of multi_dot must be list matrix.
input1
=
12
self
.
assertRaises
(
TypeError
,
paddle
.
multi_dot
,
[
input1
,
input1
])
self
.
assertRaises
(
TypeError
,
paddle
.
linalg
.
multi_dot
,
[
input1
,
input1
])
# The inputs dtype of multi_dot must be float64, float64 or float16.
input2
=
paddle
.
static
.
data
(
name
=
'input2'
,
shape
=
[
10
,
10
],
dtype
=
"int32"
)
self
.
assertRaises
(
TypeError
,
paddle
.
multi_dot
,
[
input2
,
input2
])
self
.
assertRaises
(
TypeError
,
paddle
.
linalg
.
multi_dot
,
[
input2
,
input2
])
# the number of tensor must be larger than 1
x0
=
paddle
.
static
.
data
(
name
=
'x0'
,
shape
=
[
3
,
2
],
dtype
=
"float64"
)
self
.
assertRaises
(
ValueError
,
paddle
.
multi_dot
,
[
x0
])
self
.
assertRaises
(
ValueError
,
paddle
.
linalg
.
multi_dot
,
[
x0
])
#the first tensor must be 1D or 2D
x1
=
paddle
.
static
.
data
(
name
=
'x1'
,
shape
=
[
3
,
2
,
3
],
dtype
=
"float64"
)
x2
=
paddle
.
static
.
data
(
name
=
'x2'
,
shape
=
[
3
,
2
],
dtype
=
"float64"
)
self
.
assertRaises
(
ValueError
,
paddle
.
multi_dot
,
[
x1
,
x2
])
self
.
assertRaises
(
ValueError
,
paddle
.
linalg
.
multi_dot
,
[
x1
,
x2
])
#the last tensor must be 1D or 2D
x3
=
paddle
.
static
.
data
(
name
=
'x3'
,
shape
=
[
3
,
2
],
dtype
=
"float64"
)
x4
=
paddle
.
static
.
data
(
name
=
'x4'
,
shape
=
[
3
,
2
,
2
],
dtype
=
"float64"
)
self
.
assertRaises
(
ValueError
,
paddle
.
multi_dot
,
[
x3
,
x4
])
self
.
assertRaises
(
ValueError
,
paddle
.
linalg
.
multi_dot
,
[
x3
,
x4
])
#the tensor must be 2D, except first and last tensor
x5
=
paddle
.
static
.
data
(
name
=
'x5'
,
shape
=
[
3
,
2
],
dtype
=
"float64"
)
x6
=
paddle
.
static
.
data
(
name
=
'x6'
,
shape
=
[
2
],
dtype
=
"float64"
)
x7
=
paddle
.
static
.
data
(
name
=
'x7'
,
shape
=
[
2
,
2
],
dtype
=
"float64"
)
self
.
assertRaises
(
ValueError
,
paddle
.
multi_dot
,
[
x5
,
x6
,
x7
])
self
.
assertRaises
(
ValueError
,
paddle
.
linalg
.
multi_dot
,
[
x5
,
x6
,
x7
])
class
APITestMultiDot
(
unittest
.
TestCase
):
...
...
@@ -232,7 +234,7 @@ class APITestMultiDot(unittest.TestCase):
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x0
=
paddle
.
static
.
data
(
name
=
'x0'
,
shape
=
[
3
,
2
],
dtype
=
"float64"
)
x1
=
paddle
.
static
.
data
(
name
=
'x1'
,
shape
=
[
2
,
3
],
dtype
=
'float64'
)
result
=
paddle
.
multi_dot
([
x0
,
x1
])
result
=
paddle
.
linalg
.
multi_dot
([
x0
,
x1
])
exe
=
paddle
.
static
.
Executor
(
paddle
.
CPUPlace
())
data1
=
np
.
random
.
rand
(
3
,
2
).
astype
(
"float64"
)
data2
=
np
.
random
.
rand
(
2
,
3
).
astype
(
"float64"
)
...
...
@@ -254,7 +256,7 @@ class APITestMultiDot(unittest.TestCase):
input_array2
=
np
.
random
.
rand
(
4
,
3
).
astype
(
"float64"
)
data1
=
paddle
.
to_tensor
(
input_array1
)
data2
=
paddle
.
to_tensor
(
input_array2
)
out
=
paddle
.
multi_dot
([
data1
,
data2
])
out
=
paddle
.
linalg
.
multi_dot
([
data1
,
data2
])
expected_result
=
np
.
linalg
.
multi_dot
([
input_array1
,
input_array2
])
self
.
assertTrue
(
np
.
allclose
(
expected_result
,
out
.
numpy
()))
...
...
python/paddle/tensor/__init__.py
浏览文件 @
52b45007
...
...
@@ -387,6 +387,7 @@ tensor_method_func = [ #noqa
'bitwise_not'
,
'broadcast_tensors'
,
'uniform_'
,
'multi_dot'
,
'solve'
,
]
...
...
python/paddle/tensor/linalg.py
浏览文件 @
52b45007
...
...
@@ -975,8 +975,8 @@ def t(input, name=None):
return
out
check_variable_and_dtype
(
input
,
'input'
,
[
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'transpose'
)
input
,
'input'
,
[
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'transpose'
)
helper
=
LayerHelper
(
't'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
input
.
dtype
)
...
...
@@ -1360,7 +1360,7 @@ def det(x):
Returns:
y (Tensor):the determinant value of a square matrix or batches of square matrices.
Example
:
Example
s:
.. code-block:: python
import paddle
...
...
@@ -1415,7 +1415,7 @@ def slogdet(x):
y (Tensor): A tensor containing the sign of the determinant and the natural logarithm
of the absolute value of determinant, respectively.
Example:
Example
s
:
.. code-block:: python
import paddle
...
...
@@ -1630,8 +1630,8 @@ def eigvals(x, name=None):
"""
check_variable_and_dtype
(
x
,
'dtype'
,
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
],
'eigvals'
)
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
],
'eigvals'
)
x_shape
=
list
(
x
.
shape
)
if
len
(
x_shape
)
<
2
:
...
...
@@ -1657,7 +1657,7 @@ def multi_dot(x, name=None):
"""
Multi_dot is an operator that calculates multiple matrix multiplications.
Supports inputs of float
, double and float16
dtypes. This function does not
Supports inputs of float
16(only GPU support), float32 and float64
dtypes. This function does not
support batched inputs.
The input tensor in [x] must be 2-D except for the first and last can be 1-D.
...
...
@@ -1699,7 +1699,7 @@ def multi_dot(x, name=None):
B_data = np.random.random([4, 5]).astype(np.float32)
A = paddle.to_tensor(A_data)
B = paddle.to_tensor(B_data)
out = paddle.multi_dot([A, B])
out = paddle.
linalg.
multi_dot([A, B])
print(out.numpy().shape)
# [3, 5]
...
...
@@ -1710,7 +1710,7 @@ def multi_dot(x, name=None):
A = paddle.to_tensor(A_data)
B = paddle.to_tensor(B_data)
C = paddle.to_tensor(C_data)
out = paddle.multi_dot([A, B, C])
out = paddle.
linalg.
multi_dot([A, B, C])
print(out.numpy().shape)
# [10, 7]
...
...
@@ -1998,8 +1998,8 @@ def pinv(x, rcond=1e-15, hermitian=False, name=None):
helper
=
LayerHelper
(
'pinv'
,
**
locals
())
dtype
=
x
.
dtype
check_variable_and_dtype
(
x
,
'dtype'
,
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
],
'pinv'
)
x
,
'dtype'
,
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
],
'pinv'
)
if
dtype
==
paddle
.
complex128
:
s_type
=
'float64'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录