Skip to content

Commit

Permalink
Make movmean safe for non-one-indexed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Nov 12, 2022
1 parent 39798df commit 08ae8ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NaNStatistics"
uuid = "b946abbf-3ea7-4610-9019-9858bfdeaf2d"
authors = ["C. Brenhin Keller"]
version = "0.6.14"
version = "0.6.15"

[deps]
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Expand Down
18 changes: 9 additions & 9 deletions src/ArrayStats/ArrayStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@
m = Array{mean_type}(undef, size(x))
δ = ceil(Int, (n-1)/2)
@inbounds for i eachindex(x)
iₗ = max(i-δ, 1)
iᵤ = min(i+δ, length(x))
iₗ = max(i-δ, firstindex(x))
iᵤ = min(i+δ, lastindex(x))
m[i] = nanmean(view(x, iₗ:iᵤ))
end
return m
Expand All @@ -480,15 +480,15 @@
mean_type = Base.promote_op(/, eltype(x), Int64)
m = Array{mean_type}(undef, size(x))
δ = ceil(Int, (n-1)/2)
𝐼 = repeat(1:size(x,1), 1, size(x,2))
𝐽 = repeat((1:size(x,2))', size(x,1), 1)
@inbounds for k eachindex(x)
𝐼 = repeat((firstindex(x,1):lastindex(x,1)), 1, size(x,2))
𝐽 = repeat((firstindex(x,2):lastindex(x,2))', size(x,1), 1)
@inbounds for k eachindex(𝐼,𝐽)
i = 𝐼[k]
iₗ = max(i-δ, 1)
iᵤ = min(i+δ, size(x,1))
iₗ = max(i-δ, firstindex(x,1))
iᵤ = min(i+δ, lastindex(x,1))
j = 𝐽[k]
jₗ = max(j-δ, 1)
jᵤ = min(j+δ, size(x,2))
jₗ = max(j-δ, firstindex(x,2))
jᵤ = min(j+δ, lastindex(x,2))
m[i,j] = nanmean(view(x, iₗ:iᵤ, jₗ:jᵤ))
end
return m
Expand Down

2 comments on commit 08ae8ad

@brenhinkeller
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • Make movmean safe for non-one-indexed arrays

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/72086

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.15 -m "<description of version>" 08ae8ad48e4080af159ffa5f8622befc1023c27c
git push origin v0.6.15

Please sign in to comment.