{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module DataFrame.Internal.Column where import qualified Data.Text as T import qualified Data.Vector as VB import qualified Data.Vector.Algorithms.Merge as VA import qualified Data.Vector.Generic as VG import qualified Data.Vector.Mutable as VBM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM import Control.DeepSeq (NFData (..), rnf) import Control.Exception (throw) import Control.Monad.ST (runST) import Data.Kind (Type) import Data.Maybe import Data.These import Data.Type.Equality (TestEquality (..)) import DataFrame.Errors import DataFrame.Internal.Parsing import DataFrame.Internal.Types import System.IO.Unsafe (unsafePerformIO) import Type.Reflection data Column where BoxedColumn :: (Columnable a) => VB.Vector a -> Column UnboxedColumn :: (Columnable a, VU.Unbox a) => VU.Vector a -> Column OptionalColumn :: (Columnable a) => VB.Vector (Maybe a) -> Column data MutableColumn where MBoxedColumn :: (Columnable a) => VBM.IOVector a -> MutableColumn MUnboxedColumn :: (Columnable a, VU.Unbox a) => VUM.IOVector a -> MutableColumn MOptionalColumn :: (Columnable a) => VBM.IOVector (Maybe a) -> MutableColumn data TypedColumn a where TColumn :: (Columnable a) => Column -> TypedColumn a instance (Eq a) => Eq (TypedColumn a) where (==) :: (Eq a) => TypedColumn a -> TypedColumn a -> Bool == :: Eq a => TypedColumn a -> TypedColumn a -> Bool (==) (TColumn Column a) (TColumn Column b) = Column a Column -> Column -> Bool forall a. Eq a => a -> a -> Bool == Column b instance (Ord a) => Ord (TypedColumn a) where compare :: (Ord a) => TypedColumn a -> TypedColumn a -> Ordering compare :: Ord a => TypedColumn a -> TypedColumn a -> Ordering compare (TColumn Column a) (TColumn Column b) = Column -> Column -> Ordering forall a. Ord a => a -> a -> Ordering compare Column a Column b unwrapTypedColumn :: TypedColumn a -> Column unwrapTypedColumn :: forall a. TypedColumn a -> Column unwrapTypedColumn (TColumn Column value) = Column value vectorFromTypedColumn :: TypedColumn a -> VB.Vector a vectorFromTypedColumn :: forall a. TypedColumn a -> Vector a vectorFromTypedColumn (TColumn Column value) = (DataFrameException -> Vector a) -> (Vector a -> Vector a) -> Either DataFrameException (Vector a) -> Vector a forall a c b. (a -> c) -> (b -> c) -> Either a b -> c either DataFrameException -> Vector a forall a e. Exception e => e -> a throw Vector a -> Vector a forall a. a -> a id (Column -> Either DataFrameException (Vector a) forall a (v :: * -> *). (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector Column value) hasMissing :: Column -> Bool hasMissing :: Column -> Bool hasMissing (OptionalColumn Vector (Maybe a) column) = Bool True hasMissing Column _ = Bool False allMissing :: Column -> Bool allMissing :: Column -> Bool allMissing (OptionalColumn Vector (Maybe a) column) = Vector (Maybe a) -> Int forall a. Vector a -> Int VB.length ((Maybe a -> Bool) -> Vector (Maybe a) -> Vector (Maybe a) forall a. (a -> Bool) -> Vector a -> Vector a VB.filter Maybe a -> Bool forall a. Maybe a -> Bool isNothing Vector (Maybe a) column) Int -> Int -> Bool forall a. Eq a => a -> a -> Bool == Vector (Maybe a) -> Int forall a. Vector a -> Int VB.length Vector (Maybe a) column allMissing Column _ = Bool False isNumeric :: Column -> Bool isNumeric :: Column -> Bool isNumeric (UnboxedColumn (Vector a vec :: VU.Vector a)) = case forall a. SBoolI (Numeric a) => SBool (Numeric a) sNumeric @a of SBool (Numeric a) STrue -> Bool True SBool (Numeric a) _ -> Bool False isNumeric (BoxedColumn (Vector a vec :: VB.Vector a)) = case TypeRep a -> TypeRep Integer -> Maybe (a :~: Integer) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Integer) of Maybe (a :~: Integer) Nothing -> Bool False Just a :~: Integer Refl -> Bool True isNumeric Column _ = Bool False hasElemType :: forall a. (Columnable a) => Column -> Bool hasElemType :: forall a. Columnable a => Column -> Bool hasElemType = \case BoxedColumn (Vector a column :: VB.Vector b) -> TypeRep a -> Bool forall b. TypeRep b -> Bool check (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) UnboxedColumn (Vector a column :: VU.Vector b) -> TypeRep a -> Bool forall b. TypeRep b -> Bool check (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) OptionalColumn (Vector (Maybe a) column :: VB.Vector b) -> TypeRep (Maybe a) -> Bool forall b. TypeRep b -> Bool check (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) where check :: forall (b :: Type). TypeRep b -> Bool check :: forall b. TypeRep b -> Bool check = Maybe (a :~: b) -> Bool forall a. Maybe a -> Bool isJust (Maybe (a :~: b) -> Bool) -> (TypeRep b -> Maybe (a :~: b)) -> TypeRep b -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) columnVersionString :: Column -> String columnVersionString :: Column -> String columnVersionString Column column = case Column column of BoxedColumn Vector a _ -> String "Boxed" UnboxedColumn Vector a _ -> String "Unboxed" OptionalColumn Vector (Maybe a) _ -> String "Optional" columnTypeString :: Column -> String columnTypeString :: Column -> String columnTypeString Column column = case Column column of BoxedColumn (Vector a column :: VB.Vector a) -> TypeRep a -> String forall a. Show a => a -> String show (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) UnboxedColumn (Vector a column :: VU.Vector a) -> TypeRep a -> String forall a. Show a => a -> String show (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) OptionalColumn (Vector (Maybe a) column :: VB.Vector a) -> TypeRep (Maybe a) -> String forall a. Show a => a -> String show (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) instance (Show a) => Show (TypedColumn a) where show :: (Show a) => TypedColumn a -> String show :: Show a => TypedColumn a -> String show (TColumn Column col) = Column -> String forall a. Show a => a -> String show Column col instance NFData Column where rnf :: Column -> () rnf (BoxedColumn (Vector a v :: VB.Vector a)) = Vector a -> () forall a. NFData a => a -> () rnf Vector a v rnf (UnboxedColumn Vector a v) = Vector a v Vector a -> () -> () forall a b. a -> b -> b `seq` () rnf (OptionalColumn (Vector (Maybe a) v :: VB.Vector (Maybe a))) = Vector (Maybe a) -> () forall a. NFData a => a -> () rnf Vector (Maybe a) v instance Show Column where show :: Column -> String show :: Column -> String show (BoxedColumn Vector a column) = Vector a -> String forall a. Show a => a -> String show Vector a column show (UnboxedColumn Vector a column) = Vector a -> String forall a. Show a => a -> String show Vector a column show (OptionalColumn Vector (Maybe a) column) = Vector (Maybe a) -> String forall a. Show a => a -> String show Vector (Maybe a) column instance Eq Column where (==) :: Column -> Column -> Bool == :: Column -> Column -> Bool (==) (BoxedColumn (Vector a a :: VB.Vector t1)) (BoxedColumn (Vector a b :: VB.Vector t2)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t1) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t2) of Maybe (a :~: a) Nothing -> Bool False Just a :~: a Refl -> Vector a a Vector a -> Vector a -> Bool forall a. Eq a => a -> a -> Bool == Vector a Vector a b (==) (OptionalColumn (Vector (Maybe a) a :: VB.Vector t1)) (OptionalColumn (Vector (Maybe a) b :: VB.Vector t2)) = case TypeRep (Maybe a) -> TypeRep (Maybe a) -> Maybe (Maybe a :~: Maybe a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t1) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t2) of Maybe (Maybe a :~: Maybe a) Nothing -> Bool False Just Maybe a :~: Maybe a Refl -> Vector (Maybe a) a Vector (Maybe a) -> Vector (Maybe a) -> Bool forall a. Eq a => a -> a -> Bool == Vector (Maybe a) Vector (Maybe a) b (==) (UnboxedColumn (Vector a a :: VU.Vector t1)) (UnboxedColumn (Vector a b :: VU.Vector t2)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t1) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @t2) of Maybe (a :~: a) Nothing -> Bool False Just a :~: a Refl -> Vector a a Vector a -> Vector a -> Bool forall a. Eq a => a -> a -> Bool == Vector a Vector a b (==) Column _ Column _ = Bool False generalLEQ :: forall a b. (Typeable a, Typeable b, Ord a, Ord b) => a -> b -> Bool generalLEQ :: forall a b. (Typeable a, Typeable b, Ord a, Ord b) => a -> b -> Bool generalLEQ a x b y = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Maybe (a :~: b) Nothing -> Bool False Just a :~: b Refl -> a x a -> a -> Bool forall a. Ord a => a -> a -> Bool <= a b y instance Ord Column where (<=) :: Column -> Column -> Bool <= :: Column -> Column -> Bool (<=) (BoxedColumn (Vector a a :: VB.Vector t1)) (BoxedColumn (Vector a b :: VB.Vector t2)) = Vector a -> Vector a -> Bool forall a b. (Typeable a, Typeable b, Ord a, Ord b) => a -> b -> Bool generalLEQ Vector a a Vector a b (<=) (OptionalColumn (Vector (Maybe a) a :: VB.Vector t1)) (OptionalColumn (Vector (Maybe a) b :: VB.Vector t2)) = Vector (Maybe a) -> Vector (Maybe a) -> Bool forall a b. (Typeable a, Typeable b, Ord a, Ord b) => a -> b -> Bool generalLEQ Vector (Maybe a) a Vector (Maybe a) b (<=) (UnboxedColumn (Vector a a :: VU.Vector t1)) (UnboxedColumn (Vector a b :: VU.Vector t2)) = Vector a -> Vector a -> Bool forall a b. (Typeable a, Typeable b, Ord a, Ord b) => a -> b -> Bool generalLEQ Vector a a Vector a b (<=) Column _ Column _ = Bool False class ColumnifyRep (r :: Rep) a where toColumnRep :: VB.Vector a -> Column type Columnable a = ( Columnable' a , ColumnifyRep (KindOf a) a , UnboxIf a , IntegralIf a , FloatingIf a , SBoolI (Unboxable a) , SBoolI (Numeric a) , SBoolI (IntegralTypes a) , SBoolI (FloatingTypes a) ) instance (Columnable a, VU.Unbox a) => ColumnifyRep 'RUnboxed a where toColumnRep :: (Columnable a, VUM.Unbox a) => VB.Vector a -> Column toColumnRep :: (Columnable a, Unbox a) => Vector a -> Column toColumnRep = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> (Vector a -> Vector a) -> Vector a -> Column forall b c a. (b -> c) -> (a -> b) -> a -> c . Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VU.convert instance (Columnable a) => ColumnifyRep 'RBoxed a where toColumnRep :: (Columnable a) => VB.Vector a -> Column toColumnRep :: Columnable a => Vector a -> Column toColumnRep = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn instance (Columnable a) => ColumnifyRep 'ROptional (Maybe a) where toColumnRep :: Vector (Maybe a) -> Column toColumnRep = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn fromVector :: forall a. (Columnable a, ColumnifyRep (KindOf a) a) => VB.Vector a -> Column fromVector :: forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector = forall (r :: Rep) a. ColumnifyRep r a => Vector a -> Column toColumnRep @(KindOf a) fromUnboxedVector :: forall a. (Columnable a, VU.Unbox a) => VU.Vector a -> Column fromUnboxedVector :: forall a. (Columnable a, Unbox a) => Vector a -> Column fromUnboxedVector = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn fromList :: forall a. (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column fromList :: forall a. (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column fromList = forall (r :: Rep) a. ColumnifyRep r a => Vector a -> Column toColumnRep @(KindOf a) (Vector a -> Column) -> ([a] -> Vector a) -> [a] -> Column forall b c a. (b -> c) -> (a -> b) -> a -> c . [a] -> Vector a forall a. [a] -> Vector a VB.fromList throwTypeMismatch :: forall (a :: Type) (b :: Type). (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch :: forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch = DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext b a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException MkTypeErrorContext { userType :: Either String (TypeRep b) userType = TypeRep b -> Either String (TypeRep b) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = Maybe String forall a. Maybe a Nothing , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } mapColumn :: forall b c. (Columnable b, Columnable c) => (b -> c) -> Column -> Either DataFrameException Column mapColumn :: forall b c. (Columnable b, Columnable c) => (b -> c) -> Column -> Either DataFrameException Column mapColumn b -> c f = \case BoxedColumn (Vector a col :: VB.Vector a) -> Vector a -> Either DataFrameException Column forall a. Typeable a => Vector a -> Either DataFrameException Column run Vector a col OptionalColumn (Vector (Maybe a) col :: VB.Vector (Maybe a)) -> Vector (Maybe a) -> Either DataFrameException Column forall a. Columnable a => Vector (Maybe a) -> Either DataFrameException Column runOpt Vector (Maybe a) col UnboxedColumn (Vector a col :: VU.Vector a) -> Vector a -> Either DataFrameException Column forall a. (Typeable a, Unbox a) => Vector a -> Either DataFrameException Column runUnboxed Vector a col where run :: forall a. (Typeable a) => VB.Vector a -> Either DataFrameException Column run :: forall a. Typeable a => Vector a -> Either DataFrameException Column run Vector a col = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @c ((b -> c) -> Vector b -> Vector c forall a b. (a -> b) -> Vector a -> Vector b VB.map b -> c f Vector b Vector a col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @a @b runOpt :: forall a. (Columnable a) => VB.Vector (Maybe a) -> Either DataFrameException Column runOpt :: forall a. Columnable a => Vector (Maybe a) -> Either DataFrameException Column runOpt Vector (Maybe a) col = case TypeRep (Maybe a) -> TypeRep b -> Maybe (Maybe a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @(Maybe a)) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just Maybe a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @c ((b -> c) -> Vector b -> Vector c forall a b. (a -> b) -> Vector a -> Vector b VB.map b -> c f Vector b Vector (Maybe a) col)) Maybe (Maybe a :~: b) Nothing -> case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (Vector (Maybe c) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn ((Maybe b -> Maybe c) -> Vector (Maybe b) -> Vector (Maybe c) forall a b. (a -> b) -> Vector a -> Vector b VB.map ((b -> c) -> Maybe b -> Maybe c forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap b -> c f) Vector (Maybe b) Vector (Maybe a) col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @(Maybe a) @b runUnboxed :: forall a. (Typeable a, VU.Unbox a) => VU.Vector a -> Either DataFrameException Column runUnboxed :: forall a. (Typeable a, Unbox a) => Vector a -> Either DataFrameException Column runUnboxed Vector a col = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ case forall a. SBoolI (Unboxable a) => SBool (Unboxable a) sUnbox @c of SBool (Unboxable c) STrue -> Vector c -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn ((b -> c) -> Vector b -> Vector c forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map b -> c f Vector b Vector a col) SBool (Unboxable c) SFalse -> forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @c (Int -> (Int -> c) -> Vector c forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector a -> Int forall a. Unbox a => Vector a -> Int VU.length Vector a col) (b -> c f (b -> c) -> (Int -> b) -> Int -> c forall b c a. (b -> c) -> (a -> b) -> a -> c . Vector b -> Int -> b forall a. Unbox a => Vector a -> Int -> a VU.unsafeIndex Vector b Vector a col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @a @b {-# INLINEABLE mapColumn #-} imapColumn :: forall b c. (Columnable b, Columnable c) => (Int -> b -> c) -> Column -> Either DataFrameException Column imapColumn :: forall b c. (Columnable b, Columnable c) => (Int -> b -> c) -> Column -> Either DataFrameException Column imapColumn Int -> b -> c f = \case BoxedColumn (Vector a col :: VB.Vector a) -> Vector a -> Either DataFrameException Column forall a. Typeable a => Vector a -> Either DataFrameException Column run Vector a col OptionalColumn (Vector (Maybe a) col :: VB.Vector (Maybe a)) -> Vector (Maybe a) -> Either DataFrameException Column forall a. Columnable a => Vector (Maybe a) -> Either DataFrameException Column runOpt Vector (Maybe a) col UnboxedColumn (Vector a col :: VU.Vector a) -> Vector a -> Either DataFrameException Column forall a. (Typeable a, Unbox a) => Vector a -> Either DataFrameException Column runUnboxed Vector a col where run :: forall a. (Typeable a) => VB.Vector a -> Either DataFrameException Column run :: forall a. Typeable a => Vector a -> Either DataFrameException Column run Vector a col = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @c ((Int -> b -> c) -> Vector b -> Vector c forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap Int -> b -> c f Vector b Vector a col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @a @b runOpt :: forall a. (Columnable a) => VB.Vector (Maybe a) -> Either DataFrameException Column runOpt :: forall a. Columnable a => Vector (Maybe a) -> Either DataFrameException Column runOpt Vector (Maybe a) col = case TypeRep (Maybe a) -> TypeRep b -> Maybe (Maybe a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @(Maybe a)) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just Maybe a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @c ((Int -> b -> c) -> Vector b -> Vector c forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap Int -> b -> c f Vector b Vector (Maybe a) col)) Maybe (Maybe a :~: b) Nothing -> case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (Vector (Maybe c) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn ((Int -> Maybe b -> Maybe c) -> Vector (Maybe b) -> Vector (Maybe c) forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap ((b -> c) -> Maybe b -> Maybe c forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((b -> c) -> Maybe b -> Maybe c) -> (Int -> b -> c) -> Int -> Maybe b -> Maybe c forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> b -> c f) Vector (Maybe b) Vector (Maybe a) col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @(Maybe a) @b runUnboxed :: forall a. (Typeable a, VU.Unbox a) => VU.Vector a -> Either DataFrameException Column runUnboxed :: forall a. (Typeable a, Unbox a) => Vector a -> Either DataFrameException Column runUnboxed Vector a col = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ case forall a. SBoolI (Unboxable a) => SBool (Unboxable a) sUnbox @c of SBool (Unboxable c) STrue -> Vector c -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn ((Int -> b -> c) -> Vector b -> Vector c forall a b. (Unbox a, Unbox b) => (Int -> a -> b) -> Vector a -> Vector b VU.imap Int -> b -> c f Vector b Vector a col) SBool (Unboxable c) SFalse -> Vector c -> Column forall a. Columnable a => Vector a -> Column BoxedColumn ((Int -> b -> c) -> Vector b -> Vector c forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap Int -> b -> c f (Vector b -> Vector b forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector b Vector a col)) Maybe (a :~: b) Nothing -> forall a b. (Typeable a, Typeable b) => Either DataFrameException Column throwTypeMismatch @a @b columnLength :: Column -> Int columnLength :: Column -> Int columnLength (BoxedColumn Vector a xs) = Vector a -> Int forall a. Vector a -> Int VB.length Vector a xs columnLength (UnboxedColumn Vector a xs) = Vector a -> Int forall a. Unbox a => Vector a -> Int VU.length Vector a xs columnLength (OptionalColumn Vector (Maybe a) xs) = Vector (Maybe a) -> Int forall a. Vector a -> Int VB.length Vector (Maybe a) xs {-# INLINE columnLength #-} numElements :: Column -> Int numElements :: Column -> Int numElements (BoxedColumn Vector a xs) = Vector a -> Int forall a. Vector a -> Int VB.length Vector a xs numElements (UnboxedColumn Vector a xs) = Vector a -> Int forall a. Unbox a => Vector a -> Int VU.length Vector a xs numElements (OptionalColumn Vector (Maybe a) xs) = (Int -> Maybe a -> Int) -> Int -> Vector (Maybe a) -> Int forall a b. (a -> b -> a) -> a -> Vector b -> a VB.foldl' (\Int acc Maybe a x -> Int acc Int -> Int -> Int forall a. Num a => a -> a -> a + Bool -> Int forall a. Enum a => a -> Int fromEnum (Maybe a -> Bool forall a. Maybe a -> Bool isJust Maybe a x)) Int 0 Vector (Maybe a) xs {-# INLINE numElements #-} takeColumn :: Int -> Column -> Column takeColumn :: Int -> Column -> Column takeColumn Int n (BoxedColumn Vector a xs) = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Int -> Vector a -> Vector a forall (v :: * -> *) a. Vector v a => Int -> v a -> v a VG.take Int n Vector a xs takeColumn Int n (UnboxedColumn Vector a xs) = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Int -> Vector a -> Vector a forall (v :: * -> *) a. Vector v a => Int -> v a -> v a VG.take Int n Vector a xs takeColumn Int n (OptionalColumn Vector (Maybe a) xs) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> Vector (Maybe a) -> Vector (Maybe a) forall (v :: * -> *) a. Vector v a => Int -> v a -> v a VG.take Int n Vector (Maybe a) xs {-# INLINE takeColumn #-} takeLastColumn :: Int -> Column -> Column takeLastColumn :: Int -> Column -> Column takeLastColumn Int n Column column = Int -> Int -> Column -> Column sliceColumn (Column -> Int columnLength Column column Int -> Int -> Int forall a. Num a => a -> a -> a - Int n) Int n Column column {-# INLINE takeLastColumn #-} sliceColumn :: Int -> Int -> Column -> Column sliceColumn :: Int -> Int -> Column -> Column sliceColumn Int start Int n (BoxedColumn Vector a xs) = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Int -> Int -> Vector a -> Vector a forall (v :: * -> *) a. (HasCallStack, Vector v a) => Int -> Int -> v a -> v a VG.slice Int start Int n Vector a xs sliceColumn Int start Int n (UnboxedColumn Vector a xs) = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Int -> Int -> Vector a -> Vector a forall (v :: * -> *) a. (HasCallStack, Vector v a) => Int -> Int -> v a -> v a VG.slice Int start Int n Vector a xs sliceColumn Int start Int n (OptionalColumn Vector (Maybe a) xs) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> Int -> Vector (Maybe a) -> Vector (Maybe a) forall (v :: * -> *) a. (HasCallStack, Vector v a) => Int -> Int -> v a -> v a VG.slice Int start Int n Vector (Maybe a) xs {-# INLINE sliceColumn #-} atIndicesStable :: VU.Vector Int -> Column -> Column atIndicesStable :: Vector Int -> Column -> Column atIndicesStable Vector Int indexes (BoxedColumn Vector a column) = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> a) -> Vector a forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int indexes) (\Int i -> Vector a column Vector a -> Int -> a forall a. Vector a -> Int -> a `VB.unsafeIndex` (Vector Int indexes Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int i)) atIndicesStable Vector Int indexes (UnboxedColumn Vector a column) = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Vector a -> Vector Int -> Vector a forall a. Unbox a => Vector a -> Vector Int -> Vector a VU.unsafeBackpermute Vector a column Vector Int indexes atIndicesStable Vector Int indexes (OptionalColumn Vector (Maybe a) column) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Maybe a) -> Vector (Maybe a) forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int indexes) (\Int i -> Vector (Maybe a) column Vector (Maybe a) -> Int -> Maybe a forall a. Vector a -> Int -> a `VB.unsafeIndex` (Vector Int indexes Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int i)) {-# INLINE atIndicesStable #-} gatherWithSentinel :: VU.Vector Int -> Column -> Column gatherWithSentinel :: Vector Int -> Column -> Column gatherWithSentinel Vector Int indices Column col = let !n :: Int n = Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int indices in case Column col of BoxedColumn Vector a v -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Maybe a) -> Vector (Maybe a) forall a. Int -> (Int -> a) -> Vector a VB.generate Int n ((Int -> Maybe a) -> Vector (Maybe a)) -> (Int -> Maybe a) -> Vector (Maybe a) forall a b. (a -> b) -> a -> b $ \Int i -> let !idx :: Int idx = Vector Int indices Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int i in if Int idx Int -> Int -> Bool forall a. Ord a => a -> a -> Bool < Int 0 then Maybe a forall a. Maybe a Nothing else a -> Maybe a forall a. a -> Maybe a Just (Vector a v Vector a -> Int -> a forall a. Vector a -> Int -> a `VB.unsafeIndex` Int idx) UnboxedColumn Vector a v -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Maybe a) -> Vector (Maybe a) forall a. Int -> (Int -> a) -> Vector a VB.generate Int n ((Int -> Maybe a) -> Vector (Maybe a)) -> (Int -> Maybe a) -> Vector (Maybe a) forall a b. (a -> b) -> a -> b $ \Int i -> let !idx :: Int idx = Vector Int indices Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int i in if Int idx Int -> Int -> Bool forall a. Ord a => a -> a -> Bool < Int 0 then Maybe a forall a. Maybe a Nothing else a -> Maybe a forall a. a -> Maybe a Just (Vector a v Vector a -> Int -> a forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int idx) OptionalColumn Vector (Maybe a) v -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Maybe a) -> Vector (Maybe a) forall a. Int -> (Int -> a) -> Vector a VB.generate Int n ((Int -> Maybe a) -> Vector (Maybe a)) -> (Int -> Maybe a) -> Vector (Maybe a) forall a b. (a -> b) -> a -> b $ \Int i -> let !idx :: Int idx = Vector Int indices Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a `VU.unsafeIndex` Int i in if Int idx Int -> Int -> Bool forall a. Ord a => a -> a -> Bool < Int 0 then Maybe a forall a. Maybe a Nothing else Vector (Maybe a) v Vector (Maybe a) -> Int -> Maybe a forall a. Vector a -> Int -> a `VB.unsafeIndex` Int idx {-# INLINE gatherWithSentinel #-} getIndices :: VU.Vector Int -> VB.Vector a -> VB.Vector a getIndices :: forall a. Vector Int -> Vector a -> Vector a getIndices Vector Int indices Vector a xs = Int -> (Int -> a) -> Vector a forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int indices) (\Int i -> Vector a xs Vector a -> Int -> a forall a. Vector a -> Int -> a VB.! (Vector Int indices Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.! Int i)) {-# INLINE getIndices #-} getIndicesUnboxed :: (VU.Unbox a) => VU.Vector Int -> VU.Vector a -> VU.Vector a getIndicesUnboxed :: forall a. Unbox a => Vector Int -> Vector a -> Vector a getIndicesUnboxed Vector Int indices Vector a xs = Int -> (Int -> a) -> Vector a forall a. Unbox a => Int -> (Int -> a) -> Vector a VU.generate (Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int indices) (\Int i -> Vector a xs Vector a -> Int -> a forall a. Unbox a => Vector a -> Int -> a VU.! (Vector Int indices Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.! Int i)) {-# INLINE getIndicesUnboxed #-} findIndices :: forall a. (Columnable a) => (a -> Bool) -> Column -> Either DataFrameException (VU.Vector Int) findIndices :: forall a. Columnable a => (a -> Bool) -> Column -> Either DataFrameException (Vector Int) findIndices a -> Bool pred = \case BoxedColumn (Vector a v :: VB.Vector b) -> Vector a -> (Vector Int -> Vector Int) -> Either DataFrameException (Vector Int) forall b (v :: * -> *). (Typeable b, Vector v b, Vector v Int) => v b -> (v Int -> Vector Int) -> Either DataFrameException (Vector Int) run Vector a v Vector Int -> Vector Int forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert OptionalColumn (Vector (Maybe a) v :: VB.Vector b) -> Vector (Maybe a) -> (Vector Int -> Vector Int) -> Either DataFrameException (Vector Int) forall b (v :: * -> *). (Typeable b, Vector v b, Vector v Int) => v b -> (v Int -> Vector Int) -> Either DataFrameException (Vector Int) run Vector (Maybe a) v Vector Int -> Vector Int forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert UnboxedColumn (Vector a v :: VU.Vector b) -> Vector a -> (Vector Int -> Vector Int) -> Either DataFrameException (Vector Int) forall b (v :: * -> *). (Typeable b, Vector v b, Vector v Int) => v b -> (v Int -> Vector Int) -> Either DataFrameException (Vector Int) run Vector a v Vector Int -> Vector Int forall a. a -> a id where run :: forall b v. (Typeable b, VG.Vector v b, VG.Vector v Int) => v b -> (v Int -> VU.Vector Int) -> Either DataFrameException (VU.Vector Int) run :: forall b (v :: * -> *). (Typeable b, Vector v b, Vector v Int) => v b -> (v Int -> Vector Int) -> Either DataFrameException (Vector Int) run v b column v Int -> Vector Int finalize = case TypeRep a -> TypeRep b -> Maybe (a :~: b) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: b Refl -> Vector Int -> Either DataFrameException (Vector Int) forall a b. b -> Either a b Right (Vector Int -> Either DataFrameException (Vector Int)) -> (v Int -> Vector Int) -> v Int -> Either DataFrameException (Vector Int) forall b c a. (b -> c) -> (a -> b) -> a -> c . v Int -> Vector Int finalize (v Int -> Either DataFrameException (Vector Int)) -> v Int -> Either DataFrameException (Vector Int) forall a b. (a -> b) -> a -> b $ (a -> Bool) -> v a -> v Int forall (v :: * -> *) a. (Vector v a, Vector v Int) => (a -> Bool) -> v a -> v Int VG.findIndices a -> Bool pred v a v b column Maybe (a :~: b) Nothing -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Int)) -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. (a -> b) -> a -> b $ TypeErrorContext a b -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep b) expectedType = TypeRep b -> Either String (TypeRep b) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "findIndices" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } sortedIndexes :: Bool -> Column -> VU.Vector Int sortedIndexes :: Bool -> Column -> Vector Int sortedIndexes Bool asc = \case BoxedColumn Vector a column -> (Vector Int -> Vector Int) -> Vector a -> Vector Int forall (v :: * -> *) a. (Vector v a, Ord a, Vector v (Int, a), Vector v Int) => (v Int -> Vector Int) -> v a -> Vector Int sortWorker Vector Int -> Vector Int forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a column UnboxedColumn Vector a column -> (Vector Int -> Vector Int) -> Vector a -> Vector Int forall (v :: * -> *) a. (Vector v a, Ord a, Vector v (Int, a), Vector v Int) => (v Int -> Vector Int) -> v a -> Vector Int sortWorker Vector Int -> Vector Int forall a. a -> a id Vector a column OptionalColumn Vector (Maybe a) column -> (Vector Int -> Vector Int) -> Vector (Maybe a) -> Vector Int forall (v :: * -> *) a. (Vector v a, Ord a, Vector v (Int, a), Vector v Int) => (v Int -> Vector Int) -> v a -> Vector Int sortWorker Vector Int -> Vector Int forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector (Maybe a) column where sortWorker :: (VG.Vector v a, Ord a, VG.Vector v (Int, a), VG.Vector v Int) => (v Int -> VU.Vector Int) -> v a -> VU.Vector Int sortWorker :: forall (v :: * -> *) a. (Vector v a, Ord a, Vector v (Int, a), Vector v Int) => (v Int -> Vector Int) -> v a -> Vector Int sortWorker v Int -> Vector Int finalize v a column = (forall s. ST s (Vector Int)) -> Vector Int forall a. (forall s. ST s a) -> a runST ((forall s. ST s (Vector Int)) -> Vector Int) -> (forall s. ST s (Vector Int)) -> Vector Int forall a b. (a -> b) -> a -> b $ do Mutable v s (Int, a) withIndexes <- v (Int, a) -> ST s (Mutable v (PrimState (ST s)) (Int, a)) forall (m :: * -> *) (v :: * -> *) a. (PrimMonad m, Vector v a) => v a -> m (Mutable v (PrimState m) a) VG.thaw (v (Int, a) -> ST s (Mutable v (PrimState (ST s)) (Int, a))) -> v (Int, a) -> ST s (Mutable v (PrimState (ST s)) (Int, a)) forall a b. (a -> b) -> a -> b $ v a -> v (Int, a) forall (v :: * -> *) a. (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) VG.indexed v a column let cmp :: a -> a -> Ordering cmp = if Bool asc then a -> a -> Ordering forall a. Ord a => a -> a -> Ordering compare else (a -> a -> Ordering) -> a -> a -> Ordering forall a b c. (a -> b -> c) -> b -> a -> c flip a -> a -> Ordering forall a. Ord a => a -> a -> Ordering compare Comparison (Int, a) -> Mutable v (PrimState (ST s)) (Int, a) -> ST s () forall (m :: * -> *) (v :: * -> * -> *) e. (PrimMonad m, MVector v e) => Comparison e -> v (PrimState m) e -> m () VA.sortBy (\(Int _, a b) (Int _, a b') -> a -> a -> Ordering cmp a b a b') Mutable v s (Int, a) Mutable v (PrimState (ST s)) (Int, a) withIndexes v (Int, a) sorted <- Mutable v (PrimState (ST s)) (Int, a) -> ST s (v (Int, a)) forall (m :: * -> *) (v :: * -> *) a. (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> m (v a) VG.unsafeFreeze Mutable v s (Int, a) Mutable v (PrimState (ST s)) (Int, a) withIndexes Vector Int -> ST s (Vector Int) forall a. a -> ST s a forall (m :: * -> *) a. Monad m => a -> m a return (Vector Int -> ST s (Vector Int)) -> Vector Int -> ST s (Vector Int) forall a b. (a -> b) -> a -> b $ v Int -> Vector Int finalize (v Int -> Vector Int) -> v Int -> Vector Int forall a b. (a -> b) -> a -> b $ ((Int, a) -> Int) -> v (Int, a) -> v Int forall (v :: * -> *) a b. (Vector v a, Vector v b) => (a -> b) -> v a -> v b VG.map (Int, a) -> Int forall a b. (a, b) -> a fst v (Int, a) sorted {-# INLINE sortedIndexes #-} ifoldrColumn :: forall a b. (Columnable a, Columnable b) => (Int -> a -> b -> b) -> b -> Column -> Either DataFrameException b ifoldrColumn :: forall a b. (Columnable a, Columnable b) => (Int -> a -> b -> b) -> b -> Column -> Either DataFrameException b ifoldrColumn Int -> a -> b -> b f b acc = \case BoxedColumn Vector a column -> Vector a -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldrWorker Vector a column UnboxedColumn Vector a column -> Vector a -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldrWorker Vector a column OptionalColumn Vector (Maybe a) column -> Vector (Maybe a) -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldrWorker Vector (Maybe a) column where foldrWorker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException b foldrWorker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldrWorker v c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> b -> Either DataFrameException b forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (b -> Either DataFrameException b) -> b -> Either DataFrameException b forall a b. (a -> b) -> a -> b $ (Int -> a -> b -> b) -> b -> v a -> b forall (v :: * -> *) a b. Vector v a => (Int -> a -> b -> b) -> b -> v a -> b VG.ifoldr Int -> a -> b -> b f b acc v a v c vec Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException b forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException b) -> DataFrameException -> Either DataFrameException b forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "ifoldrColumn" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) foldlColumn :: forall a b. (Columnable a, Columnable b) => (b -> a -> b) -> b -> Column -> Either DataFrameException b foldlColumn :: forall a b. (Columnable a, Columnable b) => (b -> a -> b) -> b -> Column -> Either DataFrameException b foldlColumn b -> a -> b f b acc = \case BoxedColumn Vector a column -> Vector a -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldlWorker Vector a column UnboxedColumn Vector a column -> Vector a -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldlWorker Vector a column OptionalColumn Vector (Maybe a) column -> Vector (Maybe a) -> Either DataFrameException b forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldlWorker Vector (Maybe a) column where foldlWorker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException b foldlWorker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException b foldlWorker v c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> b -> Either DataFrameException b forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (b -> Either DataFrameException b) -> b -> Either DataFrameException b forall a b. (a -> b) -> a -> b $ (b -> a -> b) -> b -> v a -> b forall (v :: * -> *) b a. Vector v b => (a -> b -> a) -> a -> v b -> a VG.foldl' b -> a -> b f b acc v a v c vec Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException b forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException b) -> DataFrameException -> Either DataFrameException b forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "ifoldrColumn" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) foldl1Column :: forall a. (Columnable a) => (a -> a -> a) -> Column -> Either DataFrameException a foldl1Column :: forall a. Columnable a => (a -> a -> a) -> Column -> Either DataFrameException a foldl1Column a -> a -> a f = \case BoxedColumn Vector a column -> Vector a -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a foldl1Worker Vector a column UnboxedColumn Vector a column -> Vector a -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a foldl1Worker Vector a column OptionalColumn Vector (Maybe a) column -> Vector (Maybe a) -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a foldl1Worker Vector (Maybe a) column where foldl1Worker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException a foldl1Worker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a foldl1Worker v c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> a -> Either DataFrameException a forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (a -> Either DataFrameException a) -> a -> Either DataFrameException a forall a b. (a -> b) -> a -> b $ (a -> a -> a) -> v a -> a forall (v :: * -> *) a. Vector v a => (a -> a -> a) -> v a -> a VG.foldl1' a -> a -> a f v a v c vec Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException a forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException a) -> DataFrameException -> Either DataFrameException a forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "foldl1Column" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) foldl1DirectGroups :: forall a. (Columnable a) => (a -> a -> a) -> Column -> VU.Vector Int -> VU.Vector Int -> Either DataFrameException Column foldl1DirectGroups :: forall a. Columnable a => (a -> a -> a) -> Column -> Vector Int -> Vector Int -> Either DataFrameException Column foldl1DirectGroups a -> a -> a f Column col Vector Int valueIndices Vector Int offsets | Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int offsets Int -> Int -> Bool forall a. Ord a => a -> a -> Bool <= Int 1 = Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @a Vector a forall a. Vector a VB.empty | Bool otherwise = case Column col of UnboxedColumn (Vector a vec :: VU.Vector d) -> Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Either DataFrameException (Vector a) -> Either DataFrameException Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Vector a -> Either DataFrameException (Vector a) forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException (v c) foldl1Worker Vector a vec BoxedColumn (Vector a vec :: VB.Vector d) -> Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Either DataFrameException (Vector a) -> Either DataFrameException Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Vector a -> Either DataFrameException (Vector a) forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException (v c) foldl1Worker Vector a vec OptionalColumn (Vector (Maybe a) vec :: VB.Vector (Maybe d)) -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Either DataFrameException (Vector (Maybe a)) -> Either DataFrameException Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Vector (Maybe a) -> Either DataFrameException (Vector (Maybe a)) forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException (v c) foldl1Worker Vector (Maybe a) vec where foldl1Worker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException (v c) foldl1Worker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException (v c) foldl1Worker v c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> v c -> Either DataFrameException (v c) forall a b. b -> Either a b Right (v c -> Either DataFrameException (v c)) -> v c -> Either DataFrameException (v c) forall a b. (a -> b) -> a -> b $ Int -> (Int -> c) -> v c forall (v :: * -> *) a. Vector v a => Int -> (Int -> a) -> v a VG.generate (Vector Int -> Int forall a. Unbox a => Vector a -> Int VU.length Vector Int offsets Int -> Int -> Int forall a. Num a => a -> a -> a - Int 1) Int -> a Int -> c foldGroup where foldGroup :: Int -> a foldGroup Int k = let !s :: Int s = Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.unsafeIndex Vector Int offsets Int k !e :: Int e = Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.unsafeIndex Vector Int offsets (Int k Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1) !seed :: c seed = v c -> Int -> c forall (v :: * -> *) a. Vector v a => v a -> Int -> a VG.unsafeIndex v c vec (Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.unsafeIndex Vector Int valueIndices Int s) in Int -> Int -> a -> a go (Int s Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1) Int e a c seed go :: Int -> Int -> a -> a go !Int i !Int e !a acc | Int i Int -> Int -> Bool forall a. Ord a => a -> a -> Bool >= Int e = a acc | Bool otherwise = Int -> Int -> a -> a go (Int i Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1) Int e (a -> a) -> a -> a forall a b. (a -> b) -> a -> b $! a -> a -> a f a acc (v a -> Int -> a forall (v :: * -> *) a. Vector v a => v a -> Int -> a VG.unsafeIndex v a v c vec (Vector Int -> Int -> Int forall a. Unbox a => Vector a -> Int -> a VU.unsafeIndex Vector Int valueIndices Int i)) Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException (v c) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (v c)) -> DataFrameException -> Either DataFrameException (v c) forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "foldl1DirectGroups" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } {-# INLINEABLE foldl1DirectGroups #-} foldLinearGroups :: forall b acc. (Columnable b, Columnable acc) => (acc -> b -> acc) -> acc -> Column -> VU.Vector Int -> Int -> Either DataFrameException Column foldLinearGroups :: forall b acc. (Columnable b, Columnable acc) => (acc -> b -> acc) -> acc -> Column -> Vector Int -> Int -> Either DataFrameException Column foldLinearGroups acc -> b -> acc f acc seed Column col Vector Int rowToGroup Int nGroups | Int nGroups Int -> Int -> Bool forall a. Eq a => a -> a -> Bool == Int 0 = Column -> Either DataFrameException Column forall a b. b -> Either a b Right (forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @acc Vector acc forall a. Vector a VB.empty) | Bool otherwise = case Column col of UnboxedColumn (Vector a vec :: VU.Vector d) -> Vector a -> Either DataFrameException Column forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException Column foldLinearWorker Vector a vec BoxedColumn (Vector a vec :: VB.Vector d) -> Vector a -> Either DataFrameException Column forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException Column foldLinearWorker Vector a vec OptionalColumn (Vector (Maybe a) vec :: VB.Vector (Maybe d)) -> Vector (Maybe a) -> Either DataFrameException Column forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException Column foldLinearWorker Vector (Maybe a) vec where foldLinearWorker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException Column foldLinearWorker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException Column foldLinearWorker v c vec = case TypeRep b -> TypeRep c -> Maybe (b :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just b :~: c Refl -> Column -> Either DataFrameException Column forall a b. b -> Either a b Right (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ IO Column -> Column forall a. IO a -> a unsafePerformIO (IO Column -> Column) -> IO Column -> Column forall a b. (a -> b) -> a -> b $ ((Int -> IO acc) -> (Int -> acc -> IO ()) -> IO ()) -> IO Column runWith ( \Int -> IO acc readAt Int -> acc -> IO () writeAt -> v c -> (Int -> c -> IO ()) -> IO () forall (m :: * -> *) (v :: * -> *) a b. (Monad m, Vector v a) => v a -> (Int -> a -> m b) -> m () VG.iforM_ v c vec ((Int -> c -> IO ()) -> IO ()) -> (Int -> c -> IO ()) -> IO () forall a b. (a -> b) -> a -> b $ \Int row c x -> do let !k :: Int k = Vector Int -> Int -> Int forall (v :: * -> *) a. Vector v a => v a -> Int -> a VG.unsafeIndex Vector Int rowToGroup Int row acc cur <- Int -> IO acc readAt Int k Int -> acc -> IO () writeAt Int k (acc -> IO ()) -> acc -> IO () forall a b. (a -> b) -> a -> b $! acc -> b -> acc f acc cur b c x ) Maybe (b :~: c) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext b c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException MkTypeErrorContext { userType :: Either String (TypeRep b) userType = TypeRep b -> Either String (TypeRep b) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "foldLinearGroups" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } runWith :: ((Int -> IO acc) -> (Int -> acc -> IO ()) -> IO ()) -> IO Column runWith :: ((Int -> IO acc) -> (Int -> acc -> IO ()) -> IO ()) -> IO Column runWith (Int -> IO acc) -> (Int -> acc -> IO ()) -> IO () body = case forall a. SBoolI (Unboxable a) => SBool (Unboxable a) sUnbox @acc of SBool (Unboxable acc) STrue -> do MVector RealWorld acc accs <- Int -> acc -> IO (MVector (PrimState IO) acc) forall (m :: * -> *) a. (PrimMonad m, Unbox a) => Int -> a -> m (MVector (PrimState m) a) VUM.replicate Int nGroups acc seed (Int -> IO acc) -> (Int -> acc -> IO ()) -> IO () body (MVector (PrimState IO) acc -> Int -> IO acc forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> m a VUM.unsafeRead MVector RealWorld acc MVector (PrimState IO) acc accs) (MVector (PrimState IO) acc -> Int -> acc -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite MVector RealWorld acc MVector (PrimState IO) acc accs) Vector acc -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector acc -> Column) -> IO (Vector acc) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) acc -> IO (Vector acc) forall a (m :: * -> *). (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) VU.unsafeFreeze MVector RealWorld acc MVector (PrimState IO) acc accs SBool (Unboxable acc) SFalse -> do MVector RealWorld acc accs <- Int -> acc -> IO (MVector (PrimState IO) acc) forall (m :: * -> *) a. PrimMonad m => Int -> a -> m (MVector (PrimState m) a) VBM.replicate Int nGroups acc seed (Int -> IO acc) -> (Int -> acc -> IO ()) -> IO () body (MVector (PrimState IO) acc -> Int -> IO acc forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> m a VBM.unsafeRead MVector RealWorld acc MVector (PrimState IO) acc accs) (MVector (PrimState IO) acc -> Int -> acc -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite MVector RealWorld acc MVector (PrimState IO) acc accs) forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector @acc (Vector acc -> Column) -> IO (Vector acc) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) acc -> IO (Vector acc) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze MVector RealWorld acc MVector (PrimState IO) acc accs {-# INLINE runWith #-} {-# INLINEABLE foldLinearGroups #-} headColumn :: forall a. (Columnable a) => Column -> Either DataFrameException a headColumn :: forall a. Columnable a => Column -> Either DataFrameException a headColumn = \case BoxedColumn Vector a col -> Vector a -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a headWorker Vector a col UnboxedColumn Vector a col -> Vector a -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a headWorker Vector a col OptionalColumn Vector (Maybe a) col -> Vector (Maybe a) -> Either DataFrameException a forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a headWorker Vector (Maybe a) col where headWorker :: forall c v. (Typeable c, VG.Vector v c) => v c -> Either DataFrameException a headWorker :: forall c (v :: * -> *). (Typeable c, Vector v c) => v c -> Either DataFrameException a headWorker v c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> if v c -> Bool forall (v :: * -> *) a. Vector v a => v a -> Bool VG.null v c vec then DataFrameException -> Either DataFrameException a forall a b. a -> Either a b Left (Text -> DataFrameException EmptyDataSetException Text "headColumn") else a -> Either DataFrameException a forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (v a -> a forall (v :: * -> *) a. Vector v a => v a -> a VG.head v a v c vec) Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException a forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException a) -> DataFrameException -> Either DataFrameException a forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "headColumn" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) zipColumns :: Column -> Column -> Column zipColumns :: Column -> Column -> Column zipColumns (BoxedColumn Vector a column) (BoxedColumn Vector a other) = Vector (a, a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Vector a -> Vector (a, a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip Vector a column Vector a other) zipColumns (BoxedColumn Vector a column) (UnboxedColumn Vector a other) = Vector (a, a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn ( Int -> (Int -> (a, a)) -> Vector (a, a) forall a. Int -> (Int -> a) -> Vector a VB.generate (Int -> Int -> Int forall a. Ord a => a -> a -> a min (Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a column) (Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a other)) (\Int i -> (Vector a column Vector a -> Int -> a forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i, Vector a other Vector a -> Int -> a forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i)) ) zipColumns (BoxedColumn Vector a column) (OptionalColumn Vector (Maybe a) optcolumn) = Vector (a, Maybe a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Vector (Maybe a) -> Vector (a, Maybe a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert Vector a column) Vector (Maybe a) optcolumn) zipColumns (UnboxedColumn Vector a column) (BoxedColumn Vector a other) = Vector (a, a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn ( Int -> (Int -> (a, a)) -> Vector (a, a) forall a. Int -> (Int -> a) -> Vector a VB.generate (Int -> Int -> Int forall a. Ord a => a -> a -> a min (Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a column) (Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a other)) (\Int i -> (Vector a column Vector a -> Int -> a forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i, Vector a other Vector a -> Int -> a forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i)) ) zipColumns (UnboxedColumn Vector a column) (UnboxedColumn Vector a other) = Vector (a, a) -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Vector a -> Vector (a, a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip Vector a column Vector a other) zipColumns (UnboxedColumn Vector a column) (OptionalColumn Vector (Maybe a) optcolumn) = Vector (a, Maybe a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Vector (Maybe a) -> Vector (a, Maybe a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert Vector a column) Vector (Maybe a) optcolumn) zipColumns (OptionalColumn Vector (Maybe a) optcolumn) (BoxedColumn Vector a column) = Vector (Maybe a, a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Maybe a) -> Vector a -> Vector (Maybe a, a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip Vector (Maybe a) optcolumn (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert Vector a column)) zipColumns (OptionalColumn Vector (Maybe a) optcolumn) (UnboxedColumn Vector a column) = Vector (Maybe a, a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Maybe a) -> Vector a -> Vector (Maybe a, a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip Vector (Maybe a) optcolumn (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert Vector a column)) zipColumns (OptionalColumn Vector (Maybe a) optcolumn) (OptionalColumn Vector (Maybe a) optother) = Vector (Maybe a, Maybe a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a, Maybe a) forall (v :: * -> *) a b. (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b) VG.zip Vector (Maybe a) optcolumn Vector (Maybe a) optother) {-# INLINE zipColumns #-} mergeColumns :: Column -> Column -> Column mergeColumns :: Column -> Column -> Column mergeColumns Column colA Column colB = case (Column colA, Column colB) of (OptionalColumn Vector (Maybe a) c1, OptionalColumn Vector (Maybe a) c2) -> Vector (Maybe (These a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (These a a)) -> Column) -> Vector (Maybe (These a a)) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) -> Vector (Maybe a) -> (Maybe a -> Maybe a -> Maybe (These a a)) -> Vector (Maybe (These a a)) forall {v :: * -> *} {t} {v :: * -> *} {t} {a}. (Vector v t, Vector v t) => v t -> v t -> (t -> t -> a) -> Vector a mkVec Vector (Maybe a) c1 Vector (Maybe a) c2 ((Maybe a -> Maybe a -> Maybe (These a a)) -> Vector (Maybe (These a a))) -> (Maybe a -> Maybe a -> Maybe (These a a)) -> Vector (Maybe (These a a)) forall a b. (a -> b) -> a -> b $ \Maybe a v1 Maybe a v2 -> case (Maybe a v1, Maybe a v2) of (Maybe a Nothing, Maybe a Nothing) -> Maybe (These a a) forall a. Maybe a Nothing (Just a x, Maybe a Nothing) -> These a a -> Maybe (These a a) forall a. a -> Maybe a Just (a -> These a a forall a b. a -> These a b This a x) (Maybe a Nothing, Just a y) -> These a a -> Maybe (These a a) forall a. a -> Maybe a Just (a -> These a a forall a b. b -> These a b That a y) (Just a x, Just a y) -> These a a -> Maybe (These a a) forall a. a -> Maybe a Just (a -> a -> These a a forall a b. a -> b -> These a b These a x a y) (OptionalColumn Vector (Maybe a) c1, BoxedColumn Vector a c2) -> Vector (Maybe a) -> Vector a -> Column forall {a} {b} {v :: * -> *} {v :: * -> *}. (Typeable a, Typeable b, Show a, Show b, Ord a, Ord b, Read a, Read b, NFData a, NFData b, Vector v (Maybe a), Vector v b) => v (Maybe a) -> v b -> Column optReq Vector (Maybe a) c1 Vector a c2 (OptionalColumn Vector (Maybe a) c1, UnboxedColumn Vector a c2) -> Vector (Maybe a) -> Vector a -> Column forall {a} {b} {v :: * -> *} {v :: * -> *}. (Typeable a, Typeable b, Show a, Show b, Ord a, Ord b, Read a, Read b, NFData a, NFData b, Vector v (Maybe a), Vector v b) => v (Maybe a) -> v b -> Column optReq Vector (Maybe a) c1 Vector a c2 (BoxedColumn Vector a c1, OptionalColumn Vector (Maybe a) c2) -> Vector a -> Vector (Maybe a) -> Column forall {a} {b} {v :: * -> *} {v :: * -> *}. (Typeable a, Typeable b, Show a, Show b, Ord a, Ord b, Read a, Read b, NFData a, NFData b, Vector v a, Vector v (Maybe b)) => v a -> v (Maybe b) -> Column reqOpt Vector a c1 Vector (Maybe a) c2 (UnboxedColumn Vector a c1, OptionalColumn Vector (Maybe a) c2) -> Vector a -> Vector (Maybe a) -> Column forall {a} {b} {v :: * -> *} {v :: * -> *}. (Typeable a, Typeable b, Show a, Show b, Ord a, Ord b, Read a, Read b, NFData a, NFData b, Vector v a, Vector v (Maybe b)) => v a -> v (Maybe b) -> Column reqOpt Vector a c1 Vector (Maybe a) c2 (BoxedColumn Vector a c1, BoxedColumn Vector a c2) -> Vector a -> Vector a -> Column forall {t} {t} {v :: * -> *} {v :: * -> *}. (Typeable t, Typeable t, Show t, Show t, Ord t, Ord t, Read t, Read t, NFData t, NFData t, Vector v t, Vector v t) => v t -> v t -> Column reqReq Vector a c1 Vector a c2 (BoxedColumn Vector a c1, UnboxedColumn Vector a c2) -> Vector a -> Vector a -> Column forall {t} {t} {v :: * -> *} {v :: * -> *}. (Typeable t, Typeable t, Show t, Show t, Ord t, Ord t, Read t, Read t, NFData t, NFData t, Vector v t, Vector v t) => v t -> v t -> Column reqReq Vector a c1 Vector a c2 (UnboxedColumn Vector a c1, BoxedColumn Vector a c2) -> Vector a -> Vector a -> Column forall {t} {t} {v :: * -> *} {v :: * -> *}. (Typeable t, Typeable t, Show t, Show t, Ord t, Ord t, Read t, Read t, NFData t, NFData t, Vector v t, Vector v t) => v t -> v t -> Column reqReq Vector a c1 Vector a c2 (UnboxedColumn Vector a c1, UnboxedColumn Vector a c2) -> Vector a -> Vector a -> Column forall {t} {t} {v :: * -> *} {v :: * -> *}. (Typeable t, Typeable t, Show t, Show t, Ord t, Ord t, Read t, Read t, NFData t, NFData t, Vector v t, Vector v t) => v t -> v t -> Column reqReq Vector a c1 Vector a c2 where mkVec :: v t -> v t -> (t -> t -> a) -> Vector a mkVec v t c1 v t c2 t -> t -> a combineElements = Int -> (Int -> a) -> Vector a forall a. Int -> (Int -> a) -> Vector a VB.generate (Int -> Int -> Int forall a. Ord a => a -> a -> a min (v t -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length v t c1) (v t -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length v t c2)) (\Int i -> t -> t -> a combineElements (v t c1 v t -> Int -> t forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i) (v t c2 v t -> Int -> t forall (v :: * -> *) a. (HasCallStack, Vector v a) => v a -> Int -> a VG.! Int i)) {-# INLINE mkVec #-} reqReq :: v t -> v t -> Column reqReq v t c1 v t c2 = Vector (These t t) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (These t t) -> Column) -> Vector (These t t) -> Column forall a b. (a -> b) -> a -> b $ v t -> v t -> (t -> t -> These t t) -> Vector (These t t) forall {v :: * -> *} {t} {v :: * -> *} {t} {a}. (Vector v t, Vector v t) => v t -> v t -> (t -> t -> a) -> Vector a mkVec v t c1 v t c2 t -> t -> These t t forall a b. a -> b -> These a b These reqOpt :: v a -> v (Maybe b) -> Column reqOpt v a c1 v (Maybe b) c2 = Vector (These a b) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (These a b) -> Column) -> Vector (These a b) -> Column forall a b. (a -> b) -> a -> b $ v a -> v (Maybe b) -> (a -> Maybe b -> These a b) -> Vector (These a b) forall {v :: * -> *} {t} {v :: * -> *} {t} {a}. (Vector v t, Vector v t) => v t -> v t -> (t -> t -> a) -> Vector a mkVec v a c1 v (Maybe b) c2 ((a -> Maybe b -> These a b) -> Vector (These a b)) -> (a -> Maybe b -> These a b) -> Vector (These a b) forall a b. (a -> b) -> a -> b $ \a v1 Maybe b v2 -> case Maybe b v2 of Maybe b Nothing -> a -> These a b forall a b. a -> These a b This a v1 Just b y -> a -> b -> These a b forall a b. a -> b -> These a b These a v1 b y optReq :: v (Maybe a) -> v b -> Column optReq v (Maybe a) c1 v b c2 = Vector (These a b) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (These a b) -> Column) -> Vector (These a b) -> Column forall a b. (a -> b) -> a -> b $ v (Maybe a) -> v b -> (Maybe a -> b -> These a b) -> Vector (These a b) forall {v :: * -> *} {t} {v :: * -> *} {t} {a}. (Vector v t, Vector v t) => v t -> v t -> (t -> t -> a) -> Vector a mkVec v (Maybe a) c1 v b c2 ((Maybe a -> b -> These a b) -> Vector (These a b)) -> (Maybe a -> b -> These a b) -> Vector (These a b) forall a b. (a -> b) -> a -> b $ \Maybe a v1 b v2 -> case Maybe a v1 of Maybe a Nothing -> b -> These a b forall a b. b -> These a b That b v2 Just a x -> a -> b -> These a b forall a b. a -> b -> These a b These a x b v2 {-# INLINE mergeColumns #-} zipWithColumns :: forall a b c. (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column zipWithColumns :: forall a b c. (Columnable a, Columnable b, Columnable c) => (a -> b -> c) -> Column -> Column -> Either DataFrameException Column zipWithColumns a -> b -> c f (UnboxedColumn (Vector a column :: VU.Vector d)) (UnboxedColumn (Vector a other :: VU.Vector e)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @d) of Just a :~: a Refl -> case TypeRep b -> TypeRep a -> Maybe (b :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @e) of Just b :~: a Refl -> Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ case forall a. SBoolI (Unboxable a) => SBool (Unboxable a) sUnbox @c of SBool (Unboxable c) STrue -> Vector c -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn ((a -> b -> c) -> Vector a -> Vector b -> Vector c forall a b c. (Unbox a, Unbox b, Unbox c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c VU.zipWith a -> b -> c f Vector a Vector a column Vector b Vector a other) SBool (Unboxable c) SFalse -> Vector c -> Column forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector (Vector c -> Column) -> Vector c -> Column forall a b. (a -> b) -> a -> b $ (a -> b -> c) -> Vector a -> Vector b -> Vector c forall a b c. (a -> b -> c) -> Vector a -> Vector b -> Vector c VB.zipWith a -> b -> c f (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a Vector a column) (Vector b -> Vector b forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector b Vector a other) Maybe (b :~: a) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext b a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep b) userType = TypeRep b -> Either String (TypeRep b) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @e) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "zipWithColumns" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) Maybe (a :~: a) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext a a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @d) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "zipWithColumns" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) zipWithColumns a -> b -> c f Column left Column right = case forall a (v :: * -> *). (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector @a Column left of Left (TypeMismatchException TypeErrorContext a b context) -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext a b -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException (TypeErrorContext a b context{callingFunctionName = Just "zipWithColumns"}) Left DataFrameException e -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left DataFrameException e Right Vector a left' -> case forall a (v :: * -> *). (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector @b Column right of Left (TypeMismatchException TypeErrorContext a b context) -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException Column) -> DataFrameException -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ TypeErrorContext a b -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException (TypeErrorContext a b context{callingFunctionName = Just "zipWithColumns"}) Left DataFrameException e -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left DataFrameException e Right Vector b right' -> Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Column -> Either DataFrameException Column) -> Column -> Either DataFrameException Column forall a b. (a -> b) -> a -> b $ Vector c -> Column forall a. (Columnable a, ColumnifyRep (KindOf a) a) => Vector a -> Column fromVector (Vector c -> Column) -> Vector c -> Column forall a b. (a -> b) -> a -> b $ (a -> b -> c) -> Vector a -> Vector b -> Vector c forall a b c. (a -> b -> c) -> Vector a -> Vector b -> Vector c VB.zipWith a -> b -> c f Vector a left' Vector b right' {-# INLINE zipWithColumns #-} writeColumn :: Int -> T.Text -> MutableColumn -> IO (Either T.Text Bool) writeColumn :: Int -> Text -> MutableColumn -> IO (Either Text Bool) writeColumn Int i Text value (MBoxedColumn (IOVector a col :: VBM.IOVector a)) = let in case TypeRep a -> TypeRep Text -> Maybe (a :~: Text) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @T.Text) of Just a :~: Text Refl -> ( if Text -> Bool isNullish Text value then MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a "" IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left (Text -> Either Text Bool) -> Text -> Either Text Bool forall a b. (a -> b) -> a -> b $! Text value) else MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a Text value IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Bool -> Either Text Bool forall a b. b -> Either a b Right Bool True) ) Maybe (a :~: Text) Nothing -> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left Text value) writeColumn Int i Text value (MOptionalColumn (IOVector (Maybe a) col :: VBM.IOVector (Maybe a))) = let in case TypeRep a -> TypeRep Text -> Maybe (a :~: Text) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @T.Text) of Just a :~: Text Refl -> ( if Text -> Bool isNullish Text value then MVector (PrimState IO) (Maybe a) -> Int -> Maybe a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector (Maybe a) MVector (PrimState IO) (Maybe a) col Int i Maybe a forall a. Maybe a Nothing IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left (Text -> Either Text Bool) -> Text -> Either Text Bool forall a b. (a -> b) -> a -> b $! Text value) else MVector (PrimState IO) (Maybe a) -> Int -> Maybe a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector (Maybe a) MVector (PrimState IO) (Maybe a) col Int i (a -> Maybe a forall a. a -> Maybe a Just a Text value) IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Bool -> Either Text Bool forall a b. b -> Either a b Right Bool True) ) Maybe (a :~: Text) Nothing -> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left Text value) writeColumn Int i Text value (MUnboxedColumn (IOVector a col :: VUM.IOVector a)) = case TypeRep a -> TypeRep Int -> Maybe (a :~: Int) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) of Just a :~: Int Refl -> case HasCallStack => Text -> Maybe Int Text -> Maybe Int readInt Text value of Just Int v -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a Int v IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Bool -> Either Text Bool forall a b. b -> Either a b Right Bool True) Maybe Int Nothing -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a 0 IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left Text value) Maybe (a :~: Int) Nothing -> case TypeRep a -> TypeRep Double -> Maybe (a :~: Double) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) of Maybe (a :~: Double) Nothing -> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left (Text -> Either Text Bool) -> Text -> Either Text Bool forall a b. (a -> b) -> a -> b $! Text value) Just a :~: Double Refl -> case HasCallStack => Text -> Maybe Double Text -> Maybe Double readDouble Text value of Just Double v -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a Double v IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Bool -> Either Text Bool forall a b. b -> Either a b Right Bool True) Maybe Double Nothing -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite IOVector a MVector (PrimState IO) a col Int i a 0 IO () -> IO (Either Text Bool) -> IO (Either Text Bool) forall a b. IO a -> IO b -> IO b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b >> Either Text Bool -> IO (Either Text Bool) forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Text -> Either Text Bool forall a b. a -> Either a b Left (Text -> Either Text Bool) -> Text -> Either Text Bool forall a b. (a -> b) -> a -> b $! Text value) {-# INLINE writeColumn #-} freezeColumn' :: [(Int, T.Text)] -> MutableColumn -> IO Column freezeColumn' :: [(Int, Text)] -> MutableColumn -> IO Column freezeColumn' [(Int, Text)] nulls (MOptionalColumn IOVector (Maybe a) col) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> IO (Vector (Maybe a)) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) (Maybe a) -> IO (Vector (Maybe a)) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector (Maybe a) MVector (PrimState IO) (Maybe a) col freezeColumn' [(Int, Text)] nulls (MBoxedColumn IOVector a col) | [(Int, Text)] -> Bool forall a. [a] -> Bool forall (t :: * -> *) a. Foldable t => t a -> Bool null [(Int, Text)] nulls = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector a MVector (PrimState IO) a col | ((Int, Text) -> Bool) -> [(Int, Text)] -> Bool forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool all (Text -> Bool isNullish (Text -> Bool) -> ((Int, Text) -> Text) -> (Int, Text) -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . (Int, Text) -> Text forall a b. (a, b) -> b snd) [(Int, Text)] nulls = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> (Vector a -> Vector (Maybe a)) -> Vector a -> Column forall b c a. (b -> c) -> (a -> b) -> a -> c . (Int -> a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap (\Int i a v -> if Int i Int -> [Int] -> Bool forall a. Eq a => a -> [a] -> Bool forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` ((Int, Text) -> Int) -> [(Int, Text)] -> [Int] forall a b. (a -> b) -> [a] -> [b] map (Int, Text) -> Int forall a b. (a, b) -> a fst [(Int, Text)] nulls then Maybe a forall a. Maybe a Nothing else a -> Maybe a forall a. a -> Maybe a Just a v) (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector a MVector (PrimState IO) a col | Bool otherwise = Vector (Either Text a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either Text a) -> Column) -> (Vector a -> Vector (Either Text a)) -> Vector a -> Column forall b c a. (b -> c) -> (a -> b) -> a -> c . (Int -> a -> Either Text a) -> Vector a -> Vector (Either Text a) forall a b. (Int -> a -> b) -> Vector a -> Vector b VB.imap ( \Int i a v -> if Int i Int -> [Int] -> Bool forall a. Eq a => a -> [a] -> Bool forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` ((Int, Text) -> Int) -> [(Int, Text)] -> [Int] forall a b. (a -> b) -> [a] -> [b] map (Int, Text) -> Int forall a b. (a, b) -> a fst [(Int, Text)] nulls then Text -> Either Text a forall a b. a -> Either a b Left (Text -> Maybe Text -> Text forall a. a -> Maybe a -> a fromMaybe (String -> Text forall a. HasCallStack => String -> a error String "UNEXPECTED ERROR DURING FREEZE") (Int -> [(Int, Text)] -> Maybe Text forall a b. Eq a => a -> [(a, b)] -> Maybe b lookup Int i [(Int, Text)] nulls)) else a -> Either Text a forall a b. b -> Either a b Right a v ) (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector a MVector (PrimState IO) a col freezeColumn' [(Int, Text)] nulls (MUnboxedColumn IOVector a col) | [(Int, Text)] -> Bool forall a. [a] -> Bool forall (t :: * -> *) a. Foldable t => t a -> Bool null [(Int, Text)] nulls = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall a (m :: * -> *). (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) VU.unsafeFreeze IOVector a MVector (PrimState IO) a col | ((Int, Text) -> Bool) -> [(Int, Text)] -> Bool forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool all (Text -> Bool isNullish (Text -> Bool) -> ((Int, Text) -> Text) -> (Int, Text) -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . (Int, Text) -> Text forall a b. (a, b) -> b snd) [(Int, Text)] nulls = MVector (PrimState IO) a -> IO (Vector a) forall a (m :: * -> *). (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) VU.unsafeFreeze IOVector a MVector (PrimState IO) a col IO (Vector a) -> (Vector a -> IO Column) -> IO Column forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= \Vector a c -> Column -> IO Column forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Column -> IO Column) -> Column -> IO Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Maybe a) -> Vector (Maybe a) forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector a -> Int forall a. Unbox a => Vector a -> Int VU.length Vector a c) (\Int i -> if Int i Int -> [Int] -> Bool forall a. Eq a => a -> [a] -> Bool forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` ((Int, Text) -> Int) -> [(Int, Text)] -> [Int] forall a b. (a -> b) -> [a] -> [b] map (Int, Text) -> Int forall a b. (a, b) -> a fst [(Int, Text)] nulls then Maybe a forall a. Maybe a Nothing else a -> Maybe a forall a. a -> Maybe a Just (Vector a c Vector a -> Int -> a forall a. Unbox a => Vector a -> Int -> a VU.! Int i)) | Bool otherwise = MVector (PrimState IO) a -> IO (Vector a) forall a (m :: * -> *). (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) VU.unsafeFreeze IOVector a MVector (PrimState IO) a col IO (Vector a) -> (Vector a -> IO Column) -> IO Column forall a b. IO a -> (a -> IO b) -> IO b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b >>= \Vector a c -> Column -> IO Column forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Column -> IO Column) -> Column -> IO Column forall a b. (a -> b) -> a -> b $ Vector (Either Text a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either Text a) -> Column) -> Vector (Either Text a) -> Column forall a b. (a -> b) -> a -> b $ Int -> (Int -> Either Text a) -> Vector (Either Text a) forall a. Int -> (Int -> a) -> Vector a VB.generate (Vector a -> Int forall a. Unbox a => Vector a -> Int VU.length Vector a c) ( \Int i -> if Int i Int -> [Int] -> Bool forall a. Eq a => a -> [a] -> Bool forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` ((Int, Text) -> Int) -> [(Int, Text)] -> [Int] forall a b. (a -> b) -> [a] -> [b] map (Int, Text) -> Int forall a b. (a, b) -> a fst [(Int, Text)] nulls then Text -> Either Text a forall a b. a -> Either a b Left (Text -> Maybe Text -> Text forall a. a -> Maybe a -> a fromMaybe (String -> Text forall a. HasCallStack => String -> a error String "UNEXPECTED ERROR DURING FREEZE") (Int -> [(Int, Text)] -> Maybe Text forall a b. Eq a => a -> [(a, b)] -> Maybe b lookup Int i [(Int, Text)] nulls)) else a -> Either Text a forall a b. b -> Either a b Right (Vector a c Vector a -> Int -> a forall a. Unbox a => Vector a -> Int -> a VU.! Int i) ) {-# INLINE freezeColumn' #-} expandColumn :: Int -> Column -> Column expandColumn :: Int -> Column -> Column expandColumn Int n (OptionalColumn Vector (Maybe a) col) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) col Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Int -> Maybe a -> Vector (Maybe a) forall a. Int -> a -> Vector a VB.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector (Maybe a) -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector (Maybe a) col) Maybe a forall a. Maybe a Nothing expandColumn Int n column :: Column column@(BoxedColumn Vector a col) | Int n Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b VB.map a -> Maybe a forall a. a -> Maybe a Just Vector a col Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Int -> Maybe a -> Vector (Maybe a) forall a. Int -> a -> Vector a VB.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col) Maybe a forall a. Maybe a Nothing | Bool otherwise = Column column expandColumn Int n column :: Column column@(UnboxedColumn Vector a col) | Int n Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b VB.map a -> Maybe a forall a. a -> Maybe a Just (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VU.convert Vector a col) Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Int -> Maybe a -> Vector (Maybe a) forall a. Int -> a -> Vector a VB.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col) Maybe a forall a. Maybe a Nothing | Bool otherwise = Column column leftExpandColumn :: Int -> Column -> Column leftExpandColumn :: Int -> Column -> Column leftExpandColumn Int n column :: Column column@(OptionalColumn Vector (Maybe a) col) | Int n Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Vector (Maybe a) -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector (Maybe a) col = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> Maybe a -> Vector (Maybe a) forall (v :: * -> *) a. Vector v a => Int -> a -> v a VG.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector (Maybe a) -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector (Maybe a) col) Maybe a forall a. Maybe a Nothing Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Vector (Maybe a) col | Bool otherwise = Column column leftExpandColumn Int n column :: Column column@(BoxedColumn Vector a col) | Int n Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> Maybe a -> Vector (Maybe a) forall (v :: * -> *) a. Vector v a => Int -> a -> v a VG.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col) Maybe a forall a. Maybe a Nothing Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall (v :: * -> *) a b. (Vector v a, Vector v b) => (a -> b) -> v a -> v b VG.map a -> Maybe a forall a. a -> Maybe a Just Vector a col | Bool otherwise = Column column leftExpandColumn Int n column :: Column column@(UnboxedColumn Vector a col) | Int n Int -> Int -> Bool forall a. Ord a => a -> a -> Bool > Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Int -> Maybe a -> Vector (Maybe a) forall (v :: * -> *) a. Vector v a => Int -> a -> v a VG.replicate (Int n Int -> Int -> Int forall a. Num a => a -> a -> a - Vector a -> Int forall (v :: * -> *) a. Vector v a => v a -> Int VG.length Vector a col) Maybe a forall a. Maybe a Nothing Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall (v :: * -> *) a b. (Vector v a, Vector v b) => (a -> b) -> v a -> v b VG.map a -> Maybe a forall a. a -> Maybe a Just (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VU.convert Vector a col) | Bool otherwise = Column column concatColumns :: Column -> Column -> Either DataFrameException Column concatColumns :: Column -> Column -> Either DataFrameException Column concatColumns Column left Column right = case (Column left, Column right) of (OptionalColumn Vector (Maybe a) l, OptionalColumn Vector (Maybe a) r) -> case TypeRep (Vector (Maybe a)) -> TypeRep (Vector (Maybe a)) -> Maybe (Vector (Maybe a) :~: Vector (Maybe a)) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) l) (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) r) of Just Vector (Maybe a) :~: Vector (Maybe a) Refl -> Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) l Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Vector (Maybe a) Vector (Maybe a) r) Maybe (Vector (Maybe a) :~: Vector (Maybe a)) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (TypeRep (Vector (Maybe a)) -> TypeRep (Vector (Maybe a)) -> DataFrameException forall x y. TypeRep x -> TypeRep y -> DataFrameException mismatchErr (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) r) (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) l)) (BoxedColumn Vector a l, BoxedColumn Vector a r) -> case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a l) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a r) of Just Vector a :~: Vector a Refl -> Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Vector a l Vector a -> Vector a -> Vector a forall a. Semigroup a => a -> a -> a <> Vector a Vector a r) Maybe (Vector a :~: Vector a) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (TypeRep (Vector a) -> TypeRep (Vector a) -> DataFrameException forall x y. TypeRep x -> TypeRep y -> DataFrameException mismatchErr (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a r) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a l)) (UnboxedColumn Vector a l, UnboxedColumn Vector a r) -> case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a l) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a r) of Just Vector a :~: Vector a Refl -> Column -> Either DataFrameException Column forall a. a -> Either DataFrameException a forall (f :: * -> *) a. Applicative f => a -> f a pure (Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Vector a l Vector a -> Vector a -> Vector a forall a. Semigroup a => a -> a -> a <> Vector a Vector a r) Maybe (Vector a :~: Vector a) Nothing -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (TypeRep (Vector a) -> TypeRep (Vector a) -> DataFrameException forall x y. TypeRep x -> TypeRep y -> DataFrameException mismatchErr (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a r) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a l)) (Column, Column) _ -> DataFrameException -> Either DataFrameException Column forall a b. a -> Either a b Left (TypeRep Column -> TypeRep Column -> DataFrameException forall x y. TypeRep x -> TypeRep y -> DataFrameException mismatchErr (Column -> TypeRep Column forall a. Typeable a => a -> TypeRep a typeOf Column right) (Column -> TypeRep Column forall a. Typeable a => a -> TypeRep a typeOf Column left)) where mismatchErr :: forall (x :: Type) (y :: Type). TypeRep x -> TypeRep y -> DataFrameException mismatchErr :: forall x y. TypeRep x -> TypeRep y -> DataFrameException mismatchErr TypeRep x ta TypeRep y tb = TypeRep x -> (Typeable x => DataFrameException) -> DataFrameException forall k (a :: k) r. TypeRep a -> (Typeable a => r) -> r withTypeable TypeRep x ta ((Typeable x => DataFrameException) -> DataFrameException) -> (Typeable x => DataFrameException) -> DataFrameException forall a b. (a -> b) -> a -> b $ TypeRep y -> (Typeable y => DataFrameException) -> DataFrameException forall k (a :: k) r. TypeRep a -> (Typeable a => r) -> r withTypeable TypeRep y tb ((Typeable y => DataFrameException) -> DataFrameException) -> (Typeable y => DataFrameException) -> DataFrameException forall a b. (a -> b) -> a -> b $ TypeErrorContext x y -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep x) userType = TypeRep x -> Either String (TypeRep x) forall a b. b -> Either a b Right TypeRep x ta , expectedType :: Either String (TypeRep y) expectedType = TypeRep y -> Either String (TypeRep y) forall a b. b -> Either a b Right TypeRep y tb , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "concatColumns" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) concatManyColumns :: [Column] -> Column concatManyColumns :: [Column] -> Column concatManyColumns [] = [Maybe Int] -> Column forall a. (Columnable a, ColumnifyRep (KindOf a) a) => [a] -> Column fromList ([] :: [Maybe Int]) concatManyColumns [Column c] = Column c concatManyColumns (Column c0 : [Column] cs) = case Column c0 of OptionalColumn Vector (Maybe a) v0 -> let getVec :: Column -> Vector (Maybe a) getVec (OptionalColumn Vector (Maybe a) v) = case TypeRep (Vector (Maybe a)) -> TypeRep (Vector (Maybe a)) -> Maybe (Vector (Maybe a) :~: Vector (Maybe a)) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) v0) (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) v) of Just Vector (Maybe a) :~: Vector (Maybe a) Refl -> Vector (Maybe a) Vector (Maybe a) v Maybe (Vector (Maybe a) :~: Vector (Maybe a)) Nothing -> String -> Vector (Maybe a) forall a. HasCallStack => String -> a error String "concatManyColumns: OptionalColumn type mismatch" getVec Column _ = String -> Vector (Maybe a) forall a. HasCallStack => String -> a error String "concatManyColumns: column constructor mismatch" in Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn ([Vector (Maybe a)] -> Vector (Maybe a) forall a. [Vector a] -> Vector a VB.concat (Vector (Maybe a) v0 Vector (Maybe a) -> [Vector (Maybe a)] -> [Vector (Maybe a)] forall a. a -> [a] -> [a] : (Column -> Vector (Maybe a)) -> [Column] -> [Vector (Maybe a)] forall a b. (a -> b) -> [a] -> [b] map Column -> Vector (Maybe a) getVec [Column] cs)) BoxedColumn Vector a v0 -> let getVec :: Column -> Vector a getVec (BoxedColumn Vector a v) = case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a v0) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a v) of Just Vector a :~: Vector a Refl -> Vector a Vector a v Maybe (Vector a :~: Vector a) Nothing -> String -> Vector a forall a. HasCallStack => String -> a error String "concatManyColumns: BoxedColumn type mismatch" getVec Column _ = String -> Vector a forall a. HasCallStack => String -> a error String "concatManyColumns: column constructor mismatch" in Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn ([Vector a] -> Vector a forall a. [Vector a] -> Vector a VB.concat (Vector a v0 Vector a -> [Vector a] -> [Vector a] forall a. a -> [a] -> [a] : (Column -> Vector a) -> [Column] -> [Vector a] forall a b. (a -> b) -> [a] -> [b] map Column -> Vector a getVec [Column] cs)) UnboxedColumn Vector a v0 -> let getVec :: Column -> Vector a getVec (UnboxedColumn Vector a v) = case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a v0) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a v) of Just Vector a :~: Vector a Refl -> Vector a Vector a v Maybe (Vector a :~: Vector a) Nothing -> String -> Vector a forall a. HasCallStack => String -> a error String "concatManyColumns: UnboxedColumn type mismatch" getVec Column _ = String -> Vector a forall a. HasCallStack => String -> a error String "concatManyColumns: column constructor mismatch" in Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn ([Vector a] -> Vector a forall a. Unbox a => [Vector a] -> Vector a VU.concat (Vector a v0 Vector a -> [Vector a] -> [Vector a] forall a. a -> [a] -> [a] : (Column -> Vector a) -> [Column] -> [Vector a] forall a b. (a -> b) -> [a] -> [b] map Column -> Vector a getVec [Column] cs)) concatColumnsEither :: Column -> Column -> Column concatColumnsEither :: Column -> Column -> Column concatColumnsEither (OptionalColumn Vector (Maybe a) left) (OptionalColumn Vector (Maybe a) right) = case TypeRep (Vector (Maybe a)) -> TypeRep (Vector (Maybe a)) -> Maybe (Vector (Maybe a) :~: Vector (Maybe a)) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) left) (Vector (Maybe a) -> TypeRep (Vector (Maybe a)) forall a. Typeable a => a -> TypeRep a typeOf Vector (Maybe a) right) of Maybe (Vector (Maybe a) :~: Vector (Maybe a)) Nothing -> Vector (Maybe (Either a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (Either a a)) -> Column) -> Vector (Maybe (Either a a)) -> Column forall a b. (a -> b) -> a -> b $ (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left) Vector (Maybe a) left Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) forall a. Semigroup a => a -> a -> a <> (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right) Vector (Maybe a) right Just Vector (Maybe a) :~: Vector (Maybe a) Refl -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) left Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Vector (Maybe a) Vector (Maybe a) right concatColumnsEither (BoxedColumn Vector a left) (BoxedColumn Vector a right) = case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a left) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a right) of Maybe (Vector a :~: Vector a) Nothing -> Vector (Either a a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either a a) -> Column) -> Vector (Either a a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left Vector a left Vector (Either a a) -> Vector (Either a a) -> Vector (Either a a) forall a. Semigroup a => a -> a -> a <> (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right Vector a right Just Vector a :~: Vector a Refl -> Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Vector a left Vector a -> Vector a -> Vector a forall a. Semigroup a => a -> a -> a <> Vector a Vector a right concatColumnsEither (UnboxedColumn Vector a left) (UnboxedColumn Vector a right) = case TypeRep (Vector a) -> TypeRep (Vector a) -> Maybe (Vector a :~: Vector a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a left) (Vector a -> TypeRep (Vector a) forall a. Typeable a => a -> TypeRep a typeOf Vector a right) of Maybe (Vector a :~: Vector a) Nothing -> Vector (Either a a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either a a) -> Column) -> Vector (Either a a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a left) Vector (Either a a) -> Vector (Either a a) -> Vector (Either a a) forall a. Semigroup a => a -> a -> a <> (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a right) Just Vector a :~: Vector a Refl -> Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> Vector a -> Column forall a b. (a -> b) -> a -> b $ Vector a left Vector a -> Vector a -> Vector a forall a. Semigroup a => a -> a -> a <> Vector a Vector a right concatColumnsEither (BoxedColumn Vector a left) (UnboxedColumn Vector a right) = Vector (Either a a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either a a) -> Column) -> Vector (Either a a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left Vector a left Vector (Either a a) -> Vector (Either a a) -> Vector (Either a a) forall a. Semigroup a => a -> a -> a <> (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a right) concatColumnsEither (UnboxedColumn Vector a left) (BoxedColumn Vector a right) = Vector (Either a a) -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector (Either a a) -> Column) -> Vector (Either a a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a left) Vector (Either a a) -> Vector (Either a a) -> Vector (Either a a) forall a. Semigroup a => a -> a -> a <> (a -> Either a a) -> Vector a -> Vector (Either a a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right Vector a right concatColumnsEither (OptionalColumn (Vector (Maybe a) left :: VB.Vector (Maybe a))) (BoxedColumn (Vector a right :: VB.Vector b)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) left Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Maybe a forall a. a -> Maybe a Just Vector a Vector a right Maybe (a :~: a) Nothing -> Vector (Maybe (Either a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (Either a a)) -> Column) -> Vector (Maybe (Either a a)) -> Column forall a b. (a -> b) -> a -> b $ (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left) Vector (Maybe a) left Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) forall a. Semigroup a => a -> a -> a <> (a -> Maybe (Either a a)) -> Vector a -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (Either a a -> Maybe (Either a a) forall a. a -> Maybe a Just (Either a a -> Maybe (Either a a)) -> (a -> Either a a) -> a -> Maybe (Either a a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> Either a a forall a b. b -> Either a b Right) Vector a right concatColumnsEither (BoxedColumn (Vector a left :: VB.Vector a)) (OptionalColumn (Vector (Maybe a) right :: VB.Vector (Maybe b))) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Maybe a forall a. a -> Maybe a Just Vector a left Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Vector (Maybe a) Vector (Maybe a) right Maybe (a :~: a) Nothing -> Vector (Maybe (Either a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (Either a a)) -> Column) -> Vector (Maybe (Either a a)) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe (Either a a)) -> Vector a -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (Either a a -> Maybe (Either a a) forall a. a -> Maybe a Just (Either a a -> Maybe (Either a a)) -> (a -> Either a a) -> a -> Maybe (Either a a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> Either a a forall a b. a -> Either a b Left) Vector a left Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) forall a. Semigroup a => a -> a -> a <> (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right) Vector (Maybe a) right concatColumnsEither (OptionalColumn (Vector (Maybe a) left :: VB.Vector (Maybe a))) (UnboxedColumn (Vector a right :: VU.Vector b)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ Vector (Maybe a) left Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Maybe a forall a. a -> Maybe a Just (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a Vector a right) Maybe (a :~: a) Nothing -> Vector (Maybe (Either a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (Either a a)) -> Column) -> Vector (Maybe (Either a a)) -> Column forall a b. (a -> b) -> a -> b $ (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. a -> Either a b Left) Vector (Maybe a) left Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) forall a. Semigroup a => a -> a -> a <> (a -> Maybe (Either a a)) -> Vector a -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (Either a a -> Maybe (Either a a) forall a. a -> Maybe a Just (Either a a -> Maybe (Either a a)) -> (a -> Either a a) -> a -> Maybe (Either a a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> Either a a forall a b. b -> Either a b Right) (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a right) concatColumnsEither (UnboxedColumn (Vector a left :: VU.Vector a)) (OptionalColumn (Vector (Maybe a) right :: VB.Vector (Maybe b))) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> Vector (Maybe a) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe a) -> Vector a -> Vector (Maybe a) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Maybe a forall a. a -> Maybe a Just (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a left) Vector (Maybe a) -> Vector (Maybe a) -> Vector (Maybe a) forall a. Semigroup a => a -> a -> a <> Vector (Maybe a) Vector (Maybe a) right Maybe (a :~: a) Nothing -> Vector (Maybe (Either a a)) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe (Either a a)) -> Column) -> Vector (Maybe (Either a a)) -> Column forall a b. (a -> b) -> a -> b $ (a -> Maybe (Either a a)) -> Vector a -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (Either a a -> Maybe (Either a a) forall a. a -> Maybe a Just (Either a a -> Maybe (Either a a)) -> (a -> Either a a) -> a -> Maybe (Either a a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> Either a a forall a b. a -> Either a b Left) (Vector a -> Vector a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert Vector a left) Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) -> Vector (Maybe (Either a a)) forall a. Semigroup a => a -> a -> a <> (Maybe a -> Maybe (Either a a)) -> Vector (Maybe a) -> Vector (Maybe (Either a a)) forall a b. (a -> b) -> Vector a -> Vector b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap ((a -> Either a a) -> Maybe a -> Maybe (Either a a) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> Either a a forall a b. b -> Either a b Right) Vector (Maybe a) right newMutableColumn :: Int -> Column -> IO MutableColumn newMutableColumn :: Int -> Column -> IO MutableColumn newMutableColumn Int n (OptionalColumn (Vector (Maybe a) _ :: VB.Vector (Maybe a))) = IOVector (Maybe a) -> MutableColumn forall a. Columnable a => IOVector (Maybe a) -> MutableColumn MOptionalColumn (IOVector (Maybe a) -> MutableColumn) -> IO (IOVector (Maybe a)) -> IO MutableColumn forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> IO (MVector (PrimState IO) (Maybe a)) forall (m :: * -> *) a. PrimMonad m => Int -> m (MVector (PrimState m) a) VBM.new Int n :: IO (VBM.IOVector (Maybe a))) newMutableColumn Int n (BoxedColumn (Vector a _ :: VB.Vector a)) = IOVector a -> MutableColumn forall a. Columnable a => IOVector a -> MutableColumn MBoxedColumn (IOVector a -> MutableColumn) -> IO (IOVector a) -> IO MutableColumn forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> IO (MVector (PrimState IO) a) forall (m :: * -> *) a. PrimMonad m => Int -> m (MVector (PrimState m) a) VBM.new Int n :: IO (VBM.IOVector a)) newMutableColumn Int n (UnboxedColumn (Vector a _ :: VU.Vector a)) = IOVector a -> MutableColumn forall a. (Columnable a, Unbox a) => IOVector a -> MutableColumn MUnboxedColumn (IOVector a -> MutableColumn) -> IO (IOVector a) -> IO MutableColumn forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> IO (MVector (PrimState IO) a) forall (m :: * -> *) a. (PrimMonad m, Unbox a) => Int -> m (MVector (PrimState m) a) VUM.new Int n :: IO (VUM.IOVector a)) copyIntoMutableColumn :: MutableColumn -> Int -> Column -> IO () copyIntoMutableColumn :: MutableColumn -> Int -> Column -> IO () copyIntoMutableColumn (MOptionalColumn (IOVector (Maybe a) mv :: VBM.IOVector (Maybe b))) Int off (OptionalColumn (Vector (Maybe a) v :: VB.Vector (Maybe a))) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> (Int -> Maybe a -> IO ()) -> Vector (Maybe a) -> IO () forall (m :: * -> *) (v :: * -> *) a b. (Monad m, Vector v a) => (Int -> a -> m b) -> v a -> m () VG.imapM_ (\Int i Maybe a x -> MVector (PrimState IO) (Maybe a) -> Int -> Maybe a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector (Maybe a) MVector (PrimState IO) (Maybe a) mv (Int off Int -> Int -> Int forall a. Num a => a -> a -> a + Int i) Maybe a x) Vector (Maybe a) Vector (Maybe a) v Maybe (a :~: a) Nothing -> String -> IO () forall a. HasCallStack => String -> a error String "copyIntoMutableColumn: Optional type mismatch" copyIntoMutableColumn (MBoxedColumn (IOVector a mv :: VBM.IOVector b)) Int off (BoxedColumn (Vector a v :: VB.Vector a)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> (Int -> a -> IO ()) -> Vector a -> IO () forall (m :: * -> *) (v :: * -> *) a b. (Monad m, Vector v a) => (Int -> a -> m b) -> v a -> m () VG.imapM_ (\Int i a x -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () VBM.unsafeWrite IOVector a MVector (PrimState IO) a mv (Int off Int -> Int -> Int forall a. Num a => a -> a -> a + Int i) a x) Vector a Vector a v Maybe (a :~: a) Nothing -> String -> IO () forall a. HasCallStack => String -> a error String "copyIntoMutableColumn: Boxed type mismatch" copyIntoMutableColumn (MUnboxedColumn (IOVector a mv :: VUM.IOVector b)) Int off (UnboxedColumn (Vector a v :: VU.Vector a)) = case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> (Int -> a -> IO ()) -> Vector a -> IO () forall (m :: * -> *) (v :: * -> *) a b. (Monad m, Vector v a) => (Int -> a -> m b) -> v a -> m () VG.imapM_ (\Int i a x -> MVector (PrimState IO) a -> Int -> a -> IO () forall (m :: * -> *) a. (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m () VUM.unsafeWrite IOVector a MVector (PrimState IO) a mv (Int off Int -> Int -> Int forall a. Num a => a -> a -> a + Int i) a x) Vector a Vector a v Maybe (a :~: a) Nothing -> String -> IO () forall a. HasCallStack => String -> a error String "copyIntoMutableColumn: Unboxed type mismatch" copyIntoMutableColumn MutableColumn _ Int _ Column _ = String -> IO () forall a. HasCallStack => String -> a error String "copyIntoMutableColumn: constructor mismatch" freezeMutableColumn :: MutableColumn -> IO Column freezeMutableColumn :: MutableColumn -> IO Column freezeMutableColumn (MOptionalColumn IOVector (Maybe a) mv) = Vector (Maybe a) -> Column forall a. Columnable a => Vector (Maybe a) -> Column OptionalColumn (Vector (Maybe a) -> Column) -> IO (Vector (Maybe a)) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) (Maybe a) -> IO (Vector (Maybe a)) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector (Maybe a) MVector (PrimState IO) (Maybe a) mv freezeMutableColumn (MBoxedColumn IOVector a mv) = Vector a -> Column forall a. Columnable a => Vector a -> Column BoxedColumn (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall (m :: * -> *) a. PrimMonad m => MVector (PrimState m) a -> m (Vector a) VB.unsafeFreeze IOVector a MVector (PrimState IO) a mv freezeMutableColumn (MUnboxedColumn IOVector a mv) = Vector a -> Column forall a. (Columnable a, Unbox a) => Vector a -> Column UnboxedColumn (Vector a -> Column) -> IO (Vector a) -> IO Column forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> MVector (PrimState IO) a -> IO (Vector a) forall a (m :: * -> *). (Unbox a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) VU.unsafeFreeze IOVector a MVector (PrimState IO) a mv toList :: forall a. (Columnable a) => Column -> [a] toList :: forall a. Columnable a => Column -> [a] toList Column xs = case forall a (v :: * -> *). (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector @a Column xs of Left DataFrameException err -> DataFrameException -> [a] forall a e. Exception e => e -> a throw DataFrameException err Right Vector a val -> Vector a -> [a] forall a. Vector a -> [a] VB.toList Vector a val toVector :: forall a v. (VG.Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector :: forall a (v :: * -> *). (Vector v a, Columnable a) => Column -> Either DataFrameException (v a) toVector = \case OptionalColumn Vector (Maybe a) col -> Vector (Maybe a) -> Either DataFrameException (v a) forall c (w :: * -> *). (Typeable c, Vector w c) => w c -> Either DataFrameException (v a) toVectorWorker Vector (Maybe a) col BoxedColumn Vector a col -> Vector a -> Either DataFrameException (v a) forall c (w :: * -> *). (Typeable c, Vector w c) => w c -> Either DataFrameException (v a) toVectorWorker Vector a col UnboxedColumn Vector a col -> Vector a -> Either DataFrameException (v a) forall c (w :: * -> *). (Typeable c, Vector w c) => w c -> Either DataFrameException (v a) toVectorWorker Vector a col where toVectorWorker :: forall c w. (Typeable c, VG.Vector w c) => w c -> Either DataFrameException (v a) toVectorWorker :: forall c (w :: * -> *). (Typeable c, Vector w c) => w c -> Either DataFrameException (v a) toVectorWorker w c vec = case TypeRep a -> TypeRep c -> Maybe (a :~: c) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) of Just a :~: c Refl -> v a -> Either DataFrameException (v a) forall a b. b -> Either a b Right (v a -> Either DataFrameException (v a)) -> v a -> Either DataFrameException (v a) forall a b. (a -> b) -> a -> b $ w a -> v a forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VG.convert w a w c vec Maybe (a :~: c) Nothing -> DataFrameException -> Either DataFrameException (v a) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (v a)) -> DataFrameException -> Either DataFrameException (v a) forall a b. (a -> b) -> a -> b $ TypeErrorContext a c -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep c) expectedType = TypeRep c -> Either String (TypeRep c) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @c) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) toDoubleVector :: Column -> Either DataFrameException (VU.Vector Double) toDoubleVector :: Column -> Either DataFrameException (Vector Double) toDoubleVector Column column = case Column column of UnboxedColumn (Vector a f :: VU.Vector a) -> case TypeRep a -> TypeRep Double -> Maybe (a :~: Double) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) of Just a :~: Double Refl -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right Vector a Vector Double f Maybe (a :~: Double) Nothing -> case forall a. SBoolI (FloatingTypes a) => SBool (FloatingTypes a) sFloating @a of SBool (FloatingTypes a) STrue -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right ((a -> Double) -> Vector a -> Vector Double forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac Vector a f) SBool (FloatingTypes a) SFalse -> case forall a. SBoolI (IntegralTypes a) => SBool (IntegralTypes a) sIntegral @a of SBool (IntegralTypes a) STrue -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right ((a -> Double) -> Vector a -> Vector Double forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map a -> Double forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) SBool (IntegralTypes a) SFalse -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Double)) -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. (a -> b) -> a -> b $ TypeErrorContext Double a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Double) userType = TypeRep Double -> Either String (TypeRep Double) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toDoubleVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) OptionalColumn (Vector (Maybe a) f :: VB.Vector (Maybe a)) -> case TypeRep a -> TypeRep Double -> Maybe (a :~: Double) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) of Just a :~: Double Refl -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right (Vector Double -> Vector Double forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Double -> Vector Double) -> Vector Double -> Vector Double forall a b. (a -> b) -> a -> b $ (Maybe Double -> Double) -> Vector (Maybe Double) -> Vector Double forall a b. (a -> b) -> Vector a -> Vector b VB.map (Double -> Maybe Double -> Double forall a. a -> Maybe a -> a fromMaybe (forall a. Read a => String -> a read @Double String "NaN")) Vector (Maybe a) Vector (Maybe Double) f) Maybe (a :~: Double) Nothing -> case forall a. SBoolI (FloatingTypes a) => SBool (FloatingTypes a) sFloating @a of SBool (FloatingTypes a) STrue -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right (Vector Double -> Vector Double forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Double -> Vector Double) -> Vector Double -> Vector Double forall a b. (a -> b) -> a -> b $ (Maybe a -> Double) -> Vector (Maybe a) -> Vector Double forall a b. (a -> b) -> Vector a -> Vector b VB.map (Double -> (a -> Double) -> Maybe a -> Double forall b a. b -> (a -> b) -> Maybe a -> b maybe (forall a. Read a => String -> a read @Double String "NaN") a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac) Vector (Maybe a) f) SBool (FloatingTypes a) SFalse -> case forall a. SBoolI (IntegralTypes a) => SBool (IntegralTypes a) sIntegral @a of SBool (IntegralTypes a) STrue -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right (Vector Double -> Vector Double forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Double -> Vector Double) -> Vector Double -> Vector Double forall a b. (a -> b) -> a -> b $ (Maybe a -> Double) -> Vector (Maybe a) -> Vector Double forall a b. (a -> b) -> Vector a -> Vector b VB.map (Double -> (a -> Double) -> Maybe a -> Double forall b a. b -> (a -> b) -> Maybe a -> b maybe (forall a. Read a => String -> a read @Double String "NaN") a -> Double forall a b. (Integral a, Num b) => a -> b fromIntegral) Vector (Maybe a) f) SBool (IntegralTypes a) SFalse -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Double)) -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. (a -> b) -> a -> b $ TypeErrorContext Double a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Double) userType = TypeRep Double -> Either String (TypeRep Double) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toDoubleVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) BoxedColumn (Vector a f :: VB.Vector a) -> case TypeRep a -> TypeRep Integer -> Maybe (a :~: Integer) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Integer) of Just a :~: Integer Refl -> Vector Double -> Either DataFrameException (Vector Double) forall a b. b -> Either a b Right (Vector Double -> Vector Double forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Double -> Vector Double) -> Vector Double -> Vector Double forall a b. (a -> b) -> a -> b $ (a -> Double) -> Vector a -> Vector Double forall a b. (a -> b) -> Vector a -> Vector b VB.map a -> Double forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) Maybe (a :~: Integer) Nothing -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Double)) -> DataFrameException -> Either DataFrameException (Vector Double) forall a b. (a -> b) -> a -> b $ TypeErrorContext Double () -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Double) userType = TypeRep Double -> Either String (TypeRep Double) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Double) , expectedType :: Either String (TypeRep ()) expectedType = String -> Either String (TypeRep ()) forall a b. a -> Either a b Left (Column -> String columnTypeString Column column) :: Either String (TypeRep ()) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toDoubleVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) toFloatVector :: Column -> Either DataFrameException (VU.Vector Float) toFloatVector :: Column -> Either DataFrameException (Vector Float) toFloatVector Column column = case Column column of UnboxedColumn (Vector a f :: VU.Vector a) -> case TypeRep a -> TypeRep Float -> Maybe (a :~: Float) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Float) of Just a :~: Float Refl -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right Vector a Vector Float f Maybe (a :~: Float) Nothing -> case forall a. SBoolI (FloatingTypes a) => SBool (FloatingTypes a) sFloating @a of SBool (FloatingTypes a) STrue -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right ((a -> Float) -> Vector a -> Vector Float forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map a -> Float forall a b. (Real a, Fractional b) => a -> b realToFrac Vector a f) SBool (FloatingTypes a) SFalse -> case forall a. SBoolI (IntegralTypes a) => SBool (IntegralTypes a) sIntegral @a of SBool (IntegralTypes a) STrue -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right ((a -> Float) -> Vector a -> Vector Float forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map a -> Float forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) SBool (IntegralTypes a) SFalse -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Float)) -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. (a -> b) -> a -> b $ TypeErrorContext Float a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Float) userType = TypeRep Float -> Either String (TypeRep Float) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Float) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toFloatVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) OptionalColumn (Vector (Maybe a) f :: VB.Vector (Maybe a)) -> case TypeRep a -> TypeRep Float -> Maybe (a :~: Float) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Float) of Just a :~: Float Refl -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right (Vector Float -> Vector Float forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Float -> Vector Float) -> Vector Float -> Vector Float forall a b. (a -> b) -> a -> b $ (Maybe Float -> Float) -> Vector (Maybe Float) -> Vector Float forall a b. (a -> b) -> Vector a -> Vector b VB.map (Float -> Maybe Float -> Float forall a. a -> Maybe a -> a fromMaybe (forall a. Read a => String -> a read @Float String "NaN")) Vector (Maybe a) Vector (Maybe Float) f) Maybe (a :~: Float) Nothing -> case forall a. SBoolI (FloatingTypes a) => SBool (FloatingTypes a) sFloating @a of SBool (FloatingTypes a) STrue -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right (Vector Float -> Vector Float forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Float -> Vector Float) -> Vector Float -> Vector Float forall a b. (a -> b) -> a -> b $ (Maybe a -> Float) -> Vector (Maybe a) -> Vector Float forall a b. (a -> b) -> Vector a -> Vector b VB.map (Float -> (a -> Float) -> Maybe a -> Float forall b a. b -> (a -> b) -> Maybe a -> b maybe (forall a. Read a => String -> a read @Float String "NaN") a -> Float forall a b. (Real a, Fractional b) => a -> b realToFrac) Vector (Maybe a) f) SBool (FloatingTypes a) SFalse -> case forall a. SBoolI (IntegralTypes a) => SBool (IntegralTypes a) sIntegral @a of SBool (IntegralTypes a) STrue -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right (Vector Float -> Vector Float forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Float -> Vector Float) -> Vector Float -> Vector Float forall a b. (a -> b) -> a -> b $ (Maybe a -> Float) -> Vector (Maybe a) -> Vector Float forall a b. (a -> b) -> Vector a -> Vector b VB.map (Float -> (a -> Float) -> Maybe a -> Float forall b a. b -> (a -> b) -> Maybe a -> b maybe (forall a. Read a => String -> a read @Float String "NaN") a -> Float forall a b. (Integral a, Num b) => a -> b fromIntegral) Vector (Maybe a) f) SBool (IntegralTypes a) SFalse -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Float)) -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. (a -> b) -> a -> b $ TypeErrorContext Float a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Float) userType = TypeRep Float -> Either String (TypeRep Float) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Float) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toFloatVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) BoxedColumn (Vector a f :: VB.Vector a) -> case TypeRep a -> TypeRep Integer -> Maybe (a :~: Integer) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Integer) of Just a :~: Integer Refl -> Vector Float -> Either DataFrameException (Vector Float) forall a b. b -> Either a b Right (Vector Float -> Vector Float forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Float -> Vector Float) -> Vector Float -> Vector Float forall a b. (a -> b) -> a -> b $ (a -> Float) -> Vector a -> Vector Float forall a b. (a -> b) -> Vector a -> Vector b VB.map a -> Float forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) Maybe (a :~: Integer) Nothing -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Float)) -> DataFrameException -> Either DataFrameException (Vector Float) forall a b. (a -> b) -> a -> b $ TypeErrorContext Float () -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Float) userType = TypeRep Float -> Either String (TypeRep Float) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Float) , expectedType :: Either String (TypeRep ()) expectedType = String -> Either String (TypeRep ()) forall a b. a -> Either a b Left (Column -> String columnTypeString Column column) :: Either String (TypeRep ()) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toFloatVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) toIntVector :: Column -> Either DataFrameException (VU.Vector Int) toIntVector :: Column -> Either DataFrameException (Vector Int) toIntVector Column column = case Column column of UnboxedColumn (Vector a f :: VU.Vector a) -> case TypeRep a -> TypeRep Int -> Maybe (a :~: Int) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) of Just a :~: Int Refl -> Vector Int -> Either DataFrameException (Vector Int) forall a b. b -> Either a b Right Vector a Vector Int f Maybe (a :~: Int) Nothing -> case forall a. SBoolI (FloatingTypes a) => SBool (FloatingTypes a) sFloating @a of SBool (FloatingTypes a) STrue -> Vector Int -> Either DataFrameException (Vector Int) forall a b. b -> Either a b Right ((a -> Int) -> Vector a -> Vector Int forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map (Double -> Int forall b. Integral b => Double -> b forall a b. (RealFrac a, Integral b) => a -> b round (Double -> Int) -> (a -> Double) -> a -> Int forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac) Vector a f) SBool (FloatingTypes a) SFalse -> case forall a. SBoolI (IntegralTypes a) => SBool (IntegralTypes a) sIntegral @a of SBool (IntegralTypes a) STrue -> Vector Int -> Either DataFrameException (Vector Int) forall a b. b -> Either a b Right ((a -> Int) -> Vector a -> Vector Int forall a b. (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b VU.map a -> Int forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) SBool (IntegralTypes a) SFalse -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Int)) -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. (a -> b) -> a -> b $ TypeErrorContext Int a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Int) userType = TypeRep Int -> Either String (TypeRep Int) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toIntVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) BoxedColumn (Vector a f :: VB.Vector a) -> case TypeRep a -> TypeRep Integer -> Maybe (a :~: Integer) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Integer) of Just a :~: Integer Refl -> Vector Int -> Either DataFrameException (Vector Int) forall a b. b -> Either a b Right (Vector Int -> Vector Int forall (v :: * -> *) a (w :: * -> *). (Vector v a, Vector w a) => v a -> w a VB.convert (Vector Int -> Vector Int) -> Vector Int -> Vector Int forall a b. (a -> b) -> a -> b $ (a -> Int) -> Vector a -> Vector Int forall a b. (a -> b) -> Vector a -> Vector b VB.map a -> Int forall a b. (Integral a, Num b) => a -> b fromIntegral Vector a f) Maybe (a :~: Integer) Nothing -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Int)) -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. (a -> b) -> a -> b $ TypeErrorContext Int () -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Int) userType = TypeRep Int -> Either String (TypeRep Int) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) , expectedType :: Either String (TypeRep ()) expectedType = String -> Either String (TypeRep ()) forall a b. a -> Either a b Left (Column -> String columnTypeString Column column) :: Either String (TypeRep ()) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toIntVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) Column _ -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector Int)) -> DataFrameException -> Either DataFrameException (Vector Int) forall a b. (a -> b) -> a -> b $ TypeErrorContext Int () -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Int) userType = TypeRep Int -> Either String (TypeRep Int) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) , expectedType :: Either String (TypeRep ()) expectedType = String -> Either String (TypeRep ()) forall a b. a -> Either a b Left (Column -> String columnTypeString Column column) :: Either String (TypeRep ()) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toIntVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) toUnboxedVector :: forall a. (Columnable a, VU.Unbox a) => Column -> Either DataFrameException (VU.Vector a) toUnboxedVector :: forall a. (Columnable a, Unbox a) => Column -> Either DataFrameException (Vector a) toUnboxedVector Column column = case Column column of UnboxedColumn (Vector a f :: VU.Vector b) -> case TypeRep a -> TypeRep a -> Maybe (a :~: a) forall a b. TypeRep a -> TypeRep b -> Maybe (a :~: b) forall {k} (f :: k -> *) (a :: k) (b :: k). TestEquality f => f a -> f b -> Maybe (a :~: b) testEquality (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @b) of Just a :~: a Refl -> Vector a -> Either DataFrameException (Vector a) forall a b. b -> Either a b Right Vector a Vector a f Maybe (a :~: a) Nothing -> DataFrameException -> Either DataFrameException (Vector a) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector a)) -> DataFrameException -> Either DataFrameException (Vector a) forall a b. (a -> b) -> a -> b $ TypeErrorContext Int a -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep Int) userType = TypeRep Int -> Either String (TypeRep Int) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @Int) , expectedType :: Either String (TypeRep a) expectedType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toUnboxedVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) Column _ -> DataFrameException -> Either DataFrameException (Vector a) forall a b. a -> Either a b Left (DataFrameException -> Either DataFrameException (Vector a)) -> DataFrameException -> Either DataFrameException (Vector a) forall a b. (a -> b) -> a -> b $ TypeErrorContext a () -> DataFrameException forall a b. (Typeable a, Typeable b) => TypeErrorContext a b -> DataFrameException TypeMismatchException ( MkTypeErrorContext { userType :: Either String (TypeRep a) userType = TypeRep a -> Either String (TypeRep a) forall a b. b -> Either a b Right (forall a. Typeable a => TypeRep a forall {k} (a :: k). Typeable a => TypeRep a typeRep @a) , expectedType :: Either String (TypeRep ()) expectedType = String -> Either String (TypeRep ()) forall a b. a -> Either a b Left (Column -> String columnTypeString Column column) :: Either String (TypeRep ()) , callingFunctionName :: Maybe String callingFunctionName = String -> Maybe String forall a. a -> Maybe a Just String "toUnboxedVector" , errorColumnName :: Maybe String errorColumnName = Maybe String forall a. Maybe a Nothing } ) {-# SPECIALIZE toUnboxedVector :: Column -> Either DataFrameException (VU.Vector Double) #-} {-# INLINE toUnboxedVector #-}