Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
5113aae6
P
Paddle
项目概览
urhero
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5113aae6
编写于
8月 13, 2020
作者:
S
ShenLiang
提交者:
GitHub
8月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the doc of inverse, dot, cholesky (#25860)
* fix the doc of inverse, dot, cholesky
上级
cfa086bd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
63 deletion
+53
-63
python/paddle/fluid/tests/unittests/test_cholesky_op.py
python/paddle/fluid/tests/unittests/test_cholesky_op.py
+10
-0
python/paddle/fluid/tests/unittests/test_inverse_op.py
python/paddle/fluid/tests/unittests/test_inverse_op.py
+2
-3
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+24
-27
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+17
-33
未找到文件。
python/paddle/fluid/tests/unittests/test_cholesky_op.py
浏览文件 @
5113aae6
...
@@ -90,5 +90,15 @@ class TestCholeskyOp2D(TestCholeskyOp):
...
@@ -90,5 +90,15 @@ class TestCholeskyOp2D(TestCholeskyOp):
self
.
_input_shape
=
(
64
,
64
)
self
.
_input_shape
=
(
64
,
64
)
class
TestDygraph
(
unittest
.
TestCase
):
def
test_dygraph
(
self
):
paddle
.
disable_static
()
a
=
np
.
random
.
rand
(
3
,
3
)
a_t
=
np
.
transpose
(
a
,
[
1
,
0
])
x_data
=
np
.
matmul
(
a
,
a_t
)
+
1e-03
x
=
paddle
.
to_variable
(
x_data
)
out
=
paddle
.
cholesky
(
x
,
upper
=
False
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_inverse_op.py
浏览文件 @
5113aae6
...
@@ -89,8 +89,7 @@ class TestInverseAPI(unittest.TestCase):
...
@@ -89,8 +89,7 @@ class TestInverseAPI(unittest.TestCase):
def
check_static_result
(
self
,
place
):
def
check_static_result
(
self
,
place
):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
4
,
4
],
dtype
=
"float64"
)
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
4
,
4
],
dtype
=
"float64"
)
result
=
paddle
.
inverse
(
input
=
input
)
result
=
paddle
.
inverse
(
x
=
input
)
input_np
=
np
.
random
.
random
([
4
,
4
]).
astype
(
"float64"
)
input_np
=
np
.
random
.
random
([
4
,
4
]).
astype
(
"float64"
)
result_np
=
np
.
linalg
.
inv
(
input_np
)
result_np
=
np
.
linalg
.
inv
(
input_np
)
...
@@ -145,7 +144,7 @@ class TestInverseSingularAPI(unittest.TestCase):
...
@@ -145,7 +144,7 @@ class TestInverseSingularAPI(unittest.TestCase):
def
check_static_result
(
self
,
place
):
def
check_static_result
(
self
,
place
):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
4
,
4
],
dtype
=
"float64"
)
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
4
,
4
],
dtype
=
"float64"
)
result
=
paddle
.
inverse
(
input
=
input
)
result
=
paddle
.
inverse
(
x
=
input
)
input_np
=
np
.
zeros
([
4
,
4
]).
astype
(
"float64"
)
input_np
=
np
.
zeros
([
4
,
4
]).
astype
(
"float64"
)
...
...
python/paddle/tensor/linalg.py
浏览文件 @
5113aae6
...
@@ -452,21 +452,18 @@ def dist(x, y, p=2):
...
@@ -452,21 +452,18 @@ def dist(x, y, p=2):
def
dot
(
x
,
y
,
name
=
None
):
def
dot
(
x
,
y
,
name
=
None
):
"""
"""
:alias_main: paddle.dot
:alias: paddle.dot,paddle.tensor.dot,paddle.tensor.linalg.dot
This operator calculates inner product for vectors.
This operator calculates inner product for vectors.
.. note::
.. note::
Only support 1-d Tensor(vector).
Only support 1-d Tensor(vector).
Parameters:
Parameters:
x(
Variable): 1-D ``Tensor`` or ``LoD
Tensor``. Its datatype should be ``float32``, ``float64``, ``int32``, ``int64``
x(
Tensor): 1-D ``
Tensor``. Its datatype should be ``float32``, ``float64``, ``int32``, ``int64``
y(
Variable): 1-D ``Tensor`` or ``LoD
Tensor``. Its datatype soulde be ``float32``, ``float64``, ``int32``, ``int64``
y(
Tensor): 1-D ``
Tensor``. Its datatype soulde be ``float32``, ``float64``, ``int32``, ``int64``
name(str, optional): Name of the output. Default is None. It's used to print debug info for developers. Details: :ref:`api_guide_Name`
name(str, optional): Name of the output. Default is None. It's used to print debug info for developers. Details: :ref:`api_guide_Name`
Returns:
Returns:
Variable: the calculated result Tensor
/LoDTensor
.
Variable: the calculated result Tensor.
Examples:
Examples:
...
@@ -475,12 +472,14 @@ def dot(x, y, name=None):
...
@@ -475,12 +472,14 @@ def dot(x, y, name=None):
import paddle
import paddle
import paddle.fluid as fluid
import paddle.fluid as fluid
import numpy as np
import numpy as np
with fluid.dygraph.guard():
paddle.disable_static()
x = fluid.dygraph.to_variable(np.random.uniform(0.1, 1, [10]).astype(np.float32))
x_data = np.random.uniform(0.1, 1, [10]).astype(np.float32)
y = fluid.dygraph.to_variable(np.random.uniform(1, 3, [10]).astype(np.float32))
y_data = np.random.uniform(1, 3, [10]).astype(np.float32)
z = paddle.dot(x, y)
x = paddle.to_variable(x_data)
print(z.numpy())
y = paddle.to_variable(y_data)
z = paddle.dot(x, y)
print(z.numpy())
"""
"""
op_type
=
'dot'
op_type
=
'dot'
...
@@ -651,11 +650,8 @@ def cross(x, y, axis=None, name=None):
...
@@ -651,11 +650,8 @@ def cross(x, y, axis=None, name=None):
return
out
return
out
def
cholesky
(
x
,
upper
=
False
):
def
cholesky
(
x
,
upper
=
False
,
name
=
None
):
"""
"""
:alias_main: paddle.cholesky
:alias: paddle.cholesky,paddle.tensor.cholesky,paddle.tensor.linalg.cholesky
Computes the Cholesky decomposition of one symmetric positive-definite
Computes the Cholesky decomposition of one symmetric positive-definite
matrix or batches of symmetric positive-definite matrice.
matrix or batches of symmetric positive-definite matrice.
...
@@ -680,21 +676,22 @@ def cholesky(x, upper=False):
...
@@ -680,21 +676,22 @@ def cholesky(x, upper=False):
.. code-block:: python
.. code-block:: python
import paddle
import paddle
import paddle.fluid as fluid
import numpy as np
import numpy as np
with fluid.dygraph.guard():
paddle.disable_static()
a = np.random.rand(3, 3)
a = np.random.rand(3, 3)
a_t = np.transpose(a, [1, 0])
a_t = np.transpose(a, [1, 0])
x
= np.matmul(a, a_t) + 1e-03
x_data
= np.matmul(a, a_t) + 1e-03
x = fluid.dygraph.to_variable(x
)
x = paddle.to_variable(x_data
)
out = paddle.cholesky(x, upper=False)
out = paddle.cholesky(x, upper=False)
print(out.numpy())
print(out.numpy())
# [[1.190523 0. 0. ]
# [[1.190523 0. 0. ]
# [0.9906703 0.27676893 0. ]
# [0.9906703 0.27676893 0. ]
# [1.25450498 0.05600871 0.06400121]]
# [1.25450498 0.05600871 0.06400121]]
"""
"""
if
in_dygraph_mode
():
return
core
.
ops
.
cholesky
(
x
,
"upper"
,
upper
)
check_variable_and_dtype
(
x
,
'dtype'
,
[
'float32'
,
'float64'
],
'cholesky'
)
check_variable_and_dtype
(
x
,
'dtype'
,
[
'float32'
,
'float64'
],
'cholesky'
)
check_type
(
upper
,
'upper'
,
bool
,
'cholesky'
)
check_type
(
upper
,
'upper'
,
bool
,
'cholesky'
)
helper
=
LayerHelper
(
'cholesky'
,
**
locals
())
helper
=
LayerHelper
(
'cholesky'
,
**
locals
())
...
...
python/paddle/tensor/math.py
浏览文件 @
5113aae6
...
@@ -1099,17 +1099,15 @@ def logsumexp(x, dim=None, keepdim=False, name=None):
...
@@ -1099,17 +1099,15 @@ def logsumexp(x, dim=None, keepdim=False, name=None):
return
layers
.
log
(
sum_out
,
name
)
return
layers
.
log
(
sum_out
,
name
)
def
inverse
(
input
,
name
=
None
):
"""
:alias_main: paddle.inverse
:alias: paddle.inverse,paddle.tensor.inverse,paddle.tensor.math.inverse
def
inverse
(
x
,
name
=
None
):
"""
Takes the inverse of the square matrix. A square matrix is a matrix with
Takes the inverse of the square matrix. A square matrix is a matrix with
the same number of rows and columns. The input can be a square matrix
the same number of rows and columns. The input can be a square matrix
(2-D Tensor) or batches of square matrices.
(2-D Tensor) or batches of square matrices.
Args:
Args:
input (Variable): The input Variable which holds a T
ensor. The last two
x (Variable): The input t
ensor. The last two
dimensions should be equal. When the number of dimensions is
dimensions should be equal. When the number of dimensions is
greater than 2, it is treated as batches of square matrix. The data
greater than 2, it is treated as batches of square matrix. The data
type can be float32 and float64.
type can be float32 and float64.
...
@@ -1118,52 +1116,38 @@ def inverse(input, name=None):
...
@@ -1118,52 +1116,38 @@ def inverse(input, name=None):
please refer to :ref:`api_guide_Name`
please refer to :ref:`api_guide_Name`
Returns:
Returns:
Variable: A Tensor holds the inverse of
input
. The shape and data type
Variable: A Tensor holds the inverse of
x
. The shape and data type
is the same as input
.
is the same as x
.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
import numpy as np
import paddle
import paddle
import paddle.fluid as fluid
mat_np = np.array([[2, 0], [0, 2]]).astype("float32")
mat_np = np.array([[2, 0], [0, 2]]).astype("float32")
paddle.disable_static()
mat = paddle.to_variable(mat_np)
inv = paddle.inverse(mat)
print(inv) # [[0.5, 0], [0, 0.5]]
# example for static graph
input = fluid.data("input", shape=[2, 2], dtype="float32")
out = paddle.inverse(input)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
results = exe.run(feed={"input": mat_np },
fetch_list=[out.name])
print(results[0]) # [[0.5, 0], [0, 0.5]]
# example for dynamic graph
with fluid.dygraph.guard():
mat = fluid.dygraph.to_variable(mat_np)
inv = paddle.inverse(mat)
print(inv) # [[0.5, 0], [0, 0.5]]
"""
"""
if
in_dygraph_mode
():
if
in_dygraph_mode
():
return
core
.
ops
.
inverse
(
input
)
return
core
.
ops
.
inverse
(
x
)
def
_check_input
(
input
):
def
_check_input
(
x
):
check_variable_and_dtype
(
input
,
'input
'
,
check_variable_and_dtype
(
x
,
'x
'
,
[
'float32'
,
'float64'
],
'inverse'
)
[
'float32'
,
'float64'
],
'inverse'
)
if
len
(
input
.
shape
)
<
2
:
if
len
(
x
.
shape
)
<
2
:
raise
ValueError
(
raise
ValueError
(
"The input of inverse is expected to be a Tensor whose number "
"The input of inverse is expected to be a Tensor whose number "
"of dimensions is no less than 2. But reviced: %d, "
"of dimensions is no less than 2. But reviced: %d, "
"input's shape: %s."
%
(
len
(
input
.
shape
),
input
.
shape
))
"x's shape: %s."
%
(
len
(
x
.
shape
),
x
.
shape
))
_check_input
(
x
)
_check_input
(
input
)
helper
=
LayerHelper
(
'inverse'
,
**
locals
())
helper
=
LayerHelper
(
'inverse'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
input
.
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
helper
.
append_op
(
type
=
'inverse'
,
inputs
=
{
'Input'
:
[
input
]
},
outputs
=
{
'Output'
:
[
out
]})
type
=
'inverse'
,
inputs
=
{
'Input'
:
[
x
]
},
outputs
=
{
'Output'
:
[
out
]})
return
out
return
out
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录