Skip to content

Commit

Permalink
improve the efficiency of agg_time
Browse files Browse the repository at this point in the history
- 必须要有findall
  • Loading branch information
kongdd committed Sep 26, 2024
1 parent 73dc8cf commit f036253
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/agg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function agg!(R::AbstractArray{FT,3}, A::AbstractArray{<:Real,3};
end
progress && next!(p)
end
R
return R
end

function agg(A::AbstractArray{<:Real,3}; fact=2, parallel=true, fun=mean)
Expand All @@ -47,7 +47,7 @@ function agg_time(A::AbstractArray{T,3}; fact::Int=2, parallel=true, progress=fa
R[i, j, k] = fun(@view A[i, j, I])
end
end
R
return R
end


Expand All @@ -66,12 +66,13 @@ function agg_time(A::AbstractArray{T,3}, by::Vector; parallel=true, progress=fal
p = Progress(ntime)
@inbounds @par parallel for k = 1:_ntime
progress && next!(p)
I = grps[k] .== by
I = (grps[k] .== by) |> findall # 必须要有findall

for j = 1:nlat, i = 1:nlon
R[i, j, k] = fun(@view A[i, j, I])
end
end
R
return R
end

export agg!, agg, agg_time
4 changes: 2 additions & 2 deletions src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function apply(A::AbstractArray, dims_by=3, args...; dims=dims_by,
else
grps = unique(by) |> sort
res = par_map(grp -> begin
ind = by .== grp
ind = findall(by .== grp)
data = selectdim(A, dims_by, ind) # |> collect
# ans = fun(data, args...; kw...)
# ans = par_mapslices(fun2, data; dims, parallel, progress)
Expand All @@ -70,7 +70,7 @@ function apply(A::AbstractArray, dims_by=3, args...; dims=dims_by,
res = cat(res..., dims=along)
end
end
res
return res
end


Expand Down

0 comments on commit f036253

Please sign in to comment.