Closed piever closed 5 years ago
This passes tests now that the StructArrays version is tagged. Will merge in a couple of days if there are no objections.
EDIT: ~actually there is still a little bit of performance tuning to do before merging.~ performance fixed (now it's exactly the same iteration as before but the common part has been factored out and moved to StructArrays as it's needed there to compute sortperm
efficiently)
This uses the new
lazygroupmap
(bikeshedding on the name wanted) which is a low-level function to abstract the common mechanism in the grouping functionsgroupby
andgroupreduce
.lazygroupmap(f, keys, perm)
returns an iterator that appliesf
to(key, perm, idxs)
wherekey
is the key of the group (as a struct),perm
is the permutation andidxs
is the range inperm
that corresponds to the valuekey
. Bothgroupby
andgroupreduce
are special cases of this operation.lazygroupmap
(implemented in https://github.com/piever/StructArrays.jl/pull/57/files, so tests will fail until that is merged and tagged) also takes care of optimizing comparison (to computeidxs
only the refs of pooled data are compared) so it should have good performance.EDIT: renamed
lazygroupmap
tomaptiedindices
(tiedindices
is the iterator that iterates the key and range inperm
corresponding to that value, so I figuredmaptiedindices
is the natural name for this).