Skip to content
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

Implementation of var(v::Range) is not type-stable #22773

Closed
oschulz opened this issue Jul 12, 2017 · 2 comments
Closed

Implementation of var(v::Range) is not type-stable #22773

oschulz opened this issue Jul 12, 2017 · 2 comments

Comments

@oschulz
Copy link
Contributor

oschulz commented Jul 12, 2017

Return type of, e.g., var(0f0:1f0:10f0) is Union{Float32, Float64}, due to conditional return of NaN in the implementation.

Example:

   @code_warntype var(0f0:1f0:10f0)q

var(v::Range{T}) should probably return real(momenttype(T)) in all cases, like var(A::AbstractArray{T}) does.

May also affect implementation of similar functions.

@stevengj
Copy link
Member

Looks like this line should be

l < 2 && return momenttype(eltype(v))(NaN)

(real is unnecessary since ranges can't be complex-valued.) Similarly for varm

@StefanKarpinski
Copy link
Sponsor Member

Might be a good use for return type annotation?

andreasnoack added a commit that referenced this issue Jul 17, 2017
andreasnoack added a commit that referenced this issue Jul 17, 2017
andreasnoack added a commit that referenced this issue Jul 17, 2017
jeffwong pushed a commit to jeffwong/julia that referenced this issue Jul 24, 2017
ararslan pushed a commit that referenced this issue Sep 11, 2017
Fixes #22773

Ref #22778
(cherry picked from commit e5ca368)
ararslan pushed a commit that referenced this issue Sep 13, 2017
Fixes #22773

(cherry picked from commit e5ca368)
vtjnash pushed a commit that referenced this issue Sep 14, 2017
Fixes #22773

(cherry picked from commit e5ca368)
ararslan pushed a commit that referenced this issue Sep 15, 2017
Fixes #22773

(cherry picked from commit e5ca368)
ararslan pushed a commit that referenced this issue Sep 16, 2017
Fixes #22773

(cherry picked from commit e5ca368)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants