Skip to content

Commit c32c468

Browse files
committed
feat: Specialize column functions.
1 parent 458734f commit c32c468

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/DataFrame/Internal/Column.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ mapColumn f = \case
280280
| Just Refl <- testEquality (typeRep @a) (typeRep @b) ->
281281
Right $ case sUnbox @c of
282282
STrue -> UnboxedColumn (VU.map f col)
283-
SFalse -> fromVector @c (VB.map f (VB.convert col))
283+
SFalse -> fromVector @c (VB.generate (VU.length col) (f . VU.unsafeIndex col))
284284
| otherwise ->
285285
Left $
286286
TypeMismatchException
@@ -291,6 +291,10 @@ mapColumn f = \case
291291
, errorColumnName = Nothing
292292
}
293293
)
294+
{-# SPECIALIZE mapColumn ::
295+
(Double -> Double) -> Column -> Either DataFrameException Column
296+
#-}
297+
{-# INLINEABLE mapColumn #-}
294298

295299
-- | O(1) Gets the number of elements in the column.
296300
columnLength :: Column -> Int
@@ -1347,7 +1351,7 @@ toUnboxedVector column =
13471351
( MkTypeErrorContext
13481352
{ userType = Right (typeRep @Int)
13491353
, expectedType = Right (typeRep @a)
1350-
, callingFunctionName = Just "toIntVector"
1354+
, callingFunctionName = Just "toUnboxedVector"
13511355
, errorColumnName = Nothing
13521356
}
13531357
)
@@ -1361,3 +1365,7 @@ toUnboxedVector column =
13611365
, errorColumnName = Nothing
13621366
}
13631367
)
1368+
{-# SPECIALIZE toUnboxedVector ::
1369+
Column -> Either DataFrameException (VU.Vector Double)
1370+
#-}
1371+
{-# INLINE toUnboxedVector #-}

src/DataFrame/Operations/Core.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,10 @@ columnAsUnboxedVector (Col name) df = case getColumn name df of
915915
columnAsUnboxedVector expr df = case interpret df expr of
916916
Left e -> throw e
917917
Right (TColumn col) -> toUnboxedVector col
918+
{-# SPECIALIZE columnAsUnboxedVector ::
919+
Expr Double -> DataFrame -> Either DataFrameException (VU.Vector Double)
920+
#-}
921+
{-# INLINE columnAsUnboxedVector #-}
918922

919923
{- | Get a specific column as a list.
920924

0 commit comments

Comments
 (0)