From 44420d29228a91798753cac75e6e5fe82c411741 Mon Sep 17 00:00:00 2001 From: Hhankyangg Date: Fri, 19 Jan 2024 00:41:53 +0800 Subject: [PATCH 1/2] fix: fix docstring issue --- python/paddle/base/executor.py | 4 ++-- python/paddle/tensor/linalg.py | 40 ++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/python/paddle/base/executor.py b/python/paddle/base/executor.py index 4a7b24d6618c84..bd68dd695cdb1f 100755 --- a/python/paddle/base/executor.py +++ b/python/paddle/base/executor.py @@ -1203,13 +1203,13 @@ class Executor: >>> # Run the main program directly without compile. >>> x = numpy.random.random(size=(10, 1)).astype('float32') - >>> loss_data, = exe.run(train_program, feed={"X": x}, fetch_list=[loss.name]) + >>> loss_data = exe.run(train_program, feed={"X": x}, fetch_list=[loss.name]) >>> # Or, compiled the program and run. See `CompiledProgram` >>> # for more details. >>> compiled_prog = paddle.static.CompiledProgram( ... train_program) - >>> loss_data, = exe.run(compiled_prog, feed={"X": x}, fetch_list=[loss.name]) + >>> loss_data = exe.run(compiled_prog, feed={"X": x}, fetch_list=[loss.name]) """ diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 19d800482fee0d..4a3c25167d7248 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -63,24 +63,40 @@ def transpose(x, perm, name=None): .. code-block:: text - x = [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12]] - [[13 14 15 16] [17 18 19 20] [21 22 23 24]]] - shape(x) = [2,3,4] + # The following codes in this code block are pseudocode, designed to show the execution logic and results of the function. + + x = to_tensor([[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12]] + [[13 14 15 16] [17 18 19 20] [21 22 23 24]]]) + shape(x): return [2,3,4] # Example 1 perm0 = [1,0,2] - y_perm0 = [[[ 1 2 3 4] [13 14 15 16]] - [[ 5 6 7 8] [17 18 19 20]] - [[ 9 10 11 12] [21 22 23 24]]] - shape(y_perm0) = [3,2,4] + y_perm0 = transpose(x, perm0) # Permute x by perm0 + + # dim:0 of y_perm0 is dim:1 of x + # dim:1 of y_perm0 is dim:0 of x + # dim:2 of y_perm0 is dim:2 of x + # The above two lines can also be understood as exchanging the zeroth and first dimensions of x + + y_perm0.data = [[[ 1 2 3 4] [13 14 15 16]] + [[ 5 6 7 8] [17 18 19 20]] + [[ 9 10 11 12] [21 22 23 24]]] + shape(y_perm0): return [3,2,4] # Example 2 perm1 = [2,1,0] - y_perm1 = [[[ 1 13] [ 5 17] [ 9 21]] - [[ 2 14] [ 6 18] [10 22]] - [[ 3 15] [ 7 19] [11 23]] - [[ 4 16] [ 8 20] [12 24]]] - shape(y_perm1) = [4,3,2] + y_perm1 = transpose(x, perm1) # Permute x by perm1 + + # dim:0 of y_perm1 is dim:2 of x + # dim:1 of y_perm1 is dim:1 of x + # dim:2 of y_perm1 is dim:0 of x + # The above two lines can also be understood as exchanging the zeroth and second dimensions of x + + y_perm1.data = [[[ 1 13] [ 5 17] [ 9 21]] + [[ 2 14] [ 6 18] [10 22]] + [[ 3 15] [ 7 19] [11 23]] + [[ 4 16] [ 8 20] [12 24]]] + shape(y_perm1): return [4,3,2] Examples: From 3503ad98992da966b63f1e0641e23ef6edcfd8a0 Mon Sep 17 00:00:00 2001 From: HankYang <97599656+Hhankyangg@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:28:50 +0800 Subject: [PATCH 2/2] update executor.py --- python/paddle/base/executor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/base/executor.py b/python/paddle/base/executor.py index bd68dd695cdb1f..4a7b24d6618c84 100755 --- a/python/paddle/base/executor.py +++ b/python/paddle/base/executor.py @@ -1203,13 +1203,13 @@ class Executor: >>> # Run the main program directly without compile. >>> x = numpy.random.random(size=(10, 1)).astype('float32') - >>> loss_data = exe.run(train_program, feed={"X": x}, fetch_list=[loss.name]) + >>> loss_data, = exe.run(train_program, feed={"X": x}, fetch_list=[loss.name]) >>> # Or, compiled the program and run. See `CompiledProgram` >>> # for more details. >>> compiled_prog = paddle.static.CompiledProgram( ... train_program) - >>> loss_data = exe.run(compiled_prog, feed={"X": x}, fetch_list=[loss.name]) + >>> loss_data, = exe.run(compiled_prog, feed={"X": x}, fetch_list=[loss.name]) """