未验证 提交 aa28e446 编写于 作者: iSerendipity's avatar iSerendipity 提交者: GitHub

[xdoctest][task 291] reformat example code with google style in...

[xdoctest][task 291] reformat example code with google style in `python/paddle/incubate/operators/unzip.py` (#56826)

* [Doctest] fix No.291, test=docs_preview

* fix

* Update python/paddle/incubate/operators/unzip.py

* switch to gpu

---------
Co-authored-by: NNyakku Shigure <sigure.qaq@gmail.com>
上级 a277fe4d
......@@ -33,34 +33,33 @@ def unzip(input, lod):
Examples:
.. code-block:: python
import numpy as np
import paddle
import paddle.fluid as fluid
paddle.enable_static()
input_np = np.array([
[1.0, 2.0, 3.0, 4.0],
[10.0, 20.0, 30.0, 40.0],
[100.0, 200.0, 300.0, 400.0]
])
lod_np = np.array([0, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12])
input = paddle.to_tensor(input_np, "int64")
lod = paddle.to_tensor(lod_np, "int64")
unzipped_input = paddle.incubate.unzip(input, lod)
'''
unzipped_input is [
[1.0, 2.0, 3.0, 4.0],
[0.0, 0.0, 0.0, 0.0],
[10.0, 20.0, 30.0, 40.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[100.0, 200.0, 300.0, 400.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0]
]
'''
>>> # doctest: +REQUIRES(env:GPU)
>>> import numpy as np
>>> import paddle
>>> paddle.set_device('gpu')
>>> input_np = np.array([
... [1.0, 2.0, 3.0, 4.0],
... [10.0, 20.0, 30.0, 40.0],
... [100.0, 200.0, 300.0, 400.0]
... ])
>>> lod_np = np.array([0, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12])
>>> input = paddle.to_tensor(input_np, "int64")
>>> lod = paddle.to_tensor(lod_np, "int64")
>>> unzipped_input = paddle.incubate.operators.unzip(input, lod)
>>> print(unzipped_input)
Tensor(shape=[10, 4], dtype=int64, place=Place(gpu:0), stop_gradient=True,
[[1 , 2 , 3 , 4 ],
[0 , 0 , 0 , 0 ],
[10, 20, 30, 40],
[0 , 0 , 0 , 0 ],
[0 , 0 , 0 , 0 ],
[0 , 0 , 0 , 0 ],
[100, 200, 300, 400],
[0 , 0 , 0 , 0 ],
[0 , 0 , 0 , 0 ],
[0 , 0 , 0 , 0 ]])
"""
helper = LayerHelper('unzip', **locals())
out = helper.create_variable(dtype=input.dtype)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册