Skip to content

refactor: use abs() and inplace operation - #7191

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
Luk-ESC:patch-5
Oct 30, 2022
Merged

refactor: use abs() and inplace operation#7191
cclauss merged 1 commit into
TheAlgorithms:masterfrom
Luk-ESC:patch-5

Conversation

@Luk-ESC

@Luk-ESC Luk-ESC commented Oct 14, 2022

Copy link
Copy Markdown
Contributor

n = -n if n < 0 else n --> n = abs(n)
n = n // 10 --> n //= 10

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

n = -n if n < 0 else n --> n = abs(n)
n = n // 10 --> n //= 10
@Luk-ESC
Luk-ESC requested a review from Kush1101 as a code owner October 14, 2022 19:52
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 14, 2022
@algorithms-keeper algorithms-keeper Bot mentioned this pull request Oct 14, 2022
14 tasks
@cclauss

cclauss commented Oct 14, 2022

Copy link
Copy Markdown
Member

Did the timeit() benchmarks improve or not?

@dhruvmanila dhruvmanila left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These changes are fine, are there similar code elsewhere which can be refactored as well?

@cclauss

cclauss commented Oct 15, 2022

Copy link
Copy Markdown
Member

I would like to avoid this issue #7190 (comment). I think we are ok on this pr.

I still want to make sure that the timeit test show that the proposed solution is faster than the current one.

@dhruvmanila

Copy link
Copy Markdown
Member

I would like to avoid this issue #7190 (comment). I think we are ok on this pr.

I do understand where you're coming from, but this is not an optimization, rather a refactor.

I still want to make sure that the timeit test show that the proposed solution is faster than the current one.

There won't be any difference.

@dhruvmanila dhruvmanila changed the title shortened code using abs() and inplace ops refactor: use abs() and inplace operation Oct 15, 2022
@cclauss

cclauss commented Oct 15, 2022

Copy link
Copy Markdown
Member

There won't be any difference.

Prove it.

@CaedenPH CaedenPH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@cclauss Looks good

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Oct 30, 2022
@cclauss
cclauss merged commit cafbbab into TheAlgorithms:master Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants