fixed imperative module in doc example code (#26149)

* fixed imperative module in doc example code

* fixed static module

* solve conflict
revert-24895-update_cub
pangyoki 5 years ago committed by GitHub
parent dbc88bb900
commit 13b80d9bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because it is too large Load Diff

@ -240,13 +240,13 @@ class TestAddMMAPI(unittest.TestCase):
data_y = np.ones((2, 2)).astype(np.float32)
data_input = np.ones((2, 2)).astype(np.float32)
paddle.enable_imperative()
paddle.disable_static()
def test_error1():
data_x_wrong = np.ones((2, 3)).astype(np.float32)
x = paddle.imperative.to_variable(data_x_wrong)
y = paddle.imperative.to_variable(data_y)
input = paddle.imperative.to_variable(data_input)
x = paddle.to_variable(data_x_wrong)
y = paddle.to_variable(data_y)
input = paddle.to_variable(data_input)
out = paddle.tensor.addmm( input=input, x=x, y=y, beta=0.5, alpha=5.0 )
self.assertRaises(ValueError, test_error1)
'''

@ -561,9 +561,9 @@ def tril(x, diagonal=0, name=None):
# [ 5, 6, 7, 8],
# [ 9, 10, 11, 12]])
paddle.enable_imperative()
paddle.disable_static()
x = paddle.imperative.to_variable(data)
x = paddle.to_variable(data)
tril1 = paddle.tensor.tril(x)
# array([[ 1, 0, 0, 0],
@ -632,10 +632,10 @@ def triu(x, diagonal=0, name=None):
# [ 5, 6, 7, 8],
# [ 9, 10, 11, 12]])
paddle.enable_imperative()
paddle.disable_static()
# example 1, default diagonal
x = paddle.imperative.to_variable(data)
x = paddle.to_variable(data)
triu1 = paddle.tensor.triu(x)
# array([[ 1, 2, 3, 4],
# [ 0, 6, 7, 8],

@ -735,10 +735,10 @@ def bmm(x, y, name=None):
input1 = np.array([[[1.0, 1.0, 1.0],[2.0, 2.0, 2.0]],[[3.0, 3.0, 3.0],[4.0, 4.0, 4.0]]])
input2 = np.array([[[1.0, 1.0],[2.0, 2.0],[3.0, 3.0]],[[4.0, 4.0],[5.0, 5.0],[6.0, 6.0]]])
paddle.enable_imperative()
paddle.disable_static()
x = paddle.imperative.to_variable(input1)
y = paddle.imperative.to_variable(input2)
x = paddle.to_variable(input1)
y = paddle.to_variable(input2)
out = paddle.bmm(x, y)
#output size: (2, 2, 2)
#output value:

@ -457,10 +457,10 @@ def stack(x, axis=0, name=None):
data2 = np.array([[3.0, 4.0]])
data3 = np.array([[5.0, 6.0]])
paddle.enable_imperative()
x1 = paddle.imperative.to_variable(data1)
x2 = paddle.imperative.to_variable(data2)
x3 = paddle.imperative.to_variable(data3)
paddle.disable_static()
x1 = paddle.to_variable(data1)
x2 = paddle.to_variable(data2)
x3 = paddle.to_variable(data3)
out = paddle.stack([x1, x2, x3], axis=0)
print(out.shape) # [3, 1, 2]
@ -637,7 +637,7 @@ def unsqueeze(x, axis, name=None):
import paddle
paddle.enable_imperative()
paddle.disable_static()
x = paddle.rand([5, 10])
print(x.shape) # [5, 10]

@ -883,11 +883,11 @@ def addmm(input, x, y, beta=1.0, alpha=1.0, name=None):
data_y = np.ones((2, 2)).astype(np.float32)
data_input = np.ones((2, 2)).astype(np.float32)
paddle.enable_imperative()
paddle.disable_static()
x = paddle.imperative.to_variable(data_x)
y = paddle.imperative.to_variable(data_y)
input = paddle.imperative.to_variable(data_input)
x = paddle.to_variable(data_x)
y = paddle.to_variable(data_y)
input = paddle.to_variable(data_input)
out = paddle.tensor.addmm( input=input, x=x, y=y, beta=0.5, alpha=5.0 )
@ -1561,10 +1561,10 @@ def cumsum(x, axis=None, dtype=None, name=None):
.. code-block:: python
import paddle
from paddle.imperative import to_variable
from paddle import to_variable
import numpy as np
paddle.enable_imperative()
paddle.disable_static()
data_np = np.arange(12).reshape(3, 4)
data = to_variable(data_np)

Loading…
Cancel
Save