Skip to content

Conversation

@abhro
Copy link
Contributor

@abhro abhro commented Oct 21, 2025

Solves #968

src/moments.jl Outdated
function _moment2(v::AbstractArray{<:Real}, m::Real; corrected=false)
n = length(v)
s = 0.0
s = zero(m * m)
Copy link
Member

Choose a reason for hiding this comment

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

In general, s does not have the correct/desired type here as this initialization purely depends on m and neglects v.

Copy link
Contributor Author

@abhro abhro Oct 21, 2025

Choose a reason for hiding this comment

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

I was making the assumption that m and v would have compatible/identical types, since m is calculated from v and the function is only called internally. Would an implementation involving v be something like zero(v[begin] * v[begin])?

Copy link
Member

Choose a reason for hiding this comment

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

IMO we shouldn't make that assumption. For instance, in var(...; mean=...) users can easily provide a mean that is of different type.

Would an implementation involving v be something like zero(v[begin] * v[begin])

No, that would error if the array is empty and would neglect the type of m.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would the most recent commit (6a236d4) work for this?

Copy link
Member

Choose a reason for hiding this comment

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

No, not in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have to say, I'm confused where it would fail 😅

@abhro abhro marked this pull request as ready for review October 27, 2025 18:23
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

Successfully merging this pull request may close these issues.

2 participants