未验证 提交 52b45007 编写于 作者: Z zhangkaihuo 提交者: GitHub

update multi_dot exposure rules (#36018)

上级 c330c3d9
......@@ -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
......
......@@ -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()))
......
......@@ -387,6 +387,7 @@ tensor_method_func = [ #noqa
'bitwise_not',
'broadcast_tensors',
'uniform_',
'multi_dot',
'solve',
]
......
......@@ -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:
Examples:
.. 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:
Examples:
.. 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 float16(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.
先完成此消息的编辑!
想要评论请 注册