Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-106498: Fix an extreme case incolorsys.rgb_to_hls#106530

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@gaogaotiantian
Copy link
Member

@gaogaotiantiangaogaotiantian commentedJul 7, 2023
edited by bedevere-bot
Loading

colorsys.rgb_to_hls(1, 1, 0.9999999999999999) raisesZeroDivisionError now (this probably is the ONLY case). Not sure if it's worth fixing, but I think "correct" in all cases is more important than "very slightly faster in theory".

This optimization is originally introduced in#23306, using the benchmark given in the PR, there's no observable performance regression with the extra check.

Benchmark Code
# /usr/bin/env pythonimporttimeitimportstatisticsfromLib.test.test_colorsysimportColorsysTestif__name__=='__main__':number=100repeat=100results=timeit.repeat('ColorsysTest().test_hls_roundtrip()',setup='from Lib.test.test_colorsys import ColorsysTest',number=number,repeat=repeat)running_times=list(sorted(results))mean=statistics.mean(running_times)std=statistics.stdev(running_times)print(f"Running time:{mean} ±{std} ms.  "f"(number, repeat) = ({number},{repeat})")

Another possible implementation is to do a try-except block for the division. Astry is almost no cost now, it would be theoretically faster than the current one. The return value would be different (a near white color can be represented in many forms in hls space). I prefer the current solution as it's easy to understand with the comment, but I do not oppose the other way.

@gaogaotiantian
Copy link
MemberAuthor

@terryjreedy as the reviewer of the related PR, could you share thoughts on this matter? Thanks!

Copy link

@nedvedernedveder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

minc == maxc andsumc == 2.0 are checking for the same thing - preventing division by zero. Another possible fix would be to check ifl==1 on line 91.

@terryjreedy
Copy link
Member

@gaogaotiantian Thank you for finding the change that caused the regression (which I merged, not just reviewed). As explained on this issue, the fix is incorrect. I am preparing a new PR with a different test addition.

@gaogaotiantiangaogaotiantian deleted the fix-colorsys-corner-case branchJune 5, 2024 17:23
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@nedvedernedvedernedveder approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@gaogaotiantian@terryjreedy@nedveder@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp