Skip to content

Speed up time calculations a tiny bit using faster test. - #8355

Merged
bsipocz merged 1 commit into
astropy:masterfrom
mhvk:time-small-speedup
Jan 25, 2019
Merged

bsipocz merged 1 commit into
astropy:masterfrom
mhvk:time-small-speedup

Conversation

@mhvk

@mhvk mhvk commented Jan 15, 2019 •

Copy link
Copy Markdown
Contributor

I was alerted to this by getting annoying deprecationwarnings arising from np.any(factor != 1) with factor a quantity. Really, the test should just short-cut only when one passes in exactly unity, and execute otherwise; inside time, the most frequent call is without a factor or divisor, so good to skip those as fast as possible.

EDIT: this relies on

In [16]: 1 is 1
Out[16]: True

This works for int, not float.

@MSeifert04

MSeifert04 commented Jan 16, 2019 •

Copy link
Copy Markdown
Contributor

Using is 1 really relies on CPython implementation details which I would avoid if possible. Why not just use None as default? It is a bit more ugly in the Signature but at least it is using well defined language features.

@mhvk
mhvk force-pushed the time-small-speedup branch from 1b6f706 to c6c074a Compare January 16, 2019 13:42
@codecov

codecov Bot commented Jan 16, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #8355 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8355      +/-   ##
==========================================
- Coverage   86.75%   86.74%   -0.01%     
==========================================
  Files         387      387              
  Lines       58108    58112       +4     
  Branches     1060     1060              
==========================================
+ Hits        50409    50412       +3     
- Misses       7084     7085       +1     
  Partials      615      615
Impacted Files Coverage Δ
astropy/time/utils.py 100% <100%> (ø) ⬆️
astropy/samp/hub.py 77.38% <0%> (-0.14%) ⬇️
astropy/units/function/core.py 99.14% <0%> (-0.01%) ⬇️
astropy/units/quantity.py 94.64% <0%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cce883a...6760ad4. Read the comment docs.

@mhvk
mhvk force-pushed the time-small-speedup branch from c6c074a to 94a4427 Compare January 16, 2019 13:44

@MSeifert04 MSeifert04 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.

LGTM

@pllim
pllim requested a review from taldcroft January 17, 2019 19:09
@pllim

pllim commented Jan 17, 2019

Copy link
Copy Markdown
Member

@taldcroft , do you want to have a look as a co-maintainer before merge? 😄

@bsipocz bsipocz modified the milestones: v3.2, 3.1.2 Jan 17, 2019
@mhvk
mhvk force-pushed the time-small-speedup branch from 94a4427 to 6760ad4 Compare January 23, 2019 14:26
@bsipocz

bsipocz commented Jan 25, 2019

Copy link
Copy Markdown
Member

While this has been only approved my non subpackage maintainers I'm going ahead a merge it to get it off the plate.

@bsipocz
bsipocz merged commit 87fd779 into astropy:master Jan 25, 2019
@bsipocz

bsipocz commented Jan 25, 2019

Copy link
Copy Markdown
Member

Thanks @mhvk!

@mhvk
mhvk deleted the time-small-speedup branch January 25, 2019 14:26
bsipocz added a commit that referenced this pull request Jan 30, 2019
Speed up time calculations a tiny bit using faster test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants