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

Preserve eltype where possible for moments #688

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/moments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ end
##### General central moment
function _moment2(v::RealArray, m::Real; corrected=false)
n = length(v)
T = promote_type(eltype(v), typeof(m))
s = zero(T)
s = zero(eltype(v)) - zero(m)
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
s += z * z
Expand All @@ -236,8 +235,7 @@ end

function _moment2(v::RealArray, wv::AbstractWeights, m::Real; corrected=false)
n = length(v)
T = promote_type(eltype(v), eltype(wv), typeof(m))
s = zero(T)
s = zero(eltype(wv)) * (zero(eltype(v)) - zero(m))^2
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
@inbounds s += (z * z) * wv[i]
Expand All @@ -248,8 +246,7 @@ end

function _moment3(v::RealArray, m::Real)
n = length(v)
T = promote_type(eltype(v), typeof(m))
s = zero(T)
s = zero(eltype(v)) - zero(m)
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
s += z * z * z
Expand All @@ -259,8 +256,7 @@ end

function _moment3(v::RealArray, wv::AbstractWeights, m::Real)
n = length(v)
T = promote_type(eltype(v), eltype(wv), typeof(m))
s = zero(T)
s = zero(eltype(wv)) * (zero(eltype(v)) - zero(m))^2
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
@inbounds s += (z * z * z) * wv[i]
Expand All @@ -270,8 +266,7 @@ end

function _moment4(v::RealArray, m::Real)
n = length(v)
T = promote_type(eltype(v), typeof(m))
s = zero(T)
s = zero(eltype(v)) - zero(m)
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
s += abs2(z * z)
Expand All @@ -281,8 +276,7 @@ end

function _moment4(v::RealArray, wv::AbstractWeights, m::Real)
n = length(v)
T = promote_type(eltype(v), eltype(wv), typeof(m))
s = zero(T)
s = zero(eltype(wv)) * (zero(eltype(v)) - zero(m))^2
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
@inbounds s += abs2(z * z) * wv[i]
Expand All @@ -292,8 +286,7 @@ end

function _momentk(v::RealArray, k::Int, m::Real)
n = length(v)
T = promote_type(eltype(v), typeof(m))
s = zero(T)
s = zero(eltype(v)) - zero(m)
for i = 1:n
@inbounds z = v[i] - m
s += (z ^ k)
Expand All @@ -303,8 +296,7 @@ end

function _momentk(v::RealArray, k::Int, wv::AbstractWeights, m::Real)
n = length(v)
T = promote_type(eltype(v), eltype(wv), typeof(m))
s = zero(T)
s = zero(eltype(wv)) * (zero(eltype(v)) - zero(m))^2
palday marked this conversation as resolved.
Show resolved Hide resolved
for i = 1:n
@inbounds z = v[i] - m
@inbounds s += (z ^ k) * wv[i]
Expand Down