-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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.1-No.5 #55804
Conversation
你的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.
@SigureMo 对于 image 这种,CI 环境里没有吧?跳过测试?
python/paddle/batch.py
Outdated
... print(data) | ||
... | ||
>>> # Output is | ||
>>> # [0, 1] | ||
>>> # [2, 3] | ||
>>> # [4, 5] | ||
>>> # [6, 7] | ||
>>> # [8, 9] |
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.
把 >>> # Output is
去掉,后面输出前面的 #
也去掉,这样xdoctest就可以比对输出的正确性了~
>>> for data in batch_reader():
... print(data)
[0, 1]
[2, 3]
[4, 5]
[6, 7]
[8, 9]
>>> with open('cat.jpg') as f: | ||
... im = load_image_bytes(f.read()) | ||
... |
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.
这个 cat.jpg
CI 环境中应该没有吧?如果 CI 这里出错了,可以用 # doctest: +SKIP
把这部分示例跳过~
>>> # doctest: +SKIP
>>> with open('cat.jpg') as f:
... im = load_image_bytes(f.read())
...
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 对于 image 这种,CI 环境里没有吧?跳过测试?
先不 skip 试试吧,如果没有的话之前也是过不了的,当时只能豁免,如果真的没有再 skip
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.
如果支持的话,还是建议加一下 reason
必须支持!不过,当时在写 convert_directive
的 regex pattern 的时候,写的太严了,导致不能兼容带有描述的 skip~
#55811 已修改~
@@ -148,7 +148,7 @@ def load_image(file, is_color=True): | |||
|
|||
.. code-block:: python | |||
|
|||
im = load_image('cat.jpg') | |||
>>> im = load_image('cat.jpg') |
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.
同上
>>> im = load_image('cat.jpg') | ||
>>> im = resize_short(im, 256) |
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.
同上
>>> im = load_image('cat.jpg') | ||
>>> im = resize_short(im, 256) | ||
>>> im = to_chw(im) |
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/fft.py
Outdated
>>> # Tensor(shape=[5], dtype=float32, place=Place(gpu:0), stop_gradient=True, | ||
>>> # [ 1.33333337, -1.33333337, -0.66666669, 0. , 0.66666669]) |
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/metric/metrics.py
Outdated
>>> correct = m.compute(x, y) | ||
>>> m.update(correct) | ||
>>> res = m.accumulate() | ||
>>> print(res) # 0.75 |
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/metric/metrics.py
Outdated
>>> m = paddle.metric.Precision() | ||
>>> m.update(x, y) | ||
>>> res = m.accumulate() | ||
>>> print(res) # 1.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.
缺少输出
python/paddle/metric/metrics.py
Outdated
>>> m = paddle.metric.Recall() | ||
>>> m.update(x, y) | ||
>>> res = m.accumulate() | ||
>>> print(res) # 2.0 / 3.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.
同上
python/paddle/metric/metrics.py
Outdated
>>> predictions = paddle.to_tensor([[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], dtype='float32') | ||
>>> label = paddle.to_tensor([[2], [0]], dtype="int64") | ||
>>> result = paddle.metric.accuracy(input=predictions, label=label, k=1) | ||
>>> # 0.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.
用 print
显性的输出结果~
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.
有一些应该是因为格式上对不上导致的错误,需要修正一下,有使用 convert-doctest 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.
对齐一下缩进吧~ 没用的空格删一下~
另外,
- im = center_crop(im, 224)
+ >>> im = center_crop(im, 224)
是不是应该先初始化一下
>>> im = load_image('cat.jpg')
>>> im = center_crop(im, 224)
python/paddle/fft.py
Outdated
>>> x = paddle.to_tensor([0.0, 1.0, 0.0, 0.0]) | ||
>>> print(paddle.fft.rfft(x)) | ||
Tensor(shape=[3], dtype=complex64, place=Place(cpu), stop_gradient=True, | ||
[ (1+0j), -1j , (-1+0j)]) |
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(shape=[3], dtype=complex64, place=Place(cpu), stop_gradient=True,
[ (1+0j), -1j , (-1+0j)])
python/paddle/fft.py
Outdated
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[0., 1., 0., 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.
同上,对齐一下缩进~
python/paddle/fft.py
Outdated
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[0., 0., 0., 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/fft.py
Outdated
Tensor(shape=[6], dtype=complex64, place=Place(cpu), stop_gradient=True, | ||
[(-0.1666666716337204+0j), (1-0j) , | ||
(2.3333334922790527-0j), (3.5+0j) , | ||
(2.3333334922790527+0j), (1+0j) ]) | ||
|
||
>>> print(paddle.fft.ihfft(spectrum)) | ||
Tensor(shape = [4], dtype = complex64, place = Place(cpu), stop_gradient = True, | ||
[(-0.1666666716337204+0j), (1-0j), | ||
(2.3333334922790527-0j), (3.5+0j)]) |
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(shape=[6], dtype=complex64, place=Place(cpu), stop_gradient=True,
[(-0.1666666716337204+0j), (1-0j),
(2.3333334922790527-0j), (3.5+0j),
(2.3333334922790527+0j), (1+0j)])
python/paddle/fft.py
Outdated
Tensor(shape=[4, 4, 4], dtype=complex128, place=Place(cpu), stop_gradient=True, | ||
[[[(24+0j), 0j , 0j , -0j ], | ||
[(-8+8j), 0j , 0j , -0j ], | ||
[(-8+0j), 0j , 0j , -0j ], | ||
[(-8-8j), 0j , 0j , -0j ]], | ||
[[(24+0j), 0j , 0j , -0j ], | ||
[(-8+8j), 0j , 0j , -0j ], | ||
[(-8+0j), 0j , 0j , -0j ], | ||
[(-8-8j), 0j , 0j , -0j ]], | ||
[[(24+0j), 0j , 0j , -0j ], | ||
[(-8+8j), 0j , 0j , -0j ], | ||
[(-8+0j), 0j , 0j , -0j ], | ||
[(-8-8j), 0j , 0j , -0j ]], | ||
[[(24+0j), 0j , 0j , -0j ], | ||
[(-8+8j), 0j , 0j , -0j ], | ||
[(-8+0j), 0j , 0j , -0j ], | ||
[(-8-8j), 0j , 0j , -0j ]]]) |
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/fft.py
Outdated
Tensor(shape=[2, 2], dtype=complex128, place=Place(cpu), stop_gradient=True, | ||
[[ (0.5+0j), 0j ], | ||
[(-0.5+0j), 0j ]]) |
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/fft.py
Outdated
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[[ 2.37500000, -1.12500000, 0.37500000, 0.87500000], | ||
[ 0.12500000, 0.12500000, 0.12500000, 0.12500000]]) |
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/fft.py
Outdated
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[[19., 7., 3., -9.], | ||
[ 1., 1., 1., 1.]]) |
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/fft.py
Outdated
Tensor(shape=[5, 5], dtype=float64, place=Place(cpu), stop_gradient=True, | ||
[[0., 0., 0., 0., 0.], | ||
[1., 1., 1., 1., 1.], | ||
[2., 2., 2., 2., 2.], | ||
[3., 3., 3., 3., 3.], | ||
[4., 4., 4., 4., 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/fft.py
Outdated
>>> fftfreq_xp = paddle.fft.fftfreq(5, d=scalar_temp) | ||
>>> print(fftfreq_xp) | ||
Tensor(shape=[5], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[ 0. , 0.40000001, 0.80000001, -0.80000001, -0.40000001]) |
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.
括号对齐一下会好看些
python/paddle/fft.py
Outdated
[[(24+0j), 0j, 0j, -0j], | ||
[(-8+8j), 0j, 0j, -0j], | ||
[(-8+0j), 0j, 0j, -0j], | ||
[(-8-8j), 0j, 0j, -0j]]]) |
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.
- [[[1, 2],
- [3, 4]]]
+ [[[1, 2],
+ [3, 4]]]
括号对齐一下吧
python/paddle/fft.py
Outdated
[0j, 0j, 0j]], | ||
[[0j, 0j, 0j], | ||
[0j, 0j, 0j], | ||
[0j, 0j, 0j]]]) |
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.
下面还有一些
好的,我修改下~ |
LGTM :) |
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 types
Others
PR changes
Others
Description
修改如下文件的示例代码为新的格式,并通过 xdoctest 检查:
@sunzhongkai588 @SigureMo @megemini