Skip to content

Commit 2e00bda

Browse files
committed
refactor: slice groups should use custom backpermite instead of converting unboxed vectors.
1 parent 4240449 commit 2e00bda

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/DataFrame/Internal/Column.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ atIndicesStable indexes (BoxedColumn column) =
380380
BoxedColumn $
381381
VB.generate
382382
(VU.length indexes)
383-
(\i -> column `VB.unsafeIndex` (indexes `VU.unsafeIndex` i))
383+
((column `VB.unsafeIndex`) . (indexes `VU.unsafeIndex`))
384384
atIndicesStable indexes (UnboxedColumn column) = UnboxedColumn $ VU.unsafeBackpermute column indexes
385385
atIndicesStable indexes (OptionalColumn column) =
386386
OptionalColumn $
387387
VB.generate
388388
(VU.length indexes)
389-
(\i -> column `VB.unsafeIndex` (indexes `VU.unsafeIndex` i))
389+
((column `VB.unsafeIndex`) . (indexes `VU.unsafeIndex`))
390390
{-# INLINE atIndicesStable #-}
391391

392392
{- | Like 'atIndicesStable' but treats negative indices as null,

src/DataFrame/Internal/Interpreter.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,21 @@ input — the sort happens once, not per-group.
213213
sliceGroups :: Column -> VU.Vector Int -> VU.Vector Int -> V.Vector Column
214214
sliceGroups col os indices = case col of
215215
BoxedColumn vec ->
216-
let !sorted = V.unsafeBackpermute vec (V.convert indices)
216+
let !sorted =
217+
V.generate
218+
(VU.length indices)
219+
((vec `V.unsafeIndex`) . (indices `VU.unsafeIndex`))
217220
in V.generate nGroups $ \i ->
218221
BoxedColumn (V.unsafeSlice (start i) (len i) sorted)
219222
UnboxedColumn vec ->
220223
let !sorted = VU.unsafeBackpermute vec indices
221224
in V.generate nGroups $ \i ->
222225
UnboxedColumn (VU.unsafeSlice (start i) (len i) sorted)
223226
OptionalColumn vec ->
224-
let !sorted = V.unsafeBackpermute vec (V.convert indices)
227+
let !sorted =
228+
V.generate
229+
(VU.length indices)
230+
((vec `V.unsafeIndex`) . (indices `VU.unsafeIndex`))
225231
in V.generate nGroups $ \i ->
226232
OptionalColumn (V.unsafeSlice (start i) (len i) sorted)
227233
where

0 commit comments

Comments
 (0)