-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xdoctest] reformat example code with google style in No.6-No.10 #56146
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/reader/decorator.py
Outdated
>>> # All data is cached into memory | ||
>>> cached_reader = paddle.io.cache(reader) | ||
|
||
>>> # Output: 0 1 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经有输出了,就不需要注释了
python/paddle/reader/decorator.py
Outdated
>>> # Output: 0 1 2 | ||
>>> for i in cached_reader(): | ||
... print(i) | ||
0 1 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里输出是在一行的?
python/paddle/reader/decorator.py
Outdated
>>> def reader(): | ||
... for i in range(5): | ||
... yield i | ||
>>> shuffled_reader = fluid.io.shuffle(reader, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用 fluid API 了,用 paddle.reader.decorator.shuffle
吧
python/paddle/reader/decorator.py
Outdated
@@ -142,15 +143,16 @@ def shuffle(reader, buf_size): | |||
Examples: | |||
.. code-block:: python | |||
|
|||
import paddle.fluid as fluid | |||
>>> # doctest: +SKIP('outputs are 0~4 unordered arrangement') | |||
>>> import paddle.fluid as fluid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fluid 相关 import 也要删掉
python/paddle/reader/decorator.py
Outdated
... for i in range(10): | ||
... yield i | ||
... return reader | ||
>>> reader = fluid.io.compose(reader_creator_10(0), reader_creator_10(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是否也可以替换成非 fluid API(不一定需要是公开的)
python/paddle/reader/decorator.py
Outdated
>>> def reader(): | ||
... for i in range(100): | ||
... yield i | ||
>>> firstn_reader = fluid.io.firstn(reader, 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/reader/decorator.py
Outdated
>>> firstn_reader = fluid.io.firstn(reader, 5) | ||
>>> for e in firstn_reader(): | ||
... print(e) | ||
0 1 2 3 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/reader/decorator.py
Outdated
# [[[9 10]], [[11 12]]] | ||
# [13,14] will be dropped | ||
|
||
>>> import paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
528 和 529 中间需要空一行
python/paddle/signal.py
Outdated
|
||
np.allclose(x, x_) # True | ||
>>> np.allclose(x, x_) # True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后面注释可以删掉了
python/paddle/reader/decorator.py
Outdated
>>> import paddle.fluid as fluid | ||
>>> from paddle.fluid.io import multiprocess_reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考 @SigureMo 的~ 不要用fluid的api了~
padding=0, | ||
weight_attr=ParamAttr(regularizer=L2Decay(coeff=0.01)), | ||
bias_attr=False) | ||
>>> # Example2: set Regularizer in parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面空一行~
python/paddle/signal.py
Outdated
>>> y0 = frame(x, frame_length=4, hop_length=2, axis=-1) | ||
[[0, 2, 4], | ||
[1, 3, 5], | ||
[2, 4, 6], | ||
[3, 5, 7]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果要输出的话,最好 print ~ 另外,最好 frame -> signal.frame
>>> import paddle
>>> from paddle import signal
>>> # 1D
>>> x = paddle.arange(8)
>>> y0 = signal.frame(x, frame_length=4, hop_length=2, axis=-1)
>>> print(y0)
Tensor(shape=[4, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 2, 4],
[1, 3, 5],
[2, 4, 6],
[3, 5, 7]])
下同 ~
python/paddle/signal.py
Outdated
|
||
paddle.seed(0) | ||
>>> paddle.seed(0)convert-doctest --debug doctest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里语法错误了,导致测试跳过~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emmm,这个问题也得记一下,最好有办法检测这个
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有个临时生成的文件 sample_file_1 不要加进来 ~
最好不要用 git add .
python/paddle/reader/__init__.py
Outdated
>>> def reader_creator_random_image(width, height): | ||
... def reader(): | ||
... while True: | ||
... yield numpy.random.uniform(-1, 1, size=width*height) | ||
>>> return reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> def reader_creator_random_image(width, height):
... def reader():
... while True:
... yield numpy.random.uniform(-1, 1, size=width*height)
>>> return reader
应该在内部返回
>>> def reader_creator_random_image(width, height):
... def reader():
... while True:
... yield numpy.random.uniform(-1, 1, size=width*height)
... return reader
python/paddle/reader/__init__.py
Outdated
>>> def reader_creator_random_image_and_label(width, height, label): | ||
... def reader(): | ||
... while True: | ||
... yield numpy.random.uniform(-1, 1, size=width*height), label | ||
>>> return reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/reader/decorator.py
Outdated
@@ -524,59 +528,55 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000): | |||
Example: | |||
|
|||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: python
要相对 Examples:
有缩进 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/paddle/reader/decorator.py 下的 multiprocess_reader 里面的 .. code-block:: python 木有缩进 ~ 是我这边没更新?!?!
这里确实没解决呢 @longranger2
python/paddle/reader/decorator.py
Outdated
>>> def fake_input_files(): | ||
... with open(sample_files[0], 'w') as f: | ||
... np.savez(f, a=np.array([1, 2]), b=np.array([3, 4]), c=np.array([5, 6]), d=np.array([7, 8])) | ||
... with open(sample_files[1], 'w') as f: | ||
... np.savez(f, a=np.array([9, 10]), b=np.array([11, 12]), c=np.array([13, 14])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.savez 直接传文件名称的字符串,或者用 'wb' ~
python/paddle/regularizer.py
Outdated
>>> from paddle.regularizer import L2Decay | ||
|
||
>>> my_conv2d = Conv2D( | ||
... in_channels=10, | ||
... out_channels=10, | ||
... kernel_size=1, | ||
... stride=1, | ||
... padding=0, | ||
... weight_attr=ParamAttr(regularizer=L2Decay(coeff=0.01)), | ||
... bias_attr=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 L1Decay 吧 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 L1Decay 吧 ~
@megemini 这是为什么呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@megemini 标 WIP 的可以暂缓 review 吧,我看你 review 了一些 WIP 的 PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@megemini 标 WIP 的可以暂缓 review 吧,我看你 review 了一些 WIP 的 PR
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 L1Decay 吧 ~
@megemini 这是为什么呢?
这个是在 L1Decay 里面的示例啊 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 L1Decay 吧 ~
@megemini 这是为什么呢?
这个是在 L1Decay 里面的示例啊 ~
哦哦好的,现在才发现[捂脸]
python/paddle/signal.py
Outdated
@@ -51,58 +51,52 @@ def frame(x, frame_length, hop_length, axis=-1, name=None): | |||
|
|||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: python
与上面的 Examples:
要有缩进 ~
python/paddle/signal.py
Outdated
>>> # 1D | ||
>>> x = paddle.arange(8) | ||
>>> y0 = signal.frame(x, frame_length=4, hop_length=2, axis=-1) | ||
>>> print(y0) | ||
[[0, 2, 4], | ||
[1, 3, 5], | ||
[2, 4, 6], | ||
[3, 5, 7]] | ||
|
||
>>> y1 = signal.frame(x, frame_length=4, hop_length=2, axis=0) | ||
>>> print(y1) | ||
[[0, 1, 2, 3], | ||
[2, 3, 4, 5], | ||
[4, 5, 6, 7]] | ||
|
||
>>> # 2D | ||
>>> x0 = paddle.arange(16).reshape([2, 8]) | ||
>>> y0 = signal.frame(x0, frame_length=4, hop_length=2, axis=-1) | ||
>>> print(y0) | ||
[[[0, 2, 4], | ||
[1, 3, 5], | ||
[2, 4, 6], | ||
[3, 5, 7]], | ||
[[8 , 10, 12], | ||
[9 , 11, 13], | ||
[10, 12, 14], | ||
[11, 13, 15]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的输出应该是 Tensor 吧~
python/paddle/signal.py
Outdated
@@ -169,34 +163,44 @@ def overlap_add(x, hop_length, axis=-1, name=None): | |||
|
|||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: python 与上面的 Examples: 要有缩进 ~
python/paddle/signal.py
Outdated
>>> # 2D | ||
>>> x0 = paddle.arange(16).reshape([8, 2]) | ||
>>> print(x0) | ||
[[0 , 1 ], | ||
[2 , 3 ], | ||
[4 , 5 ], | ||
[6 , 7 ], | ||
[8 , 9 ], | ||
[10, 11], | ||
[12, 13], | ||
[14, 15]] | ||
|
||
>>> y0 = overlap_add(x0, hop_length=2, axis=-1) | ||
>>> print(y0) | ||
[0 , 2 , 5 , 9 , 13, 17, 21, 25, 13, 15] | ||
|
||
>>> x1 = paddle.arange(16).reshape([2, 8]) | ||
>>> print(x1) | ||
[[0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ], | ||
[8 , 9 , 10, 11, 12, 13, 14, 15]] | ||
|
||
>>> y1 = overlap_add(x1, hop_length=2, axis=0) | ||
>>> print(y1) | ||
[0 , 1 , 10, 12, 14, 16, 18, 20, 14, 15] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tensor
python/paddle/signal.py
Outdated
|
||
>>> x1 = paddle.arange(32).reshape([2, 8, 1, 2]) | ||
>>> y1 = overlap_add(x1, hop_length=2, axis=0) | ||
>>> print(y1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是输出的 y1.shape
Sorry to inform you that cca196f's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据群里讨论,无法替代的 fluid 改动暂时不改即可,这个 PR 可以修改推动一下了
sample_file_1
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是?
python/paddle/reader/__init__.py
Outdated
... def reader(): | ||
... while True: | ||
... yield numpy.random.uniform(-1, 1, size=width*height) | ||
>>> return reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该用 ...
而不是 >>>
~
虽然从代码测试的角度,用 >>>
也能过测,但是,return reader
实际上是 def reader_creator_random_image(width, height):
这个函数的一部分,而不是单独的一句,所以,用 ...
更合适。
python/paddle/reader/__init__.py
Outdated
... def reader(): | ||
... while True: | ||
... yield numpy.random.uniform(-1, 1, size=width*height), label | ||
>>> return reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ฅ LGTMeow ฅ
@megemini 确认一下?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/paddle/reader/decorator.py 下的 multiprocess_reader 里面的 .. code-block:: python 木有缩进 ~ 是我这边没更新?!?!
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ~ 辛苦!:)
需要解决下 PR-CI-Codestyle-Check 的问题 |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMeow 🐾
…dlePaddle#56146) * fix sample code * fix bug * fix bug * Update regularizer.py * Update __init__.py * Update decorator.py * fix code-style
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码为新的格式,并通过 xdoctest 检查:
@sunzhongkai588 @SigureMo @megemini