{-# LANGUAGE AllowAmbiguousTypes        #-}
{-# LANGUAGE CPP                        #-}
{-# LANGUAGE ConstraintKinds            #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE ExistentialQuantification  #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MagicHash                  #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE PatternSynonyms            #-}
{-# LANGUAGE PolyKinds                  #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE TypeInType                 #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE UnboxedTuples              #-}
{-# LANGUAGE UndecidableInstances       #-}
{-# LANGUAGE ViewPatterns               #-}
#ifdef UNSAFE_INDICES
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
#endif
{- |
  The core @easytensor@ types.
 -}
module Numeric.DataFrame.Type
  ( -- * Data types
    SomeDataFrame (..), DataFrame'
#if defined(__HADDOCK__) || defined(__HADDOCK_VERSION__)
  , DataFrame (SingleFrame, MultiFrame, XFrame)
  , pattern Z, pattern (:*:)
  , pattern S, pattern DF2, pattern DF3, pattern DF4, pattern DF5
  , pattern DF6, pattern DF7, pattern DF8, pattern DF9
#else
  , DataFrame ( SingleFrame, MultiFrame, XFrame, (:*:), Z
              , S, DF2, DF3, DF4, DF5, DF6, DF7, DF8, DF9)
#endif
  , scalar, unScalar
  , IndexFrame (..), SubFrameIndexCtx
    -- * Flexible assembling and disassembling
  , PackDF, packDF, unpackDF
  , appendDF, consDF, snocDF
  , fromFlatList, fromListWithDefault, fromList
  , constrainDF, asDiag
    -- * Infer type class instances
  , KnownBackend (), DFBackend, KnownBackends
  , InferKnownBackend (..), inferPrimElem
    -- * Re-exports
  , Dim (..), Idx (), Nat, XNat (..), N, XN, Dims, Idxs, TypedList (..)
  , PrimBytes (), bSizeOf, bAlignOf, bFieldOffsetOf
  , PrimArray (), ixOff
  ) where


#if !(MIN_VERSION_base(4,13,0))
import Data.Proxy (Proxy)
#endif
import           Control.Arrow                   (second, (***))
import           Data.Data
import           Data.Semigroup                  hiding (All, Min)
import           Data.Type.Lits
import           Data.Void
import           Foreign.Storable                (Storable (..))
import           GHC.Base
import           GHC.Exts                        (TYPE)
import qualified GHC.Generics                    as G
import           GHC.Ptr                         (Ptr (..))
import qualified Text.ParserCombinators.ReadPrec as Read
import qualified Text.Read                       as Read
import qualified Text.Read.Lex                   as Read
import           Unsafe.Coerce

import           Numeric.Basics
import           Numeric.DataFrame.Internal.PrimArray
import           Numeric.Dimensions
import           Numeric.PrimBytes
import           Numeric.ProductOrd
import qualified Numeric.ProductOrd.NonTransitive     as NonTransitive
import qualified Numeric.ProductOrd.Partial           as Partial
import           Numeric.TypedList                    (typeables)

import           Numeric.DataFrame.Internal.BackendI (DFBackend, KnownBackend)
import qualified Numeric.DataFrame.Internal.BackendI as Backend

-- See dimensions:Numeric.Dimensions.Dim
#define IS_UNSOUND_MATCHING_810_900 (MIN_VERSION_GLASGOW_HASKELL(8,10,0,0) && !MIN_VERSION_GLASGOW_HASKELL(9,1,0,0))

-- | Keep data in a primitive data frame
--    and maintain information about Dimensions in the type system
data family DataFrame (t :: l) (xs :: [k])

-- | Single frame
newtype instance DataFrame (t :: Type) (ns :: [Nat])
  = SingleFrame { DataFrame t ns -> DFBackend t ns
getSingleFrame :: DFBackend t ns }

-- | Multiple "columns" of data frames of the same shape
newtype instance DataFrame (ts :: [Type]) (ns :: [Nat])
  = MultiFrame ( TypedList (DataFrame' ns) ts )

-- | Data frame with some dimensions missing at compile time.
--   Pattern-match against its constructor to get a Nat-indexed data frame.
data instance DataFrame (ts :: l) (xns :: [XNat])
  = forall (ns :: [Nat])
  . (All KnownDimType xns, FixedDims xns ns, Dimensions ns, KnownBackends ts ns)
  => XFrame (DataFrame ts ns)

-- | Data frame that has an unknown dimensionality at compile time.
--   Pattern-match against its constructor to get a Nat-indexed data frame
data SomeDataFrame (t :: l)
  = forall (ns :: [Nat]) . (Dimensions ns, KnownBackends t ns)
  => SomeDataFrame (DataFrame t ns)
  deriving Typeable

-- | DataFrame with its type arguments swapped.
newtype DataFrame' (xs :: [k]) (t :: l) = DataFrame' (DataFrame t xs)
  deriving Typeable

{-# COMPLETE Z, (:*:) #-}

#define PLEASE_STYLISH_HASKELL \
  forall (xs :: [Type]) (ns :: [Nat])  . () => \
  forall (y :: Type)    (ys :: [Type]) . (xs ~ (y ': ys)) => \
  DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns

-- | Constructing a @MultiFrame@ using DataFrame columns
pattern (:*:) :: PLEASE_STYLISH_HASKELL
pattern $b:*: :: DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
$m:*: :: forall r (xs :: [*]) (ns :: [Nat]).
DataFrame xs ns
-> (forall y (ys :: [*]).
    (xs ~ (y : ys)) =>
    DataFrame y ns -> DataFrame ys ns -> r)
-> (Void# -> r)
-> r
(:*:) x xs <- (MultiFrame (DataFrame' x :* (MultiFrame -> xs)))
  where
    (:*:) DataFrame y ns
x (MultiFrame xs) = TypedList (DataFrame' ns) xs -> DataFrame xs ns
forall (ts :: [*]) (ns :: [Nat]).
TypedList (DataFrame' ns) ts -> DataFrame ts ns
MultiFrame (DataFrame y ns -> DataFrame' ns y
forall k l (xs :: [k]) (t :: l). DataFrame t xs -> DataFrame' xs t
DataFrame' DataFrame y ns
x DataFrame' ns y
-> TypedList (DataFrame' ns) ys -> TypedList (DataFrame' ns) xs
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList (DataFrame' ns) ys
xs)
infixr 6 :*:
#undef PLEASE_STYLISH_HASKELL

-- | Empty MultiFrame
pattern Z :: forall (xs :: [Type]) (ns :: [Nat])
           . () => (xs ~ '[]) => DataFrame xs ns
pattern $bZ :: DataFrame xs ns
$mZ :: forall r (xs :: [*]) (ns :: [Nat]).
DataFrame xs ns -> ((xs ~ '[]) => r) -> (Void# -> r) -> r
Z = MultiFrame U

-- | Convert a scalar back to an ordinary type
unScalar :: DataFrame t ('[] :: [Nat]) -> t
-- rely on that Scalar is just two times newtype alias to t
unScalar :: DataFrame t '[] -> t
unScalar = DataFrame t '[] -> t
forall a b. a -> b
unsafeCoerce
{-# INLINE unScalar #-}

-- | Convert any type to a scalar wrapper
scalar :: t -> DataFrame t ('[] :: [Nat])
-- rely on that Scalar is just two times newtype alias to t
scalar :: t -> DataFrame t '[]
scalar = t -> DataFrame t '[]
forall a b. a -> b
unsafeCoerce
{-# INLINE scalar #-}

-- | I use this kind-polymorphic constraint to generalize @XFrame@ and @SomeDataFrame@
--   over @SingleFrame@ and @MultiFrame@.
type family KnownBackends (ts :: l) (ns :: [Nat]) :: Constraint where
    KnownBackends ( t      ::  Type ) ns = KnownBackend t ns
    KnownBackends ('[]     :: [Type]) _  = ()
    KnownBackends (t ': ts :: [Type]) ns =
      (KnownBackend t ns, KnownBackends ts ns)

-- | Allow inferring @KnownBackends@ if you know the dimensions and the element types.
class InferKnownBackend t (ds :: [Nat]) where
    -- | Infer @KnownBackends@ if you know the dimensions and the element types.
    inferKnownBackend :: Dict (KnownBackends t ds)

instance (PrimBytes t, Dimensions ds) => InferKnownBackend (t :: Type) ds where
    inferKnownBackend :: Dict (KnownBackends t ds)
inferKnownBackend = (PrimBytes t, Dimensions ds) => Dict (KnownBackend t ds)
forall t (ds :: [Nat]).
(PrimBytes t, Dimensions ds) =>
Dict (KnownBackend t ds)
Backend.inferKnownBackend @t @ds

instance (RepresentableList ts, All PrimBytes ts, Dimensions ds)
      => InferKnownBackend (ts :: [Type]) ds where
    inferKnownBackend :: Dict (KnownBackends ts ds)
inferKnownBackend = TypeList ts -> Dict (KnownBackends ts ds)
forall (ss :: [*]).
All PrimBytes ss =>
TypeList ss -> Dict (KnownBackends ss ds)
go (RepresentableList ts => TypeList ts
forall k (xs :: [k]). RepresentableList xs => TypeList xs
tList @ts)
      where
        go :: forall ss . All PrimBytes ss
           => TypeList ss -> Dict (KnownBackends ss ds)
        go :: TypeList ss -> Dict (KnownBackends ss ds)
go TypeList ss
U = Dict (KnownBackends ss ds)
forall (a :: Constraint). a => Dict a
Dict
        go ((Proxy y
_ :: Proxy t) :* TypedList Proxy ys
ts)
             = case (PrimBytes y, Dimensions ds) => Dict (KnownBackend y ds)
forall t (ds :: [Nat]).
(PrimBytes t, Dimensions ds) =>
Dict (KnownBackend t ds)
Backend.inferKnownBackend @t @ds of
                 Dict (KnownBackend y ds)
Dict -> case TypedList Proxy ys -> Dict (KnownBackends ys ds)
forall (ss :: [*]).
All PrimBytes ss =>
TypeList ss -> Dict (KnownBackends ss ds)
go TypedList Proxy ys
ts of
                   Dict (KnownBackends ys ds)
Dict -> Dict (KnownBackends ss ds)
forall (a :: Constraint). a => Dict a
Dict


-- | All component data frames must satisfy a given constraint.
type family AllFrames (f :: Type -> Constraint) (ts :: [Type]) (ds :: [Nat])
                                                             :: Constraint where
    AllFrames _ '[] _ = ()
    AllFrames f (t ': ts) ds = (f (DataFrame t ds), AllFrames f ts ds)


-- | Index one dimension deep into a @DataFrame@.
class IndexFrame t d ds where
    -- | Index one dimension deep into a @DataFrame@.
    --
    --   Note, this function does not provide indexing safety at the type level;
    --   it throws an `OutOfDimBounds` exception if an index is out of bounds
    --   (unless @unsafeindices@ package flag is enabled, which is even more dangerous).
    (!) :: DataFrame t (d ': ds) -> Word -> DataFrame t ds

instance (PrimArray t (DataFrame t '[d]), KnownDim d)
      => IndexFrame (t :: Type) (d :: Nat) '[] where
    {-# INLINE (!) #-}
    (!) DataFrame t '[d]
df Word
i
#ifndef UNSAFE_INDICES
      | Word
i Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= KnownDim d => Word
forall k (n :: k). KnownDim n => Word
dimVal' @d = String
-> Word
-> Word
-> Maybe Word
-> Maybe ([Word], [Word])
-> DataFrame t '[]
forall i a.
Integral i =>
String -> i -> Word -> Maybe Word -> Maybe ([Word], [Word]) -> a
outOfDimBoundsNoCallStack String
"IndexFrame.(!)"
                            Word
i (KnownDim d => Word
forall k (n :: k). KnownDim n => Word
dimVal' @d) Maybe Word
forall a. Maybe a
Nothing Maybe ([Word], [Word])
forall a. Maybe a
Nothing
      | Bool
otherwise
#endif
        = t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S (Int -> DataFrame t '[d] -> t
forall t a. PrimArray t a => Int -> a -> t
ixOff (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
i) DataFrame t '[d]
df)

instance {-# INCOHERENT #-}
         ( PrimArray t (DataFrame t (d ': ds))
         , KnownDim d, KnownBackend t ds)
      => IndexFrame (t :: Type) (d :: Nat) ds where
    {-# INLINE (!) #-}
    (!) DataFrame t (d : ds)
df Word
i
#ifndef UNSAFE_INDICES
      | Word
i Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= KnownDim d => Word
forall k (n :: k). KnownDim n => Word
dimVal' @d = String
-> Word
-> Word
-> Maybe Word
-> Maybe ([Word], [Word])
-> DataFrame t ds
forall i a.
Integral i =>
String -> i -> Word -> Maybe Word -> Maybe ([Word], [Word]) -> a
outOfDimBoundsNoCallStack String
"IndexFrame.(!)"
                            Word
i (KnownDim d => Word
forall k (n :: k). KnownDim n => Word
dimVal' @d) Maybe Word
forall a. Maybe a
Nothing Maybe ([Word], [Word])
forall a. Maybe a
Nothing
      | Bool
otherwise
#endif
        = (t -> DataFrame t ds)
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t ds)
-> DataFrame t (d : ds)
-> DataFrame t ds
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t ds
forall t a. PrimArray t a => t -> a
broadcast
           (\(CumulDims ~(Word
_:ss :: [Word]
ss@(Word
s:[Word]
_))) Int#
off0 ->
               CumulDims -> Int# -> ByteArray# -> DataFrame t ds
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems ([Word] -> CumulDims
CumulDims [Word]
ss) (case Word
sWord -> Word -> Word
forall a. Num a => a -> a -> a
*Word
i of W# Word#
off -> Int#
off0 Int# -> Int# -> Int#
+# Word# -> Int#
word2Int# Word#
off)
           ) DataFrame t (d : ds)
df


instance IndexFrame ('[] :: [Type]) (d :: Nat) ds where
    {-# INLINE (!) #-}
    (!) DataFrame '[] (d : ds)
Z Word
_ = DataFrame '[] ds
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z

instance (IndexFrame t d ds, IndexFrame ts d ds)
      => IndexFrame ((t ': ts) :: [Type]) (d :: Nat) ds where
    {-# INLINE (!) #-}
    (!) (DataFrame y (d : ds)
df :*: DataFrame ys (d : ds)
dfs) Word
i = DataFrame y (d : ds)
df DataFrame y (d : ds) -> Word -> DataFrame y ds
forall k k (t :: k) (d :: k) (ds :: [k]).
IndexFrame t d ds =>
DataFrame t (d : ds) -> Word -> DataFrame t ds
! Word
i DataFrame y ds -> DataFrame ys ds -> DataFrame (t : ts) ds
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
:*: DataFrame ys (d : ds)
dfs DataFrame ys (d : ds) -> Word -> DataFrame ys ds
forall k k (t :: k) (d :: k) (ds :: [k]).
IndexFrame t d ds =>
DataFrame t (d : ds) -> Word -> DataFrame t ds
! Word
i

instance PrimBytes t
      => IndexFrame (t :: Type) (xd :: XNat) xds where
    {-# INLINE (!) #-}
    (!) (XFrame df) Word
i
      | Dim y
D :* (Dims ys
Dims :: Dims ns) <- TypedList Dim ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims TypedList Dim ns -> DataFrame t ns -> TypedList Dim ns
forall k (ds :: k) (p :: k -> *) (q :: k -> *).
p ds -> q ds -> p ds
`inSpaceOf` DataFrame t ns
df
      , Dict (KnownBackends t ys)
Dict <- InferKnownBackend t ys => Dict (KnownBackends t ys)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ns
        = DataFrame t (Tail ns) -> DataFrame t xds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (DataFrame t ns
DataFrame t (Head ns : Tail ns)
df DataFrame t (Head ns : Tail ns) -> Word -> DataFrame t (Tail ns)
forall k k (t :: k) (d :: k) (ds :: [k]).
IndexFrame t d ds =>
DataFrame t (d : ds) -> Word -> DataFrame t ds
! Word
i)
    (!) DataFrame t (xd : xds)
_ Word
_ = String -> DataFrame t xds
forall a. HasCallStack => String -> a
error String
"IndexFrame: impossible arguments"

instance (RepresentableList ts, All PrimBytes ts)
      => IndexFrame (ts :: [Type]) (xd :: XNat) xds where
    {-# INLINE (!) #-}
    (!) (XFrame df) Word
i
      | (Dim y
D :: Dim n) :* (Dims ys
Dims :: Dims ns) <- TypedList Dim ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims TypedList Dim ns -> DataFrame ts ns -> TypedList Dim ns
forall k (ds :: k) (p :: k -> *) (q :: k -> *).
p ds -> q ds -> p ds
`inSpaceOf` DataFrame ts ns
df
      , Dict (IndexFrame ts y ys, KnownBackends ts ys)
Dict <- TypeList ts -> Dict (IndexFrame ts y ys, KnownBackends ts ys)
forall (as :: [*]) (d :: Nat) (ds :: [Nat]).
(All PrimBytes as, KnownBackends as (d : ds), Dimensions ds,
 KnownDim d) =>
TypeList as -> Dict (IndexFrame as d ds, KnownBackends as ds)
getTsEvs @ts @n @ns TypeList ts
forall k (xs :: [k]). RepresentableList xs => TypeList xs
tList
        = DataFrame ts (Tail ns) -> DataFrame ts xds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (DataFrame ts ns
DataFrame ts (Head ns : Tail ns)
df DataFrame ts (Head ns : Tail ns) -> Word -> DataFrame ts (Tail ns)
forall k k (t :: k) (d :: k) (ds :: [k]).
IndexFrame t d ds =>
DataFrame t (d : ds) -> Word -> DataFrame t ds
! Word
i)
      where
        getTsEvs :: forall (as :: [Type]) (d :: Nat) (ds :: [Nat])
                  . ( All PrimBytes as, KnownBackends as (d ': ds)
                    , Dimensions ds, KnownDim d)
                 => TypeList as -> Dict (IndexFrame as d ds, KnownBackends as ds)
        getTsEvs :: TypeList as -> Dict (IndexFrame as d ds, KnownBackends as ds)
getTsEvs TypeList as
U = Dict (IndexFrame as d ds, KnownBackends as ds)
forall (a :: Constraint). a => Dict a
Dict
        getTsEvs ((Proxy y
_ :: Proxy a) :* TypedList Proxy ys
as')
          | Dict (IndexFrame ys d ds, KnownBackends ys ds)
Dict <- TypedList Proxy ys
-> Dict (IndexFrame ys d ds, KnownBackends ys ds)
forall (as :: [*]) (d :: Nat) (ds :: [Nat]).
(All PrimBytes as, KnownBackends as (d : ds), Dimensions ds,
 KnownDim d) =>
TypeList as -> Dict (IndexFrame as d ds, KnownBackends as ds)
getTsEvs @_ @d @ds TypedList Proxy ys
as'
          , Dict (KnownBackends y ds)
Dict <- InferKnownBackend y ds => Dict (KnownBackends y ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @a @ds = Dict (IndexFrame as d ds, KnownBackends as ds)
forall (a :: Constraint). a => Dict a
Dict
    (!) DataFrame ts (xd : xds)
_ Word
_ = String -> DataFrame ts xds
forall a. HasCallStack => String -> a
error String
"IndexFrame: impossible arguments"

{- |
This type family describes two strategies for dealing with dimensions when
slicing a @DataFrame@.

If the original space dimension (@d@) is fixed at compile time
(@d :: Nat@ or @d ~ N n@), then we enforce the safety of a slicing operation
with types:
    the index space is bounded by the size of the original space
    minus the subframe size.

If the original space dimension (@d@) is not fixed (@d ~ XN m@), then we give up.
Just let the user do the slicing as easy as possible, and throw an `OutOfDimBounds`
exception at runtime if the index plus the sliced size is greater than the
original size of the DataFrame.
 -}
type family SubFrameIndexCtx (d :: k) (idxN :: k) (subN :: k) :: Constraint where
    SubFrameIndexCtx (n :: Nat) idxN subN
      = (n + 1) ~ (idxN + subN)
    SubFrameIndexCtx (N n) idxN subN
      = ( (n + 1) ~ (DimBound idxN + DimBound subN)
        , idxN ~ N (DimBound idxN)
        , subN ~ N (DimBound subN)
        )
    SubFrameIndexCtx (XN m) idxN subN
      = ( idxN ~ XN m
        , subN ~ N (DimBound subN)
        )

deriving instance Typeable (DataFrame (t :: l) (xs :: [k]))
deriving instance ( Data (DataFrame t xs)
                  , Typeable t, Typeable xs, Typeable k, Typeable l)
               => Data (DataFrame' (xs :: [k]) (t :: l))
deriving instance Eq (DFBackend t ds)
               => Eq (DataFrame t ds)
deriving instance Ord (DFBackend t ds)
               => Ord (DataFrame t ds)
deriving instance ProductOrder (DFBackend t ds)
               => ProductOrder (DataFrame t ds)
deriving instance Bounded (DFBackend t ds)
               => Bounded (DataFrame t ds)
deriving instance Enum (DFBackend t ds)
               => Enum (DataFrame t ds)
deriving instance Integral (DFBackend t ds)
               => Integral (DataFrame t ds)
deriving instance Num (DFBackend t ds)
               => Num (DataFrame t ds)
deriving instance Fractional (DFBackend t ds)
               => Fractional (DataFrame t ds)
deriving instance Floating (DFBackend t ds)
               => Floating (DataFrame t ds)
deriving instance Epsilon (DFBackend t ds)
               => Epsilon (DataFrame t ds)
deriving instance Real (DFBackend t ds)
               => Real (DataFrame t ds)
deriving instance RealExtras (DFBackend t ds)
               => RealExtras (DataFrame t ds)
deriving instance RealFrac (DFBackend t ds)
               => RealFrac (DataFrame t ds)
deriving instance RealFloat (DFBackend t ds)
               => RealFloat (DataFrame t ds)
deriving instance RealFloatExtras (DFBackend t ds)
               => RealFloatExtras (DataFrame t ds)
deriving instance PrimBytes (DFBackend t ds)
               => PrimBytes (DataFrame t ds)
deriving instance (PrimArray t (DFBackend t ds), PrimBytes t)
               => PrimArray t (DataFrame t ds)


instance Ord (NonTransitive.ProductOrd (DFBackend t ds))
      => Ord (NonTransitive.ProductOrd (DataFrame t ds)) where
    > :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(>) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(>) @(NonTransitive.ProductOrd (DFBackend t ds)))
    < :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(<) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(<) @(NonTransitive.ProductOrd (DFBackend t ds)))
    >= :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(>=) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(>=) @(NonTransitive.ProductOrd (DFBackend t ds)))
    <= :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(<=) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(<=) @(NonTransitive.ProductOrd (DFBackend t ds)))
    compare :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> Ordering
compare = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Ordering)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Ordering
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare @(NonTransitive.ProductOrd (DFBackend t ds)))
    min :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds)
min = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds))
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds)
forall a. Ord a => a -> a -> a
min @(NonTransitive.ProductOrd (DFBackend t ds)))
    max :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds)
max = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds))
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds)
forall a. Ord a => a -> a -> a
max @(NonTransitive.ProductOrd (DFBackend t ds)))

instance (Ord (Partial.ProductOrd (DFBackend t ds)), Eq (DFBackend t ds))
      => Ord (Partial.ProductOrd (DataFrame t ds)) where
    > :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(>) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(>) @(Partial.ProductOrd (DFBackend t ds)))
    < :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(<) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(<) @(Partial.ProductOrd (DFBackend t ds)))
    >= :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(>=) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(>=) @(Partial.ProductOrd (DFBackend t ds)))
    <= :: ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds) -> Bool
(<=) = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Bool)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Bool
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds) -> Bool
forall a. Ord a => a -> a -> Bool
(<=) @(Partial.ProductOrd (DFBackend t ds)))
    compare :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> Ordering
compare = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> Ordering)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> Ordering
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare @(Partial.ProductOrd (DFBackend t ds)))
    min :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds)
min = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds))
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds)
forall a. Ord a => a -> a -> a
min @(Partial.ProductOrd (DFBackend t ds)))
    max :: ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds) -> ProductOrd (DataFrame t ds)
max = (ProductOrd (DFBackend t ds)
 -> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds))
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
-> ProductOrd (DataFrame t ds)
coerce (Ord (ProductOrd (DFBackend t ds)) =>
ProductOrd (DFBackend t ds)
-> ProductOrd (DFBackend t ds) -> ProductOrd (DFBackend t ds)
forall a. Ord a => a -> a -> a
max @(Partial.ProductOrd (DFBackend t ds)))



instance PrimBytes (DataFrame t ds) => Storable (DataFrame t ds) where
    sizeOf :: DataFrame t ds -> Int
sizeOf DataFrame t ds
x = Int# -> Int
I# (DataFrame t ds -> Int#
forall a. PrimBytes a => a -> Int#
byteSize DataFrame t ds
x)
    alignment :: DataFrame t ds -> Int
alignment DataFrame t ds
x = Int# -> Int
I# (DataFrame t ds -> Int#
forall a. PrimBytes a => a -> Int#
byteAlign DataFrame t ds
x)
    peek :: Ptr (DataFrame t ds) -> IO (DataFrame t ds)
peek (Ptr Addr#
addr) = (State# RealWorld -> (# State# RealWorld, DataFrame t ds #))
-> IO (DataFrame t ds)
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO (Addr# -> State# RealWorld -> (# State# RealWorld, DataFrame t ds #)
forall a s. PrimBytes a => Addr# -> State# s -> (# State# s, a #)
readAddr Addr#
addr)
    poke :: Ptr (DataFrame t ds) -> DataFrame t ds -> IO ()
poke (Ptr Addr#
addr) DataFrame t ds
a = (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO (\State# RealWorld
s -> (# DataFrame t ds -> Addr# -> State# RealWorld -> State# RealWorld
forall a s. PrimBytes a => a -> Addr# -> State# s -> State# s
writeAddr DataFrame t ds
a Addr#
addr State# RealWorld
s, () #))


instance AllFrames Eq ts ds => Eq (DataFrame (ts :: [Type]) ds) where
    DataFrame ts ds
Z == :: DataFrame ts ds -> DataFrame ts ds -> Bool
== DataFrame ts ds
Z = Bool
True
    (DataFrame y ds
a :*: DataFrame ys ds
as) == (DataFrame y ds
b :*: DataFrame ys ds
bs) = DataFrame y ds
a DataFrame y ds -> DataFrame y ds -> Bool
forall a. Eq a => a -> a -> Bool
== DataFrame y ds
DataFrame y ds
b Bool -> Bool -> Bool
&& DataFrame ys ds
as DataFrame ys ds -> DataFrame ys ds -> Bool
forall a. Eq a => a -> a -> Bool
== DataFrame ys ds
DataFrame ys ds
bs

instance Eq t => Eq (DataFrame (t :: Type) (ds :: [XNat])) where
    XFrame dfa == :: DataFrame t ds -> DataFrame t ds -> Bool
== XFrame dfb
      | Just Dict (ns ~ ns)
Dict <- DataFrame t ns -> DataFrame t ns -> Maybe (Dict (ns ~ ns))
forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] -> *)
       (q :: [Nat] -> *).
(Dimensions as, Dimensions bs) =>
p as -> q bs -> Maybe (Dict (as ~ bs))
sameDims' DataFrame t ns
dfa DataFrame t ns
dfb = DataFrame t ns
dfa DataFrame t ns -> DataFrame t ns -> Bool
forall a. Eq a => a -> a -> Bool
== DataFrame t ns
DataFrame t ns
dfb
      | Bool
otherwise                      = Bool
False

instance All Eq ts => Eq (DataFrame (ts :: [Type]) (ds :: [XNat])) where
    XFrame dfa == :: DataFrame ts ds -> DataFrame ts ds -> Bool
== XFrame dfb
      | Just Dict (ns ~ ns)
Dict <- DataFrame ts ns -> DataFrame ts ns -> Maybe (Dict (ns ~ ns))
forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] -> *)
       (q :: [Nat] -> *).
(Dimensions as, Dimensions bs) =>
p as -> q bs -> Maybe (Dict (as ~ bs))
sameDims' DataFrame ts ns
dfa DataFrame ts ns
dfb = DataFrame ts ns -> DataFrame ts ns -> Bool
forall (xs :: [*]) (ns :: [Nat]).
(KnownBackends xs ns, All Eq xs) =>
DataFrame xs ns -> DataFrame xs ns -> Bool
eqFrames DataFrame ts ns
dfa DataFrame ts ns
DataFrame ts ns
dfb
      | Bool
otherwise                      = Bool
False

instance Eq t => Eq (SomeDataFrame (t :: Type)) where
    SomeDataFrame DataFrame t ns
dfa == :: SomeDataFrame t -> SomeDataFrame t -> Bool
== SomeDataFrame DataFrame t ns
dfb
      | Just Dict (ns ~ ns)
Dict <- DataFrame t ns -> DataFrame t ns -> Maybe (Dict (ns ~ ns))
forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] -> *)
       (q :: [Nat] -> *).
(Dimensions as, Dimensions bs) =>
p as -> q bs -> Maybe (Dict (as ~ bs))
sameDims' DataFrame t ns
dfa DataFrame t ns
dfb = DataFrame t ns
dfa DataFrame t ns -> DataFrame t ns -> Bool
forall a. Eq a => a -> a -> Bool
== DataFrame t ns
DataFrame t ns
dfb
      | Bool
otherwise                      = Bool
False

instance All Eq ts => Eq (SomeDataFrame (ts :: [Type])) where
    SomeDataFrame DataFrame ts ns
dfa == :: SomeDataFrame ts -> SomeDataFrame ts -> Bool
== SomeDataFrame DataFrame ts ns
dfb
      | Just Dict (ns ~ ns)
Dict <- DataFrame ts ns -> DataFrame ts ns -> Maybe (Dict (ns ~ ns))
forall (as :: [Nat]) (bs :: [Nat]) (p :: [Nat] -> *)
       (q :: [Nat] -> *).
(Dimensions as, Dimensions bs) =>
p as -> q bs -> Maybe (Dict (as ~ bs))
sameDims' DataFrame ts ns
dfa DataFrame ts ns
dfb = DataFrame ts ns -> DataFrame ts ns -> Bool
forall (xs :: [*]) (ns :: [Nat]).
(KnownBackends xs ns, All Eq xs) =>
DataFrame xs ns -> DataFrame xs ns -> Bool
eqFrames DataFrame ts ns
dfa DataFrame ts ns
DataFrame ts ns
dfb
      | Bool
otherwise                      = Bool
False


eqFrames :: forall (xs :: [Type]) (ns :: [Nat])
          . (KnownBackends xs ns, All Eq xs)
         => DataFrame xs ns -> DataFrame xs ns -> Bool
eqFrames :: DataFrame xs ns -> DataFrame xs ns -> Bool
eqFrames DataFrame xs ns
Z DataFrame xs ns
Z                   = Bool
True
eqFrames (DataFrame y ns
a :*: DataFrame ys ns
as) (DataFrame y ns
b :*: DataFrame ys ns
bs) = DataFrame y ns
a DataFrame y ns -> DataFrame y ns -> Bool
forall a. Eq a => a -> a -> Bool
== DataFrame y ns
DataFrame y ns
b Bool -> Bool -> Bool
&& DataFrame ys ns -> DataFrame ys ns -> Bool
forall (xs :: [*]) (ns :: [Nat]).
(KnownBackends xs ns, All Eq xs) =>
DataFrame xs ns -> DataFrame xs ns -> Bool
eqFrames DataFrame ys ns
as DataFrame ys ns
DataFrame ys ns
bs



instance ( Show t
         , PrimBytes t
         , Dimensions ds
         ) => Show (DataFrame (t :: Type) (ds :: [Nat])) where
    showsPrec :: Int -> DataFrame t ds -> ShowS
showsPrec Int
p DataFrame t ds
x = case Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds of
      Dims ds
U       -> Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10)
        (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"S " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> t -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
10 (DataFrame t '[] -> t
forall t. DataFrame t '[] -> t
unScalar DataFrame t ds
DataFrame t '[]
x)
      Dim y
D0 :* TypedList Dim ys
_ -> String -> ShowS
showString String
"DF0"
      Dim y
d  :* TypedList Dim ys
_ -> Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10)
        (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ (Dict (Dimensions ys, KnownBackend t ys)
 -> (forall z. (Int -> DataFrame t ys -> z) -> Int -> z)
 -> Int
 -> ShowS)
-> DataFrame t (y : ys) -> ShowS
forall t (d :: Nat) (ds :: [Nat]) r.
(PrimBytes t, Dimensions (d : ds)) =>
(Dict (Dimensions ds, KnownBackend t ds)
 -> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
 -> Int
 -> r)
-> DataFrame t (d : ds) -> r
unpackDF' ( \Dict (Dimensions ys, KnownBackend t ys)
Dict forall z. (Int -> DataFrame t ys -> z) -> Int -> z
f ->
            let g :: Endo (Int -> ShowS)
                g :: Endo (Int -> ShowS)
g = ((Int -> ShowS) -> Int -> ShowS) -> Endo (Int -> ShowS)
forall a. (a -> a) -> Endo a
Endo (((Int -> ShowS) -> Int -> ShowS) -> Endo (Int -> ShowS))
-> ((Int -> ShowS) -> Int -> ShowS) -> Endo (Int -> ShowS)
forall a b. (a -> b) -> a -> b
$ \Int -> ShowS
k -> (Int -> DataFrame t ys -> ShowS) -> Int -> ShowS
forall z. (Int -> DataFrame t ys -> z) -> Int -> z
f (\Int
o DataFrame t ys
e -> Int -> ShowS
k Int
o ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame t ys -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 DataFrame t ys
e)
                n :: Word
n = Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
d
            in  Endo (Int -> ShowS) -> (Int -> ShowS) -> Int -> ShowS
forall a. Endo a -> a -> a
appEndo (Word -> Endo (Int -> ShowS) -> Endo (Int -> ShowS)
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes Word
n Endo (Int -> ShowS)
g) (ShowS -> Int -> ShowS
forall a b. a -> b -> a
const (ShowS -> Int -> ShowS) -> ShowS -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"DF" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> ShowS
forall a. Show a => a -> ShowS
shows Word
n)
          ) DataFrame t ds
DataFrame t (y : ys)
x

instance ( All Show ts
         , All PrimBytes ts
         , Dimensions ds
         ) => Show (DataFrame (ts :: [Type]) (ds :: [Nat])) where
    showsPrec :: Int -> DataFrame ts ds -> ShowS
showsPrec Int
_ DataFrame ts ds
Z = Char -> ShowS
showChar Char
'Z'
    showsPrec Int
p (DataFrame y ds
x :*: DataFrame ys ds
xs) = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
7) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
        Int -> DataFrame y ds -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
7 DataFrame y ds
x ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" :*: " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame ys ds -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
6 DataFrame ys ds
xs

instance (Show t, PrimBytes t)
      => Show (DataFrame (t :: Type) (xns :: [XNat])) where
    showsPrec :: Int -> DataFrame t xns -> ShowS
showsPrec Int
p (XFrame x)
      = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"XFrame " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame t ns -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 DataFrame t ns
x

instance (All Show ts, All PrimBytes ts)
      => Show (DataFrame (ts :: [Type]) (xns :: [XNat])) where
    showsPrec :: Int -> DataFrame ts xns -> ShowS
showsPrec Int
p (XFrame x)
      = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"XFrame " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame ts ns -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 DataFrame ts ns
x

instance (Show t, PrimBytes t)
      => Show (SomeDataFrame (t :: Type)) where
    showsPrec :: Int -> SomeDataFrame t -> ShowS
showsPrec Int
p (SomeDataFrame DataFrame t ns
x)
      = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"SomeDataFrame " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame t ns -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 DataFrame t ns
x

instance (All Show ts, All PrimBytes ts)
      => Show (SomeDataFrame (ts :: [Type])) where
    showsPrec :: Int -> SomeDataFrame ts -> ShowS
showsPrec Int
p (SomeDataFrame DataFrame ts ns
x)
      = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"SomeDataFrame " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> DataFrame ts ns -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 DataFrame ts ns
x


instance (Read t, PrimBytes t, Dimensions ds)
      => Read (DataFrame (t :: Type) (ds :: [Nat])) where
    readPrec :: ReadPrec (DataFrame t ds)
readPrec = Dims ds -> ReadPrec (DataFrame t ds)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF (Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds)
    readList :: ReadS [DataFrame t ds]
readList = ReadS [DataFrame t ds]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [DataFrame t ds]
readListPrec = ReadPrec [DataFrame t ds]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

instance (All Read ts, All PrimBytes ts, RepresentableList ts, Dimensions ds)
      => Read (DataFrame (ts :: [Type]) (ds :: [Nat])) where
    readPrec :: ReadPrec (DataFrame ts ds)
readPrec = TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
forall (ts :: [*]) (ds :: [Nat]).
(All Read ts, All PrimBytes ts) =>
TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readFixedMultiDF (RepresentableList ts => TypeList ts
forall k (xs :: [k]). RepresentableList xs => TypeList xs
tList @ts) (Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds)
    readList :: ReadS [DataFrame ts ds]
readList = ReadS [DataFrame ts ds]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [DataFrame ts ds]
readListPrec = ReadPrec [DataFrame ts ds]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

instance (Read t, PrimBytes t, BoundedDims ds, All KnownDimType ds)
      => Read (DataFrame (t :: Type) (ds :: [XNat])) where
    readPrec :: ReadPrec (DataFrame t ds)
readPrec = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds)
-> ReadPrec (DataFrame t ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ do
      ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"XFrame"
      ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ Dims ds -> ReadPrec (DataFrame t ds)
forall t (ds :: [XNat]).
(Read t, PrimBytes t, All KnownDimType ds) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF (BoundedDims ds => Dims ds
forall k (ds :: [k]). BoundedDims ds => Dims ds
minimalDims @ds)
    readList :: ReadS [DataFrame t ds]
readList = ReadS [DataFrame t ds]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [DataFrame t ds]
readListPrec = ReadPrec [DataFrame t ds]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

instance ( All Read ts, All PrimBytes ts, RepresentableList ts
         , BoundedDims ds, All KnownDimType ds)
      => Read (DataFrame (ts :: [Type]) (ds :: [XNat])) where
    readPrec :: ReadPrec (DataFrame ts ds)
readPrec = ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds)
-> ReadPrec (DataFrame ts ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a b. (a -> b) -> a -> b
$ do
      ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"XFrame"
      ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a b. (a -> b) -> a -> b
$ TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
forall (ts :: [*]) (ds :: [XNat]).
(All Read ts, All PrimBytes ts, All KnownDimType ds) =>
TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readBoundedMultiDF (RepresentableList ts => TypeList ts
forall k (xs :: [k]). RepresentableList xs => TypeList xs
tList @ts) (BoundedDims ds => Dims ds
forall k (ds :: [k]). BoundedDims ds => Dims ds
minimalDims @ds)
    readList :: ReadS [DataFrame ts ds]
readList = ReadS [DataFrame ts ds]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [DataFrame ts ds]
readListPrec = ReadPrec [DataFrame ts ds]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

instance (Read t, PrimBytes t)
      => Read (SomeDataFrame (t :: Type)) where
    readPrec :: ReadPrec (SomeDataFrame t)
readPrec = ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t))
-> (ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t))
-> ReadPrec (SomeDataFrame t)
-> ReadPrec (SomeDataFrame t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t))
-> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a b. (a -> b) -> a -> b
$ do
      ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"SomeDataFrame"
      ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. ReadPrec a -> ReadPrec a
Read.step ReadPrec (SomeDataFrame t)
forall t. (Read t, PrimBytes t) => ReadPrec (SomeDataFrame t)
readPrecSomeDF
    readList :: ReadS [SomeDataFrame t]
readList = ReadS [SomeDataFrame t]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [SomeDataFrame t]
readListPrec = ReadPrec [SomeDataFrame t]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

instance ( All Read ts, All PrimBytes ts, RepresentableList ts )
      => Read (SomeDataFrame (ts :: [Type])) where
    readPrec :: ReadPrec (SomeDataFrame ts)
readPrec = ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts)
-> ReadPrec (SomeDataFrame ts)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a b. (a -> b) -> a -> b
$ do
      ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"SomeDataFrame"
      ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a b. (a -> b) -> a -> b
$ TypeList ts -> ReadPrec (SomeDataFrame ts)
forall (ts :: [*]).
(All Read ts, All PrimBytes ts) =>
TypeList ts -> ReadPrec (SomeDataFrame ts)
readSomeMultiDF (RepresentableList ts => TypeList ts
forall k (xs :: [k]). RepresentableList xs => TypeList xs
tList @ts)
    readList :: ReadS [SomeDataFrame ts]
readList = ReadS [SomeDataFrame ts]
forall a. Read a => ReadS [a]
Read.readListDefault
    readListPrec :: ReadPrec [SomeDataFrame ts]
readListPrec = ReadPrec [SomeDataFrame ts]
forall a. Read a => ReadPrec [a]
Read.readListPrecDefault

readPrecFixedDF :: forall (t :: Type) (ds :: [Nat])
                 . (Read t, PrimBytes t)
                => Dims ds -> Read.ReadPrec (DataFrame t ds)
readPrecFixedDF :: Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF Dims ds
U
  = ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[])
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[]))
-> (ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[]))
-> ReadPrec (DataFrame t '[])
-> ReadPrec (DataFrame t '[])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[])
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[]))
-> ReadPrec (DataFrame t '[]) -> ReadPrec (DataFrame t '[])
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"S"
    t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S (t -> DataFrame t '[]) -> ReadPrec t -> ReadPrec (DataFrame t '[])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec t -> ReadPrec t
forall a. ReadPrec a -> ReadPrec a
Read.step ReadPrec t
forall a. Read a => ReadPrec a
Read.readPrec
readPrecFixedDF (Dim y
D0 :* Dims ys
Dims)
  = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF0"
    DataFrame t ds -> ReadPrec (DataFrame t ds)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall (ds :: [Nat]).
(PrimBytes t, Dimensions (0 : ds)) =>
PackDF t ds 0 (DataFrame t (0 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @0)
readPrecFixedDF (d :: Dim y
d@Dim y
D :* ds :: TypedList Dim ys
ds@TypedList Dim ys
Dims)
  = ReadPrec (DataFrame t (y : ys)) -> ReadPrec (DataFrame t (y : ys))
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t (y : ys))
 -> ReadPrec (DataFrame t (y : ys)))
-> (ReadPrec (DataFrame t (y : ys))
    -> ReadPrec (DataFrame t (y : ys)))
-> ReadPrec (DataFrame t (y : ys))
-> ReadPrec (DataFrame t (y : ys))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> ReadPrec (DataFrame t (y : ys))
-> ReadPrec (DataFrame t (y : ys))
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t (y : ys))
 -> ReadPrec (DataFrame t (y : ys)))
-> ReadPrec (DataFrame t (y : ys))
-> ReadPrec (DataFrame t (y : ys))
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show (Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
d)
    (forall r. ReadPrec (DataFrame t ys -> r) -> ReadPrec r)
-> (forall r. r -> ReadPrec r) -> ReadPrec (DataFrame t (y : ys))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' (ReadPrec (DataFrame t ys -> r)
-> ReadPrec (DataFrame t ys) -> ReadPrec r
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys)
forall a. ReadPrec a -> ReadPrec a
Read.step (TypedList Dim ys -> ReadPrec (DataFrame t ys)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF TypedList Dim ys
ds)) forall r. r -> ReadPrec r
forall (f :: * -> *) a. Applicative f => a -> f a
pure
#if IS_UNSOUND_MATCHING_810_900
readPrecFixedDF Dims ds
_ = String -> ReadPrec (DataFrame t ds)
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.readPrecFixedDF: impossible arguments"
#endif

{-
The first argument is, in fact, a @dimsBound@, but covered in the same @[XNat]@
  form. That is, XN values are lower bounds rather than actual runtime dimensions.

The interesting bit about this function is that it is very particular in specifying
what is enforced and what is unknown.
At the very least, the call site must know the order of the Dims (unless DF0 is present)
  -- and specify all dims as @XN 0@.
It allows a fine-grained control over the shape of a DataFrame.

For example,

>>> readPrecBoundedDF (Dx @5 DF5 :* Dn DF4 :* Dn DF4 :* U)

  reads an array of 4x4 matrices of length at least 5.

 -}
readPrecBoundedDF :: forall (t :: Type) (ds :: [XNat])
                   . (Read t, PrimBytes t, All KnownDimType ds)
                  => Dims ds -> Read.ReadPrec (DataFrame t ds)
-- reading scalar
readPrecBoundedDF :: Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF Dims ds
U
  = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds)
-> ReadPrec (DataFrame t ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"S"
    case InferKnownBackend t '[] => Dict (KnownBackends t '[])
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @'[] of
      Dict (KnownBackends t '[])
Dict -> DataFrame t '[] -> DataFrame t '[]
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (DataFrame t '[] -> DataFrame t '[])
-> (t -> DataFrame t '[]) -> t -> DataFrame t '[]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S (t -> DataFrame t '[]) -> ReadPrec t -> ReadPrec (DataFrame t '[])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec t -> ReadPrec t
forall a. ReadPrec a -> ReadPrec a
Read.step ReadPrec t
forall a. Read a => ReadPrec a
Read.readPrec
-- DF0 is funny because it will succesfully parse any dimension to the right of it.
readPrecBoundedDF (Dn Dim n
D0 :* XDims (Dims ns
Dims :: Dims ns))
  = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF0"
    DataFrame t ds -> ReadPrec (DataFrame t ds)
forall (m :: * -> *) a. Monad m => a -> m a
return (DataFrame t ds -> ReadPrec (DataFrame t ds))
-> DataFrame t ds -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ case InferKnownBackend t (0 : ns) => Dict (KnownBackends t (0 : ns))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(0 ': ns) of
      Dict (KnownBackends t (0 : ns))
Dict -> DataFrame t (0 : ns) -> DataFrame t ds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame @Type @t @ds @(0 ': ns) ((PrimBytes t, Dimensions (0 : ns)) =>
PackDF t ns 0 (DataFrame t (0 : ns))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @0 @ns)
-- Fixed dimension:
--  The number of component frames is exactly n
--  the first component frame fixes the shape of the rest n-1
readPrecBoundedDF (Dn d :: Dim n
d@(Dim n
D :: Dim n) :* TypedList Dim ys
xns)
  = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds)
-> ReadPrec (DataFrame t ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ do
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show (Dim n -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim n
d)
    XFrame (x :: DataFrame t ns) <- ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys))
-> ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys)
forall a b. (a -> b) -> a -> b
$ TypedList Dim ys -> ReadPrec (DataFrame t ys)
forall t (ds :: [XNat]).
(Read t, PrimBytes t, All KnownDimType ds) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF @t TypedList Dim ys
xns
    case InferKnownBackend t (n : ns) => Dict (KnownBackends t (n : ns))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n ': ns) of
      Dict (KnownBackends t (n : ns))
Dict -> (DataFrame t (n : ns) -> DataFrame t (N n : ys))
-> ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (N n : ys))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataFrame t (n : ns) -> DataFrame t (N n : ys)
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (ReadPrec (DataFrame t (n : ns))
 -> ReadPrec (DataFrame t (N n : ys)))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> ReadPrec (DataFrame t (n : ns)))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (N n : ys))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
-> ReadPrec (DataFrame t (n : ns))
forall a b. (a, b) -> b
snd ((ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
 -> ReadPrec (DataFrame t (n : ns)))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns))))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (n : ns))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Delayed t ns ReadPrec (DataFrame t (n : ns))
-> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
forall l (t :: l) k (ds :: [k]) (c :: * -> *) a.
Delayed t ds c a -> (c (DataFrame t ds), c a)
runDelay (Delayed t ns ReadPrec (DataFrame t (n : ns))
 -> ReadPrec (DataFrame t (N n : ys)))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (N n : ys))
forall a b. (a -> b) -> a -> b
$ (forall r.
 Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> (forall r. r -> Delayed t ns ReadPrec r)
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' @t @n @ns
        (ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall t (ds :: [Nat]) (c :: * -> *) r.
Applicative c =>
c (DataFrame t ds)
-> Delayed t ds c (DataFrame t ds -> r) -> Delayed t ds c r
readDelayed (ReadPrec (DataFrame t ns)
 -> Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall a b. (a -> b) -> a -> b
$ Int -> ReadPrec (DataFrame t ns) -> ReadPrec (DataFrame t ns)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (Dims ns -> ReadPrec (DataFrame t ns)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF @t @ns Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims))
        (DataFrame t ns -> r -> Delayed t ns ReadPrec r
forall l k (c :: * -> *) (t :: l) (ds :: [k]) a.
Applicative c =>
DataFrame t ds -> a -> Delayed t ds c a
followedBy DataFrame t ns
x)
-- Bounded dimension:
--   The number of component frames is at least m
--   the first component frame fixes the shape of the rest n-1
readPrecBoundedDF ((Dx (Dim n
m :: Dim m) :: Dim xm) :* TypedList Dim ys
xns)
  | Dict ('XN n ~ y)
Dict <- Dict ('XN n ~ y)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @XNat @('XN m) @xm -- by user contract the argument is dimBound
  = ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds) -> ReadPrec (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ ReadPrec Lexeme
lookLex ReadPrec Lexeme
-> (Lexeme -> ReadPrec (DataFrame t ds))
-> ReadPrec (DataFrame t ds)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Read.Ident (Char
'D':Char
'F':String
s)
      | Just (Dx (Dim n
n :: Dim n)) <- (String -> Maybe SomeDim
forall a. Read a => String -> Maybe a
Read.readMaybe (Char
'D'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s) :: Maybe SomeDim)
      , Just Dict (n <= n)
Dict <- Dim n -> Dim n -> Maybe (Dict (n <= n))
forall (x :: Nat) (y :: Nat).
Dim x -> Dim y -> Maybe (Dict (x <= y))
lessOrEqDim Dim n
m Dim n
n
        -> case Dim n
n of
          Dim n
D0 -> do -- need to repack it under different constraint dims
            XFrame x <- Dims (N 0 : ys) -> ReadPrec (DataFrame t (N 0 : ys))
forall t (ds :: [XNat]).
(Read t, PrimBytes t, All KnownDimType ds) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF @t (Dim 0 -> Dim (N 0)
forall k (d :: k) (n :: Nat).
(KnownDimType d, d ~~ N n) =>
Dim n -> Dim d
Dn Dim 0
forall (n :: Nat). (n ~ 0) => Dim n
D0 Dim (N 0) -> TypedList Dim ys -> Dims (N 0 : ys)
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Dim ys
xns)
            DataFrame t (XN m : ys) -> ReadPrec (DataFrame t (XN m : ys))
forall (m :: * -> *) a. Monad m => a -> m a
return (DataFrame t ns -> DataFrame t (XN m : ys)
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame DataFrame t ns
x)
          Dim n
D  -> do
            ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show (Dim n -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim n
n)
            XFrame (x :: DataFrame t ns) <- Int -> ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys))
-> ReadPrec (DataFrame t ys) -> ReadPrec (DataFrame t ys)
forall a b. (a -> b) -> a -> b
$ TypedList Dim ys -> ReadPrec (DataFrame t ys)
forall t (ds :: [XNat]).
(Read t, PrimBytes t, All KnownDimType ds) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF @t TypedList Dim ys
xns
            case InferKnownBackend t (n : ns) => Dict (KnownBackends t (n : ns))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n ': ns) of
              Dict (KnownBackends t (n : ns))
Dict -> (DataFrame t (n : ns) -> DataFrame t (XN m : ys))
-> ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (XN m : ys))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataFrame t (n : ns) -> DataFrame t (XN m : ys)
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (ReadPrec (DataFrame t (n : ns))
 -> ReadPrec (DataFrame t (XN m : ys)))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> ReadPrec (DataFrame t (n : ns)))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (XN m : ys))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
-> ReadPrec (DataFrame t (n : ns))
forall a b. (a, b) -> b
snd ((ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
 -> ReadPrec (DataFrame t (n : ns)))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns))))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (n : ns))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Delayed t ns ReadPrec (DataFrame t (n : ns))
-> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
forall l (t :: l) k (ds :: [k]) (c :: * -> *) a.
Delayed t ds c a -> (c (DataFrame t ds), c a)
runDelay (Delayed t ns ReadPrec (DataFrame t (n : ns))
 -> ReadPrec (DataFrame t (XN m : ys)))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (XN m : ys))
forall a b. (a -> b) -> a -> b
$ (forall r.
 Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> (forall r. r -> Delayed t ns ReadPrec r)
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' @t @n @ns
                (ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall t (ds :: [Nat]) (c :: * -> *) r.
Applicative c =>
c (DataFrame t ds)
-> Delayed t ds c (DataFrame t ds -> r) -> Delayed t ds c r
readDelayed (ReadPrec (DataFrame t ns)
 -> Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall a b. (a -> b) -> a -> b
$ Int -> ReadPrec (DataFrame t ns) -> ReadPrec (DataFrame t ns)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (Dims ns -> ReadPrec (DataFrame t ns)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF @t @ns Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims))
                (DataFrame t ns -> r -> Delayed t ns ReadPrec r
forall l k (c :: * -> *) (t :: l) (ds :: [k]) a.
Applicative c =>
DataFrame t ds -> a -> Delayed t ds c a
followedBy DataFrame t ns
x)

    Lexeme
_ -> ReadPrec (DataFrame t ds)
forall a. ReadPrec a
Read.pfail

{-
In this case we know Nothing about the dimensionality of a DataFrame.
The logic is similar to readPrecBoundedDF, but a bit simpler:
the first dimension is flexible, but fixes the rest dimensions.
 -}
readPrecSomeDF :: forall (t :: Type) . (Read t, PrimBytes t)
               => Read.ReadPrec (SomeDataFrame t)
readPrecSomeDF :: ReadPrec (SomeDataFrame t)
readPrecSomeDF = ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t))
-> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a b. (a -> b) -> a -> b
$
    Int -> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (do
      ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"S"
      case InferKnownBackend t '[] => Dict (KnownBackends t '[])
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @'[] of
        Dict (KnownBackends t '[])
Dict -> DataFrame t '[] -> SomeDataFrame t
forall l (t :: l) (ns :: [Nat]).
(Dimensions ns, KnownBackends t ns) =>
DataFrame t ns -> SomeDataFrame t
SomeDataFrame (DataFrame t '[] -> SomeDataFrame t)
-> (t -> DataFrame t '[]) -> t -> SomeDataFrame t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S (t -> SomeDataFrame t) -> ReadPrec t -> ReadPrec (SomeDataFrame t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec t
forall a. Read a => ReadPrec a
Read.readPrec
    )
    ReadPrec (SomeDataFrame t)
-> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
Read.+++
    (ReadPrec Lexeme
lookLex ReadPrec Lexeme
-> (Lexeme -> ReadPrec (SomeDataFrame t))
-> ReadPrec (SomeDataFrame t)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
       Read.Ident (Char
'D':Char
'F':String
s)
         | Just (Dx (d :: Dim n
d@Dim n
D :: Dim d)) <- (String -> Maybe SomeDim
forall a. Read a => String -> Maybe a
Read.readMaybe (Char
'D'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s) :: Maybe SomeDim)
           -> case Dim n
d of
             Dim n
D0 | Dict (KnownBackends t '[0])
Dict <- InferKnownBackend t '[0] => Dict (KnownBackends t '[0])
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @'[0]
                 -> DataFrame t '[0] -> SomeDataFrame t
forall l (t :: l) (ns :: [Nat]).
(Dimensions ns, KnownBackends t ns) =>
DataFrame t ns -> SomeDataFrame t
SomeDataFrame (DataFrame t '[0] -> SomeDataFrame t)
-> ReadPrec (DataFrame t '[0]) -> ReadPrec (SomeDataFrame t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dims '[0] -> ReadPrec (DataFrame t '[0])
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF @t (Dim 0
forall (n :: Nat). (n ~ 0) => Dim n
D0 Dim 0 -> TypedList Dim '[] -> Dims '[0]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Dim '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
             Dim n
_ -> do
               ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (String -> ReadP ()) -> String -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> (String -> Lexeme) -> String -> ReadP ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Lexeme
Read.Ident (String -> ReadPrec ()) -> String -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String
"DF" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show (Dim n -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim n
d)
               SomeDataFrame (DataFrame t ns
x :: DataFrame t ds) <- Int -> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t))
-> ReadPrec (SomeDataFrame t) -> ReadPrec (SomeDataFrame t)
forall a b. (a -> b) -> a -> b
$ (Read t, PrimBytes t) => ReadPrec (SomeDataFrame t)
forall t. (Read t, PrimBytes t) => ReadPrec (SomeDataFrame t)
readPrecSomeDF @t
               case InferKnownBackend t (n : ns) => Dict (KnownBackends t (n : ns))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(d ': ds) of
                 Dict (KnownBackends t (n : ns))
Dict -> (DataFrame t (n : ns) -> SomeDataFrame t)
-> ReadPrec (DataFrame t (n : ns)) -> ReadPrec (SomeDataFrame t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataFrame t (n : ns) -> SomeDataFrame t
forall l (t :: l) (ns :: [Nat]).
(Dimensions ns, KnownBackends t ns) =>
DataFrame t ns -> SomeDataFrame t
SomeDataFrame (ReadPrec (DataFrame t (n : ns)) -> ReadPrec (SomeDataFrame t))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> ReadPrec (DataFrame t (n : ns)))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (SomeDataFrame t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
-> ReadPrec (DataFrame t (n : ns))
forall a b. (a, b) -> b
snd ((ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
 -> ReadPrec (DataFrame t (n : ns)))
-> (Delayed t ns ReadPrec (DataFrame t (n : ns))
    -> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns))))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (DataFrame t (n : ns))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Delayed t ns ReadPrec (DataFrame t (n : ns))
-> (ReadPrec (DataFrame t ns), ReadPrec (DataFrame t (n : ns)))
forall l (t :: l) k (ds :: [k]) (c :: * -> *) a.
Delayed t ds c a -> (c (DataFrame t ds), c a)
runDelay (Delayed t ns ReadPrec (DataFrame t (n : ns))
 -> ReadPrec (SomeDataFrame t))
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
-> ReadPrec (SomeDataFrame t)
forall a b. (a -> b) -> a -> b
$ (forall r.
 Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> (forall r. r -> Delayed t ns ReadPrec r)
-> Delayed t ns ReadPrec (DataFrame t (n : ns))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' @t @d @ds
                   (ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall t (ds :: [Nat]) (c :: * -> *) r.
Applicative c =>
c (DataFrame t ds)
-> Delayed t ds c (DataFrame t ds -> r) -> Delayed t ds c r
readDelayed (ReadPrec (DataFrame t ns)
 -> Delayed t ns ReadPrec (DataFrame t ns -> r)
 -> Delayed t ns ReadPrec r)
-> ReadPrec (DataFrame t ns)
-> Delayed t ns ReadPrec (DataFrame t ns -> r)
-> Delayed t ns ReadPrec r
forall a b. (a -> b) -> a -> b
$ Int -> ReadPrec (DataFrame t ns) -> ReadPrec (DataFrame t ns)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
10 (Dims ns -> ReadPrec (DataFrame t ns)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF @t @ds Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims))
                   (DataFrame t ns -> r -> Delayed t ns ReadPrec r
forall l k (c :: * -> *) (t :: l) (ds :: [k]) a.
Applicative c =>
DataFrame t ds -> a -> Delayed t ds c a
followedBy DataFrame t ns
x)
       Lexeme
_ -> ReadPrec (SomeDataFrame t)
forall a. ReadPrec a
Read.pfail
    )

readFixedMultiDF :: forall (ts :: [Type]) (ds :: [Nat])
                  . (All Read ts, All PrimBytes ts)
                 => TypeList ts
                 -> Dims ds
                 -> Read.ReadPrec (DataFrame ts ds)
readFixedMultiDF :: TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readFixedMultiDF TypeList ts
U Dims ds
_ = ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a b. (a -> b) -> a -> b
$
    DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z DataFrame ts ds -> ReadPrec () -> ReadPrec (DataFrame ts ds)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> Lexeme -> ReadP ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"Z")
readFixedMultiDF (Proxy y
_ :* TypedList Proxy ys
ts) Dims ds
ds = ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds)
-> ReadPrec (DataFrame ts ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
6 (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a b. (a -> b) -> a -> b
$ do
    DataFrame y ds
x <- ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds))
-> ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds)
forall a b. (a -> b) -> a -> b
$ Dims ds -> ReadPrec (DataFrame y ds)
forall t (ds :: [Nat]).
(Read t, PrimBytes t) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecFixedDF Dims ds
ds
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Symbol String
":*:"
    DataFrame ys ds
xs <- TypedList Proxy ys -> Dims ds -> ReadPrec (DataFrame ys ds)
forall (ts :: [*]) (ds :: [Nat]).
(All Read ts, All PrimBytes ts) =>
TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readFixedMultiDF TypedList Proxy ys
ts Dims ds
ds
    DataFrame ts ds -> ReadPrec (DataFrame ts ds)
forall (m :: * -> *) a. Monad m => a -> m a
return (DataFrame y ds
x DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
:*: DataFrame ys ds
xs)

readBoundedMultiDF :: forall (ts :: [Type]) (ds :: [XNat])
                    . (All Read ts, All PrimBytes ts, All KnownDimType ds)
                   => TypeList ts
                   -> Dims ds
                   -> Read.ReadPrec (DataFrame ts ds)
readBoundedMultiDF :: TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readBoundedMultiDF TypeList ts
U (XDims (Dims ns
Dims :: Dims ns))
  = ReadPrec (DataFrame '[] ds) -> ReadPrec (DataFrame '[] ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame '[] ds) -> ReadPrec (DataFrame '[] ds))
-> ReadPrec (DataFrame '[] ds) -> ReadPrec (DataFrame '[] ds)
forall a b. (a -> b) -> a -> b
$
    DataFrame '[] ns -> DataFrame '[] ds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame @[Type] @'[] @ds @ns DataFrame '[] ns
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z DataFrame '[] ds -> ReadPrec () -> ReadPrec (DataFrame '[] ds)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> Lexeme -> ReadP ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"Z")
readBoundedMultiDF ((Proxy y
_ :: Proxy t) :* ts :: TypedList Proxy ys
ts@TypedList Proxy ys
TypeList) Dims ds
ds
  = ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds)
-> ReadPrec (DataFrame ts ds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
6 (ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds))
-> ReadPrec (DataFrame ts ds) -> ReadPrec (DataFrame ts ds)
forall a b. (a -> b) -> a -> b
$ do
    XFrame (x :: DataFrame t ns) <- ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds))
-> ReadPrec (DataFrame y ds) -> ReadPrec (DataFrame y ds)
forall a b. (a -> b) -> a -> b
$ Dims ds -> ReadPrec (DataFrame y ds)
forall t (ds :: [XNat]).
(Read t, PrimBytes t, All KnownDimType ds) =>
Dims ds -> ReadPrec (DataFrame t ds)
readPrecBoundedDF @t Dims ds
ds
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Symbol String
":*:"
    DataFrame ys ns
xs <- TypedList Proxy ys -> Dims ns -> ReadPrec (DataFrame ys ns)
forall (ts :: [*]) (ds :: [Nat]).
(All Read ts, All PrimBytes ts) =>
TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readFixedMultiDF TypedList Proxy ys
ts (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ns)
    case InferKnownBackend ts ns => Dict (KnownBackends ts ns)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @ts @ns of
      Dict (KnownBackends ts ns)
Dict -> DataFrame (y : ys) ds -> ReadPrec (DataFrame (y : ys) ds)
forall (m :: * -> *) a. Monad m => a -> m a
return (DataFrame (y : ys) ds -> ReadPrec (DataFrame (y : ys) ds))
-> DataFrame (y : ys) ds -> ReadPrec (DataFrame (y : ys) ds)
forall a b. (a -> b) -> a -> b
$ DataFrame (y : ys) ns -> DataFrame (y : ys) ds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (DataFrame y ns
x DataFrame y ns -> DataFrame ys ns -> DataFrame (y : ys) ns
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
:*: DataFrame ys ns
xs)
#if IS_UNSOUND_MATCHING_810_900
readBoundedMultiDF TypeList ts
_ Dims ds
_ = String -> ReadPrec (DataFrame ts ds)
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.readBoundedMultiDF: impossible arguments"
#endif

readSomeMultiDF :: forall (ts :: [Type])
                 . (All Read ts, All PrimBytes ts)
                => TypeList ts
                -> Read.ReadPrec (SomeDataFrame ts)
readSomeMultiDF :: TypeList ts -> ReadPrec (SomeDataFrame ts)
readSomeMultiDF TypeList ts
U
  = ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a b. (a -> b) -> a -> b
$
    DataFrame ts '[] -> SomeDataFrame ts
forall l (t :: l) (ns :: [Nat]).
(Dimensions ns, KnownBackends t ns) =>
DataFrame t ns -> SomeDataFrame t
SomeDataFrame @[Type] @ts @'[] DataFrame ts '[]
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z SomeDataFrame ts -> ReadPrec () -> ReadPrec (SomeDataFrame ts)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadP ()) -> Lexeme -> ReadP ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Ident String
"Z")
readSomeMultiDF ((Proxy y
_ :: Proxy t) :* ts :: TypedList Proxy ys
ts@TypedList Proxy ys
TypeList)
  = ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. ReadPrec a -> ReadPrec a
Read.parens (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts)
-> ReadPrec (SomeDataFrame ts)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a. Int -> ReadPrec a -> ReadPrec a
Read.prec Int
6 (ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts))
-> ReadPrec (SomeDataFrame ts) -> ReadPrec (SomeDataFrame ts)
forall a b. (a -> b) -> a -> b
$ do
    SomeDataFrame (DataFrame y ns
x :: DataFrame t ns) <- ReadPrec (SomeDataFrame y) -> ReadPrec (SomeDataFrame y)
forall a. ReadPrec a -> ReadPrec a
Read.step (ReadPrec (SomeDataFrame y) -> ReadPrec (SomeDataFrame y))
-> ReadPrec (SomeDataFrame y) -> ReadPrec (SomeDataFrame y)
forall a b. (a -> b) -> a -> b
$ (Read y, PrimBytes y) => ReadPrec (SomeDataFrame y)
forall t. (Read t, PrimBytes t) => ReadPrec (SomeDataFrame t)
readPrecSomeDF @t
    ReadP () -> ReadPrec ()
forall a. ReadP a -> ReadPrec a
Read.lift (ReadP () -> ReadPrec ())
-> (Lexeme -> ReadP ()) -> Lexeme -> ReadPrec ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lexeme -> ReadP ()
Read.expect (Lexeme -> ReadPrec ()) -> Lexeme -> ReadPrec ()
forall a b. (a -> b) -> a -> b
$ String -> Lexeme
Read.Symbol String
":*:"
    DataFrame ys ns
xs <- TypedList Proxy ys -> Dims ns -> ReadPrec (DataFrame ys ns)
forall (ts :: [*]) (ds :: [Nat]).
(All Read ts, All PrimBytes ts) =>
TypeList ts -> Dims ds -> ReadPrec (DataFrame ts ds)
readFixedMultiDF TypedList Proxy ys
ts (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ns)
    case InferKnownBackend ts ns => Dict (KnownBackends ts ns)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @ts @ns of
      Dict (KnownBackends ts ns)
Dict -> SomeDataFrame (y : ys) -> ReadPrec (SomeDataFrame (y : ys))
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeDataFrame (y : ys) -> ReadPrec (SomeDataFrame (y : ys)))
-> SomeDataFrame (y : ys) -> ReadPrec (SomeDataFrame (y : ys))
forall a b. (a -> b) -> a -> b
$ DataFrame (y : ys) ns -> SomeDataFrame (y : ys)
forall l (t :: l) (ns :: [Nat]).
(Dimensions ns, KnownBackends t ns) =>
DataFrame t ns -> SomeDataFrame t
SomeDataFrame (DataFrame y ns
x DataFrame y ns -> DataFrame ys ns -> DataFrame (y : ys) ns
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
:*: DataFrame ys ns
xs)

-- First element is read separately, enforcing the structure of the rest.
newtype Delayed t ds c a = Delayed { Delayed t ds c a -> (c (DataFrame t ds), c a)
runDelay :: (c (DataFrame t ds), c a) }

followedBy :: Applicative c => DataFrame t ds -> a -> Delayed t ds c a
followedBy :: DataFrame t ds -> a -> Delayed t ds c a
followedBy DataFrame t ds
x = (c (DataFrame t ds), c a) -> Delayed t ds c a
forall l k (t :: l) (ds :: [k]) (c :: * -> *) a.
(c (DataFrame t ds), c a) -> Delayed t ds c a
Delayed ((c (DataFrame t ds), c a) -> Delayed t ds c a)
-> (a -> (c (DataFrame t ds), c a)) -> a -> Delayed t ds c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) (DataFrame t ds -> c (DataFrame t ds)
forall (f :: * -> *) a. Applicative f => a -> f a
pure DataFrame t ds
x) (c a -> (c (DataFrame t ds), c a))
-> (a -> c a) -> a -> (c (DataFrame t ds), c a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> c a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

readDelayed :: forall (t :: Type) (ds :: [Nat]) (c :: Type -> Type) (r :: Type)
             . Applicative c
            => c (DataFrame t ds)
            -> Delayed t ds c (DataFrame t ds -> r) -> Delayed t ds c r
readDelayed :: c (DataFrame t ds)
-> Delayed t ds c (DataFrame t ds -> r) -> Delayed t ds c r
readDelayed c (DataFrame t ds)
readF (Delayed (c (DataFrame t ds)
cprev, c (DataFrame t ds -> r)
cf)) = (c (DataFrame t ds), c r) -> Delayed t ds c r
forall l k (t :: l) (ds :: [k]) (c :: * -> *) a.
(c (DataFrame t ds), c a) -> Delayed t ds c a
Delayed (c (DataFrame t ds)
readF, c (DataFrame t ds -> r)
cf c (DataFrame t ds -> r) -> c (DataFrame t ds) -> c r
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c (DataFrame t ds)
cprev)


-- | Check the next lexeme without consuming it
lookLex :: Read.ReadPrec Read.Lexeme
lookLex :: ReadPrec Lexeme
lookLex = ReadPrec String
Read.look ReadPrec String -> (String -> ReadPrec Lexeme) -> ReadPrec Lexeme
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
  [ReadPrec Lexeme] -> ReadPrec Lexeme
forall a. [ReadPrec a] -> ReadPrec a
Read.choice ([ReadPrec Lexeme] -> ReadPrec Lexeme)
-> (String -> [ReadPrec Lexeme]) -> String -> ReadPrec Lexeme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Lexeme, String) -> ReadPrec Lexeme)
-> [(Lexeme, String)] -> [ReadPrec Lexeme]
forall a b. (a -> b) -> [a] -> [b]
map (Lexeme -> ReadPrec Lexeme
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Lexeme -> ReadPrec Lexeme)
-> ((Lexeme, String) -> Lexeme)
-> (Lexeme, String)
-> ReadPrec Lexeme
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Lexeme, String) -> Lexeme
forall a b. (a, b) -> a
fst) ([(Lexeme, String)] -> [ReadPrec Lexeme])
-> (String -> [(Lexeme, String)]) -> String -> [ReadPrec Lexeme]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReadPrec Lexeme -> Int -> String -> [(Lexeme, String)]
forall a. ReadPrec a -> Int -> ReadS a
Read.readPrec_to_S ReadPrec Lexeme
Read.lexP Int
10




-- | Evidence that the elements of the DataFrame are PrimBytes.
inferPrimElem
  :: forall (t :: Type) (d :: Nat) (ds :: [Nat])
   . KnownBackend t (d ': ds)
  => DataFrame t (d ': ds) -> Dict (PrimBytes t)
inferPrimElem :: DataFrame t (d : ds) -> Dict (PrimBytes t)
inferPrimElem = Backend I t (d : ds) (BackendFamily t (d : ds))
-> Dict (PrimBytes t)
forall t (d :: Nat) (ds :: [Nat]) i.
KnownBackend t (d : ds) =>
Backend i t (d : ds) (BackendFamily t (d : ds))
-> Dict (PrimBytes t)
Backend.inferPrimElem (Backend I t (d : ds) (BackendFamily t (d : ds))
 -> Dict (PrimBytes t))
-> (DataFrame t (d : ds)
    -> Backend I t (d : ds) (BackendFamily t (d : ds)))
-> DataFrame t (d : ds)
-> Dict (PrimBytes t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame t (d : ds)
-> Backend I t (d : ds) (BackendFamily t (d : ds))
forall t (ns :: [Nat]). DataFrame t ns -> DFBackend t ns
getSingleFrame

-- | Construct a DataFrame from a flat list.
--
--   The values are filled according to the DataFrame layout: row-by-row and
--   further from the last dimension (least significant) to the first dimension
--   (most significant).
--
--   If the argument list is shorter than @totalDim@, then the rest of the frame
--   is padded with a default value (second argument).
--
--   If the argument list is longer than @totalDim@, then unused values are dropped.
--   If you want, you can pass an infinite list as an argument, i.e. the following
--   is a valid use:
--
--   >>> fromFlatList (dims :: Dims '[2,5]) 0 [6,8..]
--
fromFlatList :: forall (t :: Type) (ds :: [Nat])
              . PrimArray t (DataFrame t ds)
             => Dims ds -> t -> [t] -> DataFrame t ds
fromFlatList :: Dims ds -> t -> [t] -> DataFrame t ds
fromFlatList = Dims ds -> t -> [t] -> DataFrame t ds
forall k t a (ns :: [k]). PrimArray t a => Dims ns -> t -> [t] -> a
unsafeFromFlatList



-- | A scalar DataFrame is just a newtype wrapper on a value.
pattern S :: forall (t :: Type) . t -> DataFrame t ('[] :: [Nat])
-- rely on that Scalar is just two times newtype alias to t
pattern $bS :: t -> DataFrame t '[]
$mS :: forall r t. DataFrame t '[] -> (t -> r) -> (Void# -> r) -> r
S x <- (unScalar -> x)
  where
    S = t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
scalar
{-# COMPLETE S #-}


pattern DF2 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (2 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t (2 ': ds)
pattern $bDF2 :: DataFrame t ds -> DataFrame t ds -> DataFrame t (2 : ds)
$mDF2 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (2 : ds)) =>
DataFrame t (2 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds -> DataFrame t ds -> r)
-> (Void# -> r)
-> r
DF2 a1 a2
    <- (unpackDF @t @2 @ds (#,,#) -> (# a1,a2,Dict #))
  where DF2 = (PrimBytes t, Dimensions (2 : ds)) =>
PackDF t ds 2 (DataFrame t (2 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @2 @ds
{-# COMPLETE DF2 #-}

pattern DF3 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (3 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t (3 ': ds)
pattern $bDF3 :: DataFrame t ds
-> DataFrame t ds -> DataFrame t ds -> DataFrame t (3 : ds)
$mDF3 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (3 : ds)) =>
DataFrame t (3 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> r)
-> (Void# -> r)
-> r
DF3 a1 a2 a3
    <- (unpackDF @t @3 @ds (#,,,#) -> (# a1,a2,a3,Dict #))
  where DF3 = (PrimBytes t, Dimensions (3 : ds)) =>
PackDF t ds 3 (DataFrame t (3 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @3 @ds
{-# COMPLETE DF3 #-}

pattern DF4 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (4 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t (4 ': ds)
pattern $bDF4 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (4 : ds)
$mDF4 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (4 : ds)) =>
DataFrame t (4 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> r)
-> (Void# -> r)
-> r
DF4 a1 a2 a3 a4
    <- (unpackDF @t @4 @ds (#,,,,#) -> (# a1,a2,a3,a4,Dict #))
  where DF4 = (PrimBytes t, Dimensions (4 : ds)) =>
PackDF t ds 4 (DataFrame t (4 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @4 @ds
{-# COMPLETE DF4 #-}

pattern DF5 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (5 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds
            -> DataFrame t (5 ': ds)
pattern $bDF5 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (5 : ds)
$mDF5 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (5 : ds)) =>
DataFrame t (5 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> r)
-> (Void# -> r)
-> r
DF5 a1 a2 a3 a4 a5
    <- (unpackDF @t @5 @ds (#,,,,,#) -> (# a1,a2,a3,a4,a5,Dict #))
  where DF5 = (PrimBytes t, Dimensions (5 : ds)) =>
PackDF t ds 5 (DataFrame t (5 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @5 @ds
{-# COMPLETE DF5 #-}

pattern DF6 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (6 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t (6 ': ds)
pattern $bDF6 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (6 : ds)
$mDF6 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (6 : ds)) =>
DataFrame t (6 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> r)
-> (Void# -> r)
-> r
DF6 a1 a2 a3 a4 a5 a6
    <- (unpackDF @t @6 @ds (#,,,,,,#) -> (# a1,a2,a3,a4,a5,a6,Dict #))
  where DF6 = (PrimBytes t, Dimensions (6 : ds)) =>
PackDF t ds 6 (DataFrame t (6 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @6 @ds
{-# COMPLETE DF6 #-}

pattern DF7 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (7 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t (7 ': ds)
pattern $bDF7 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (7 : ds)
$mDF7 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (7 : ds)) =>
DataFrame t (7 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> r)
-> (Void# -> r)
-> r
DF7 a1 a2 a3 a4 a5 a6 a7
    <- (unpackDF @t @7 @ds (#,,,,,,,#) -> (# a1,a2,a3,a4,a5,a6,a7,Dict #))
  where DF7 = (PrimBytes t, Dimensions (7 : ds)) =>
PackDF t ds 7 (DataFrame t (7 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @7 @ds
{-# COMPLETE DF7 #-}

pattern DF8 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (8 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t (8 ': ds)
pattern $bDF8 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (8 : ds)
$mDF8 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (8 : ds)) =>
DataFrame t (8 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> r)
-> (Void# -> r)
-> r
DF8 a1 a2 a3 a4 a5 a6 a7 a8
    <- (unpackDF @t @8 @ds (#,,,,,,,,#) -> (# a1,a2,a3,a4,a5,a6,a7,a8,Dict #))
  where DF8 = (PrimBytes t, Dimensions (8 : ds)) =>
PackDF t ds 8 (DataFrame t (8 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @8 @ds
{-# COMPLETE DF8 #-}

pattern DF9 :: forall (t :: Type) (ds :: [Nat])
             . (PrimBytes t, Dimensions (9 ': ds))
            => (Dimensions ds, KnownBackend t ds)
            => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds
            -> DataFrame t ds
            -> DataFrame t (9 ': ds)
pattern $bDF9 :: DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t ds
-> DataFrame t (9 : ds)
$mDF9 :: forall r t (ds :: [Nat]).
(PrimBytes t, Dimensions (9 : ds)) =>
DataFrame t (9 : ds)
-> ((Dimensions ds, KnownBackend t ds) =>
    DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> DataFrame t ds
    -> r)
-> (Void# -> r)
-> r
DF9 a1 a2 a3 a4 a5 a6 a7 a8 a9
    <- (unpackDF @t @9 @ds (#,,,,,,,,,#) -> (# a1,a2,a3,a4,a5,a6,a7,a8,a9,Dict #))
  where DF9 = (PrimBytes t, Dimensions (9 : ds)) =>
PackDF t ds 9 (DataFrame t (9 : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @9 @ds
{-# COMPLETE DF9 #-}


-- | Represent smart constructor functions `packDF` and `unpackDF`.
type family PackDF (t :: Type) (ds :: [Nat]) (d :: Nat) (r :: Type) :: Type where
    PackDF _ _  0 r = r
    PackDF t ds d r = DataFrame t ds -> PackDF t ds (d - 1) r

{- |
   Takes @d@ arguments of type @DataFrame t ds@ and produce a @DataFrame t (d ': ds)@.

   NB: always use @TypeApplications@ extension with this function to apply all
       type arguments!
       Otherwise, a very dumb type family @PackDF@ will not infer the types for you.

   The following example creates a @Matrix Double 12 3@ filled with twelve
   3D vectors (using @fromInteger@ of @Vector Double 3@):

   >>> packDF @Double @12 @'[3] 1 2 3 4 5 6 7 8 9 10 11 12

  `packDF` and `unpackDF`  together serve as a generic constructor for a DataFrame
   of an arbitrary (statically known) size.

 -}
packDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat])
        . (PrimBytes t, Dimensions (d ': ds))
       => PackDF t ds d (DataFrame t (d ': ds))
packDF :: PackDF t ds d (DataFrame t (d : ds))
packDF
  | Dim y
d :* Dims ys
Dims <- Dimensions (d : ds) => TypedList Dim (d : ds)
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @(d ': ds)
  , Dict (KnownBackends t (d : ds))
Dict <- InferKnownBackend t (d : ds) => Dict (KnownBackends t (d : ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(d ': ds)
  , Dict (KnownBackends t ds)
Dict <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
    = (Dimensions ds, KnownBackend t ds, KnownBackend t (d : ds)) =>
Dim d -> PackDF t ds d (DataFrame t (d : ds))
Dim d -> PackDF t ds d (DataFrame t (d : ds))
go Dim d
Dim y
d
  | Bool
otherwise = String -> PackDF t ds d (DataFrame t (d : ds))
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.packDF: impossible arguments"
  where
    go :: (Dimensions ds, KnownBackend t ds, KnownBackend t (d ': ds))
       => Dim d
       -> PackDF t ds d (DataFrame t (d ': ds))
    go :: Dim d -> PackDF t ds d (DataFrame t (d : ds))
go Dim d
d = Dim d
-> (forall r.
    (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r)
-> PackDF t ds d (DataFrame t (d : ds))
forall (n :: Nat).
Dim n
-> (forall r.
    (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r)
-> PackDF t ds n (DataFrame t (d : ds))
recur Dim d
d forall r.
(forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
getResult
      where
        -- number of elements in the frame as Int#
        els :: Int#
els = case Dim d -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim d
d of W# Word#
w -> Word# -> Int#
word2Int# Word#
w
        -- size of a single element in bytes
        asize :: Int#
asize = DataFrame t ds -> Int#
forall a. PrimBytes a => a -> Int#
byteSize @(DataFrame t ds) DataFrame t ds
forall a. HasCallStack => a
undefined

        getResult :: forall rRep (r :: TYPE rRep)
                  . (forall s. Int# -> MutableByteArray# s -> State# s -> r)
                  -> r
        getResult :: (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
getResult forall s. Int# -> MutableByteArray# s -> State# s -> r
f = (State# RealWorld -> r) -> r
forall o. (State# RealWorld -> o) -> o
runRW#
          ( \State# RealWorld
s0 -> case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# (Int#
asize Int# -> Int# -> Int#
*# Int#
els) State# RealWorld
s0 of
               (# State# RealWorld
s1, MutableByteArray# RealWorld
mba #) -> Int# -> MutableByteArray# RealWorld -> State# RealWorld -> r
forall s. Int# -> MutableByteArray# s -> State# s -> r
f Int#
0# MutableByteArray# RealWorld
mba State# RealWorld
s1
          )

        recur :: forall n . Dim n
              -> (forall rRep (r :: TYPE rRep)
                    . (forall s. Int# -> MutableByteArray# s -> State# s -> r ) -> r)
              -> PackDF t ds n (DataFrame t (d ': ds))
        recur :: Dim n
-> (forall r.
    (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r)
-> PackDF t ds n (DataFrame t (d : ds))
recur Dim n
n forall r.
(forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
f = case Dim n -> Dim 1 -> Maybe (Dim (n - 1))
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Maybe (Dim (n - m))
minusDimM Dim n
n (Dim 1
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D :: Dim 1) of
          Maybe (Dim (n - 1))
Nothing -> case Dict (n ~ 0)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @Nat @n @0 of
            Dict (n ~ 0)
Dict -> (forall s.
 Int# -> MutableByteArray# s -> State# s -> DataFrame t (d : ds))
-> DataFrame t (d : ds)
forall r.
(forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
f (\Int#
_ MutableByteArray# s
mba State# s
s -> case MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# s
mba State# s
s of
                                     (# State# s
_, ByteArray#
ba #) -> Int# -> ByteArray# -> DataFrame t (d : ds)
forall a. PrimBytes a => Int# -> ByteArray# -> a
fromBytes Int#
0# ByteArray#
ba )
          Just Dim (n - 1)
n' -> case Dict
  (PackDF t ds n (DataFrame t (d : ds))
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds))))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @_
                           @(PackDF t ds n (DataFrame t (d ': ds)))
                           @(DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d ': ds))) of
            Dict
  (PackDF t ds n (DataFrame t (d : ds))
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds))))
Dict -> \DataFrame t ds
x -> Dim (n - 1)
-> (forall r.
    (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r)
-> PackDF t ds (n - 1) (DataFrame t (d : ds))
forall (n :: Nat).
Dim n
-> (forall r.
    (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r)
-> PackDF t ds n (DataFrame t (d : ds))
recur Dim (n - 1)
n'
              ( \forall s. Int# -> MutableByteArray# s -> State# s -> r
c -> (forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
forall r.
(forall s. Int# -> MutableByteArray# s -> State# s -> r) -> r
f (\Int#
off MutableByteArray# s
mba State# s
s -> Int# -> MutableByteArray# s -> State# s -> r
forall s. Int# -> MutableByteArray# s -> State# s -> r
c (Int#
off Int# -> Int# -> Int#
+# Int#
asize) MutableByteArray# s
mba (MutableByteArray# s
-> Int# -> DataFrame t ds -> State# s -> State# s
forall a s.
PrimBytes a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeBytes MutableByteArray# s
mba Int#
off DataFrame t ds
x State# s
s)) )



{- |
  Takes a function (e.g. a constructor) with @d+1@ argument (df1, df2, .. dfd, Dict)
   and a @DataFrame t (d ': ds)@.
   Feeds the dataframe elements into that function.
   For example, you can pass a tuple to this function, and get all dataframe elements
    (and some dictionaries -- useful evidence to work with element frames)

   NB: always use @TypeApplications@ extension with this function to apply all
       type arguments!
       Otherwise, a very dumb type family @PackDF@ will not infer the types for you.

   The following example unpacks a 3D vector
     (created using @fromInteger@ of @Vector Double 3@)
   into a 4-tuple with three scalars and one Dict:

   >>> unpackDF @Double @3 @'[] (,,,) 2

  `packDF` and `unpackDF`  together serve as a generic constructor for a DataFrame
   of an arbitrary (statically known) size.

 -}
unpackDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat])
                   (rep :: RuntimeRep) (r :: TYPE rep)
          . (PrimBytes t, Dimensions (d ': ds))
         => PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
         -> DataFrame t (d ': ds) -> r
unpackDF :: PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
-> DataFrame t (d : ds) -> r
unpackDF PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
c
  | Dim y
d :* Dims ys
Dims <- Dimensions (d : ds) => TypedList Dim (d : ds)
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @(d ': ds)
    = (Dict (Dimensions ds, KnownBackend t ds)
 -> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
 -> Int
 -> r)
-> DataFrame t (d : ds) -> r
forall t (d :: Nat) (ds :: [Nat]) r.
(PrimBytes t, Dimensions (d : ds)) =>
(Dict (Dimensions ds, KnownBackend t ds)
 -> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
 -> Int
 -> r)
-> DataFrame t (d : ds) -> r
unpackDF' (Dim d
-> Dict (Dimensions ds, KnownBackend t ds)
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
-> Int
-> r
forall a.
(a ~ Dict (Dimensions ds, KnownBackend t ds)) =>
Dim d
-> a
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
-> Int
-> r
go Dim d
Dim y
d)
  | Bool
otherwise = String -> DataFrame t (d : ds) -> r
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.unpackDF: impossible arguments"
  where
    go :: forall a . (a ~ Dict (Dimensions ds, KnownBackend t ds))
       => Dim d -> a
       -> (forall (zRep :: RuntimeRep) (z :: TYPE zRep)
                  . (Int -> DataFrame t ds -> z) -> Int -> z)
       -> Int -> r
    go :: Dim d
-> a
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
-> Int
-> r
go Dim d
d a
a forall z. (Int -> DataFrame t ds -> z) -> Int -> z
k = Dim d -> (Int -> PackDF t ds d (a -> r)) -> Int -> r
forall (n :: Nat).
Dim n -> (Int -> PackDF t ds n (a -> r)) -> Int -> r
recur Dim d
d (PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
-> Int
-> PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
forall a b. a -> b -> a
const PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r)
c)
      where
        recur :: forall n
               . Dim n
              -> (Int -> PackDF t ds n (a -> r))
              -> Int -> r
        recur :: Dim n -> (Int -> PackDF t ds n (a -> r)) -> Int -> r
recur Dim n
n Int -> PackDF t ds n (a -> r)
f = case Dim n -> Dim 1 -> Maybe (Dim (n - 1))
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Maybe (Dim (n - m))
minusDimM Dim n
n (Dim 1
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D :: Dim 1) of
          Maybe (Dim (n - 1))
Nothing -> case Dict (n ~ 0)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @Nat @n @0 of
            Dict (n ~ 0)
Dict -> (Int -> PackDF t ds n (a -> r)
Int -> a -> r
`f` a
a)
          Just Dim (n - 1)
n' -> case Dict
  (PackDF t ds n (a -> r)
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (a -> r)))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @_
                           @(PackDF t ds n (a -> r))
                           @(DataFrame t ds -> PackDF t ds (n - 1) (a -> r)) of
            Dict
  (PackDF t ds n (a -> r)
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (a -> r)))
Dict -> Dim (n - 1) -> (Int -> PackDF t ds (n - 1) (a -> r)) -> Int -> r
forall (n :: Nat).
Dim n -> (Int -> PackDF t ds n (a -> r)) -> Int -> r
recur Dim (n - 1)
n' ((Int
 -> DataFrame t ds
 -> PackDF
      t ds (n - 1) (Dict (Dimensions ds, KnownBackend t ds) -> r))
-> Int
-> PackDF
     t ds (n - 1) (Dict (Dimensions ds, KnownBackend t ds) -> r)
forall z. (Int -> DataFrame t ds -> z) -> Int -> z
k Int -> PackDF t ds n (a -> r)
Int
-> DataFrame t ds
-> PackDF
     t ds (n - 1) (Dict (Dimensions ds, KnownBackend t ds) -> r)
f)


packDF' :: forall (t :: Type) (d :: Nat) (ds :: [Nat]) c
         . (PrimBytes t, Dimensions (d ': ds))
        => (forall r. c (DataFrame t ds -> r) -> c r)
        -> (forall r. r -> c r)
        -> c (DataFrame t (d ': ds))
packDF' :: (forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' forall r. c (DataFrame t ds -> r) -> c r
k forall r. r -> c r
z
  | Dim y
d :* TypedList Dim ys
_ <- Dimensions (d : ds) => TypedList Dim (d : ds)
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @(d ': ds)
    = Dim y
-> c (PackDF t ds y (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
forall (n :: Nat).
Dim n
-> c (PackDF t ds n (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
go Dim y
d (PackDF t ds d (DataFrame t (d : ds))
-> c (PackDF t ds d (DataFrame t (d : ds)))
forall r. r -> c r
z ((PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
PackDF t ds d (DataFrame t (d : ds))
packDF @t @d @ds))
#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
  | Bool
otherwise = String -> c (DataFrame t (d : ds))
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.packDF': impossible arguments"
#endif
  where
    go :: forall n . Dim n
       -> c (PackDF t ds n (DataFrame t (d ': ds))) -> c (DataFrame t (d ': ds))
    go :: Dim n
-> c (PackDF t ds n (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
go Dim n
n = case Dim n -> Dim 1 -> Maybe (Dim (n - 1))
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Maybe (Dim (n - m))
minusDimM Dim n
n (Dim 1
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D :: Dim 1) of
      Maybe (Dim (n - 1))
Nothing -> case Dict (n ~ 0)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @Nat @n @0 of Dict (n ~ 0)
Dict -> c (PackDF t ds n (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
forall a. a -> a
id
      Just Dim (n - 1)
n' -> case Dict
  (PackDF t ds n (DataFrame t (d : ds))
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds))))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @_
                       @(PackDF t ds n (DataFrame t (d ': ds)))
                       @(DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d ': ds))) of
        Dict
  (PackDF t ds n (DataFrame t (d : ds))
   ~ (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds))))
Dict -> Dim (n - 1)
-> c (PackDF t ds (n - 1) (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
forall (n :: Nat).
Dim n
-> c (PackDF t ds n (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
go Dim (n - 1)
n' (c (PackDF t ds (n - 1) (DataFrame t (d : ds)))
 -> c (DataFrame t (d : ds)))
-> (c (DataFrame t ds
       -> PackDF t ds (n - 1) (DataFrame t (d : ds)))
    -> c (PackDF t ds (n - 1) (DataFrame t (d : ds))))
-> c (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds)))
-> c (DataFrame t (d : ds))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c (DataFrame t ds -> PackDF t ds (n - 1) (DataFrame t (d : ds)))
-> c (PackDF t ds (n - 1) (DataFrame t (d : ds)))
forall r. c (DataFrame t ds -> r) -> c r
k


-- Parameter Int# here is an element offset, it should not be used at the call site.
unpackDF' :: forall (rep :: RuntimeRep)
                    (t :: Type) (d :: Nat) (ds :: [Nat]) (r :: TYPE rep)
           . (PrimBytes t, Dimensions (d ': ds))
          => ( Dict (Dimensions ds, KnownBackend t ds)
               -> (forall (zRep :: RuntimeRep) (z :: TYPE zRep)
                          . (Int -> DataFrame t ds -> z) -> Int -> z)
               -> Int -> r)
          -> DataFrame t (d ': ds)
          -> r
unpackDF' :: (Dict (Dimensions ds, KnownBackend t ds)
 -> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
 -> Int
 -> r)
-> DataFrame t (d : ds) -> r
unpackDF' Dict (Dimensions ds, KnownBackend t ds)
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z) -> Int -> r
k
  | Dim y
d :* Dims ys
Dims <- Dimensions (d : ds) => TypedList Dim (d : ds)
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @(d ': ds)
  , Dict (KnownBackends t (d : ds))
Dict <- InferKnownBackend t (d : ds) => Dict (KnownBackends t (d : ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(d ': ds)
  , Dict (KnownBackends t ds)
Dict <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
    = (t -> r)
-> (CumulDims -> Int# -> ByteArray# -> r)
-> DataFrame t (d : ds)
-> r
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent
    ( \t
x ->
      let e :: DataFrame t ds
e = t -> DataFrame t ds
forall t a. PrimArray t a => t -> a
broadcast t
x
          f :: forall (zr :: RuntimeRep) (z :: TYPE zr)
             . (Int -> DataFrame t ds -> z) -> Int -> z
          f :: (Int -> DataFrame t ds -> z) -> Int -> z
f Int -> DataFrame t ds -> z
consume = (Int -> DataFrame t ds -> z
`consume` DataFrame t ds
e)
      in Dict (Dimensions ds, KnownBackend t ds)
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z) -> Int -> r
k Dict (Dimensions ds, KnownBackend t ds)
forall (a :: Constraint). a => Dict a
Dict forall z. (Int -> DataFrame t ds -> z) -> Int -> z
f Int
0
    )
    ( \CumulDims
cdims Int#
off ByteArray#
arr ->
      let cd :: CumulDims
cd = [Word] -> CumulDims
CumulDims ([Word] -> CumulDims) -> ([Word] -> [Word]) -> [Word] -> CumulDims
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word] -> [Word]
forall a. [a] -> [a]
tail ([Word] -> CumulDims) -> [Word] -> CumulDims
forall a b. (a -> b) -> a -> b
$ CumulDims -> [Word]
unCumulDims CumulDims
cdims
          td :: Int#
td = CumulDims -> Int#
cdTotalDim# CumulDims
cd
          n :: Int#
n = case Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
d of W# Word#
w -> Word# -> Int#
word2Int# Word#
w
          f :: forall (zr :: RuntimeRep) (z :: TYPE zr)
             . (Int -> DataFrame t ds -> z) -> Int -> z
          f :: (Int -> DataFrame t ds -> z) -> Int -> z
f Int -> DataFrame t ds -> z
consume (I# Int#
o) = Int -> DataFrame t ds -> z
consume (Int# -> Int
I# (Int#
o Int# -> Int# -> Int#
-# Int#
td)) (CumulDims -> Int# -> ByteArray# -> DataFrame t ds
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
cd Int#
o ByteArray#
arr)
      in Dict (Dimensions ds, KnownBackend t ds)
-> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z) -> Int -> r
k Dict (Dimensions ds, KnownBackend t ds)
forall (a :: Constraint). a => Dict a
Dict forall z. (Int -> DataFrame t ds -> z) -> Int -> z
f (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
td Int# -> Int# -> Int#
*# (Int#
n Int# -> Int# -> Int#
-# Int#
1#)))
    )
  | Bool
otherwise = String -> DataFrame t (d : ds) -> r
forall a. HasCallStack => String -> a
error String
"Numeric.DataFrame.Type.unpackDF: impossible arguments"


-- | Append one DataFrame to another, sum up the first dimension.
--
--   If you want to deconstruct a DataFrame, use
--       `Numeric.DataFrame.SubSpace.index`
--    or `Numeric.DataFrame.SubSpace.slice` instead.
appendDF :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type)
       . ( PrimBytes t, Dimensions ds, KnownDim n, KnownDim m )
        => DataFrame t (n :+ ds)
        -> DataFrame t (m :+ ds)
        -> DataFrame t ((n + m) :+ ds)
appendDF :: DataFrame t (n :+ ds)
-> DataFrame t (m :+ ds) -> DataFrame t ((n + m) :+ ds)
appendDF
  | Dim (n + m)
D <- (KnownDimType n, Nat ~ Nat, KnownDim n) => Dim n
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @n Dim n -> Dim m -> Dim (n + m)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (n + m)
`plusDim` (KnownDimType m, Nat ~ Nat, KnownDim m) => Dim m
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @m
  , Dict (KnownBackends t (n :+ ds))
Dict <- InferKnownBackend t (n :+ ds) => Dict (KnownBackends t (n :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n :+ ds)
  , Dict (KnownBackends t (m :+ ds))
Dict <- InferKnownBackend t (m :+ ds) => Dict (KnownBackends t (m :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(m :+ ds)
  , Dict (KnownBackends t ((n + m) :+ ds))
Dict <- InferKnownBackend t ((n + m) :+ ds) =>
Dict (KnownBackends t ((n + m) :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @((n + m) :+ ds)
              = DataFrame t (n :+ ds)
-> DataFrame t (m :+ ds) -> DataFrame t ((n + m) :+ ds)
forall x y z.
(PrimBytes x, PrimBytes y, PrimBytes z) =>
x -> y -> z
unsafeAppendPB
#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
  | Bool
otherwise = String
-> DataFrame t (n :+ ds)
-> DataFrame t (m :+ ds)
-> DataFrame t ((n + m) :+ ds)
forall a. HasCallStack => String -> a
error String
"Numeri.DataFrame.Type.appendDF: impossible arguments"
#endif

-- | Append a small DataFrame to a big DataFrame on the left.
--
--   If you want to deconstruct a DataFrame, use
--       `Numeric.DataFrame.SubSpace.index`
--    or `Numeric.DataFrame.SubSpace.slice` instead.
consDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type)
       . ( PrimBytes t, Dimensions ds, KnownDim n )
        => DataFrame t ds
        -> DataFrame t (n :+ ds)
        -> DataFrame t ((n + 1) :+ ds)
consDF :: DataFrame t ds
-> DataFrame t (n :+ ds) -> DataFrame t ((n + 1) :+ ds)
consDF
  | Dim (n + 1)
D <- (KnownDimType n, Nat ~ Nat, KnownDim n) => Dim n
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @n Dim n -> Dim 1 -> Dim (n + 1)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (n + m)
`plusDim` Dim 1
forall (n :: Nat). (n ~ 1) => Dim n
D1
  , Dict (KnownBackends t (n :+ ds))
Dict <- InferKnownBackend t (n :+ ds) => Dict (KnownBackends t (n :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n :+ ds)
  , Dict (KnownBackends t ds)
Dict <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
  , Dict (KnownBackends t ((n + 1) :+ ds))
Dict <- InferKnownBackend t ((n + 1) :+ ds) =>
Dict (KnownBackends t ((n + 1) :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @((n + 1) :+ ds)
              = DataFrame t ds
-> DataFrame t (n :+ ds) -> DataFrame t ((n + 1) :+ ds)
forall x y z.
(PrimBytes x, PrimBytes y, PrimBytes z) =>
x -> y -> z
unsafeAppendPB
#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
  | Bool
otherwise = String
-> DataFrame t ds
-> DataFrame t (n :+ ds)
-> DataFrame t ((n + 1) :+ ds)
forall a. HasCallStack => String -> a
error String
"Numeri.DataFrame.Type.consDF: impossible arguments"
#endif

-- | Append a small DataFrame to a big DataFrame on the right.
--
--   If you want to deconstruct a DataFrame, use
--       `Numeric.DataFrame.SubSpace.index`
--    or `Numeric.DataFrame.SubSpace.slice` instead.
snocDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type)
       . ( PrimBytes t, Dimensions ds, KnownDim n )
        => DataFrame t (n :+ ds)
        -> DataFrame t ds
        -> DataFrame t ((n + 1) :+ ds)
snocDF :: DataFrame t (n :+ ds)
-> DataFrame t ds -> DataFrame t ((n + 1) :+ ds)
snocDF
  | Dim (n + 1)
D <- (KnownDimType n, Nat ~ Nat, KnownDim n) => Dim n
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @n Dim n -> Dim 1 -> Dim (n + 1)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (n + m)
`plusDim` Dim 1
forall (n :: Nat). (n ~ 1) => Dim n
D1
  , Dict (KnownBackends t (n :+ ds))
Dict <- InferKnownBackend t (n :+ ds) => Dict (KnownBackends t (n :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n :+ ds)
  , Dict (KnownBackends t ds)
Dict <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
  , Dict (KnownBackends t ((n + 1) :+ ds))
Dict <- InferKnownBackend t ((n + 1) :+ ds) =>
Dict (KnownBackends t ((n + 1) :+ ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @((n + 1) :+ ds)
              = DataFrame t (n :+ ds)
-> DataFrame t ds -> DataFrame t ((n + 1) :+ ds)
forall x y z.
(PrimBytes x, PrimBytes y, PrimBytes z) =>
x -> y -> z
unsafeAppendPB
#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
  | Bool
otherwise = String
-> DataFrame t (n :+ ds)
-> DataFrame t ds
-> DataFrame t ((n + 1) :+ ds)
forall a. HasCallStack => String -> a
error String
"Numeri.DataFrame.Type.snocDF: impossible arguments"
#endif

-- | Unsafely copy two PrimBytes values into a third one.
unsafeAppendPB :: forall x y z
                . (PrimBytes x, PrimBytes y, PrimBytes z)
               => x -> y -> z
unsafeAppendPB :: x -> y -> z
unsafeAppendPB x
x y
y = Int# -> Int# -> z
go (x -> Int#
forall a. PrimBytes a => a -> Int#
byteSize x
x) (y -> Int#
forall a. PrimBytes a => a -> Int#
byteSize y
y)
  where
    go :: Int# -> Int# -> z
    go :: Int# -> Int# -> z
go Int#
0# Int#
_  = Int# -> ByteArray# -> z
forall a. PrimBytes a => Int# -> ByteArray# -> a
fromBytes (y -> Int#
forall a. PrimBytes a => a -> Int#
byteOffset y
y) (y -> ByteArray#
forall a. PrimBytes a => a -> ByteArray#
getBytes y
y)
    go Int#
_  Int#
0# = Int# -> ByteArray# -> z
forall a. PrimBytes a => Int# -> ByteArray# -> a
fromBytes (x -> Int#
forall a. PrimBytes a => a -> Int#
byteOffset x
x) (x -> ByteArray#
forall a. PrimBytes a => a -> ByteArray#
getBytes x
x)
    go Int#
sx Int#
sy = case (State# RealWorld -> (# State# RealWorld, ByteArray# #))
-> (# State# RealWorld, ByteArray# #)
forall o. (State# RealWorld -> o) -> o
runRW#
      ( \State# RealWorld
s0 -> case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# (Int#
sx Int# -> Int# -> Int#
+# Int#
sy) State# RealWorld
s0 of
          (# State# RealWorld
s1, MutableByteArray# RealWorld
mba #) -> MutableByteArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, ByteArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# RealWorld
mba
              ( MutableByteArray# RealWorld
-> Int# -> y -> State# RealWorld -> State# RealWorld
forall a s.
PrimBytes a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeBytes MutableByteArray# RealWorld
mba Int#
sx y
y
              ( MutableByteArray# RealWorld
-> Int# -> x -> State# RealWorld -> State# RealWorld
forall a s.
PrimBytes a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeBytes MutableByteArray# RealWorld
mba Int#
0# x
x State# RealWorld
s1))
      ) of (# State# RealWorld
_, ByteArray#
r #) -> Int# -> ByteArray# -> z
forall a. PrimBytes a => Int# -> ByteArray# -> a
fromBytes Int#
0# ByteArray#
r

-- | Construct a DataFrame from a list of smaller DataFrames.
--
--
--   If the argument list is shorter than @d@, then the rest of the frame
--   is padded with a default value (first argument).
--
--   If the argument list is longer than @d@, then unused values are dropped.
--   If you want, you can pass an infinite list as an argument.
fromListWithDefault :: forall (t :: Type) (d :: Nat) (ds :: [Nat])
                     . (PrimBytes t, Dimensions (d ': ds))
                    => DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d ': ds)
fromListWithDefault :: DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d : ds)
fromListWithDefault DataFrame t ds
d [DataFrame t ds]
ds = ([DataFrame t ds], DataFrame t (d : ds)) -> DataFrame t (d : ds)
forall a b. (a, b) -> b
snd (([DataFrame t ds], DataFrame t (d : ds)) -> DataFrame t (d : ds))
-> ([DataFrame t ds], DataFrame t (d : ds)) -> DataFrame t (d : ds)
forall a b. (a -> b) -> a -> b
$ (forall r.
 ([DataFrame t ds], DataFrame t ds -> r) -> ([DataFrame t ds], r))
-> (forall r. r -> ([DataFrame t ds], r))
-> ([DataFrame t ds], DataFrame t (d : ds))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' forall r.
([DataFrame t ds], DataFrame t ds -> r) -> ([DataFrame t ds], r)
f ((,) [DataFrame t ds]
ds)
  where
    f :: forall r . ([DataFrame t ds], DataFrame t ds -> r) -> ([DataFrame t ds], r)
    f :: ([DataFrame t ds], DataFrame t ds -> r) -> ([DataFrame t ds], r)
f ([] ,  DataFrame t ds -> r
k) = ([], DataFrame t ds -> r
k DataFrame t ds
d)
    f (DataFrame t ds
x:[DataFrame t ds]
xs, DataFrame t ds -> r
k) = ([DataFrame t ds]
xs, DataFrame t ds -> r
k DataFrame t ds
x)

-- | Construct a dynamic DataFrame from a list of smaller DataFrames.
--   Pattern-match against the resulting @XFrame@ to find out its dimensionality.
--
--   You must not provide an infinite list as an argument.
fromList :: forall (t :: Type) (ds :: [Nat]) (xds :: [XNat])
          . (PrimBytes t, Dimensions ds, xds ~ Map N ds, ds ~ UnMap N xds)
         => [DataFrame t ds] -> DataFrame t (XN 0 ': xds)
fromList :: [DataFrame t ds] -> DataFrame t (XN 0 : xds)
fromList [DataFrame t ds]
xs
    | Dx (Dim n
D :: Dim n) <- Word -> SomeDim
someDimVal (Word -> SomeDim) -> (Int -> Word) -> Int -> SomeDim
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> SomeDim) -> Int -> SomeDim
forall a b. (a -> b) -> a -> b
$ [DataFrame t ds] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DataFrame t ds]
xs
    , Dict (ds ~ UnMap N xds)
Dict <- (ds ~ UnMap N xds) => Dict (ds ~ UnMap N xds)
forall (a :: Constraint). a => Dict a
Dict @(ds ~ UnMap N xds) -- just to make GHC not complain about unused constraints.
    , Dict (KnownBackends t (n : ds))
Dict <- InferKnownBackend t (n : ds) => Dict (KnownBackends t (n : ds))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(n ': ds)
    , Dict (ds ~ DimsBound xds)
Dict <- Dict (ds ~ DimsBound xds)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @_ @ds @(DimsBound xds)
    , Dict (All KnownDimType xds, FixedDims xds (DimsBound xds))
Dict <- Dims (DimsBound xds)
-> Dict (All KnownDimType xds, FixedDims xds (DimsBound xds))
forall (ds :: [XNat]).
ExactDims ds =>
Dims (DimsBound ds)
-> Dict (All KnownDimType ds, FixedDims ds (DimsBound ds))
inferExactFixedDims (Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds)
      = DataFrame t (n : ds) -> DataFrame t (XN 0 : xds)
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame (DataFrame t ds -> [DataFrame t ds] -> DataFrame t (n : ds)
forall t (d :: Nat) (ds :: [Nat]).
(PrimBytes t, Dimensions (d : ds)) =>
DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d : ds)
fromListWithDefault @t @n @ds DataFrame t ds
forall a. HasCallStack => a
undefined [DataFrame t ds]
xs)
#if !MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
    | Bool
otherwise
      = String -> DataFrame t (XN 0 : xds)
forall a. HasCallStack => String -> a
error String
"Numeri.DataFrame.Type.fromList: impossible arguments"
#endif

-- | Try to convert between @XNat@-indexed DataFrames.
--
--   This is useful for imposing restrictions on unknown DataFrames,
--   e.g. increasing the minimum number of elements.
constrainDF :: forall (ds :: [XNat]) (ys :: [XNat]) t
             . (BoundedDims ds, All KnownDimType ds)
            => DataFrame t ys -> Maybe (DataFrame t ds)
constrainDF :: DataFrame t ys -> Maybe (DataFrame t ds)
constrainDF (XFrame (df :: DataFrame t ns))
  | Dims ns
ns <- Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ns
  = case Dims ns -> Maybe (Dims ds)
forall k (ds :: [k]) k1 (ys :: [k1]).
BoundedDims ds =>
Dims ys -> Maybe (Dims ds)
constrainDims @ds Dims ns
ns of
      Just (XDims (Dims ns
Dims :: Dims ms))
        | Dict (ns ~ ns)
Dict <- Dict (ns ~ ns)
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @[Nat] @ns @ms
          -> DataFrame t ds -> Maybe (DataFrame t ds)
forall a. a -> Maybe a
Just (DataFrame t ds -> Maybe (DataFrame t ds))
-> DataFrame t ds -> Maybe (DataFrame t ds)
forall a b. (a -> b) -> a -> b
$ DataFrame t ns -> DataFrame t ds
forall l (ts :: l) (xns :: [XNat]) (ns :: [Nat]).
(All KnownDimType xns, FixedDims xns ns, Dimensions ns,
 KnownBackends ts ns) =>
DataFrame ts ns -> DataFrame ts xns
XFrame DataFrame t ns
df
      Maybe (Dims ds)
_   -> Maybe (DataFrame t ds)
forall a. Maybe a
Nothing

-- | Place elements of a vector on the main diagonal of a matrix;
--   fill the rest of the matrix with zeroes.
--
--   Note, this function is naturally generalized onto higher dimensions
--    (which can be seen from the type signature).
--
--   Note, the argument of this function does not fully determine its result type.
--   This may cause some obscure type errors.
--   Specify type parameters @n@ and @m@ explicitly or make sure the result type is fixed.
asDiag :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type)
        . ( Dimensions ds, KnownDim n, KnownDim m
          , KnownBackend t (Min n m :+ ds)
          , KnownBackend t (n :+ m :+ ds)
          , PrimBytes t)
       => DataFrame t (Min n m :+ ds)
       -> DataFrame t (n :+ m :+ ds)
asDiag :: DataFrame t (Min n m :+ ds) -> DataFrame t (n :+ (m :+ ds))
asDiag DataFrame t (Min n m :+ ds)
x
  | Int#
elemSize <- t -> Int#
forall a. PrimBytes a => a -> Int#
byteSize @t t
forall a. HasCallStack => a
undefined
  , dMinNM :: Dim (Min n m)
dMinNM@Dim (Min n m)
D <- Dim n -> Dim m -> Dim (Min n m)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (Min n m)
minDim ((KnownDimType n, Nat ~ Nat, KnownDim n) => Dim n
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @n) ((KnownDimType m, Nat ~ Nat, KnownDim m) => Dim m
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @m)
  , ByteArray#
xba <- DataFrame t (Min n m :+ ds) -> ByteArray#
forall a. PrimBytes a => a -> ByteArray#
getBytes DataFrame t (Min n m :+ ds)
x
  , Dims ds
ds <- Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds
  , steps :: CumulDims
steps@(CumulDims (Word
elemsNR:Word
_:Word
elemsNE:[Word]
_)) <- Dims (n :+ (m :+ ds)) -> CumulDims
forall k (ns :: [k]). Dims ns -> CumulDims
cumulDims ((KnownDimType n, Nat ~ Nat, KnownDim n) => Dim n
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @n Dim n -> TypedList Dim (m :+ ds) -> Dims (n :+ (m :+ ds))
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* (KnownDimType m, Nat ~ Nat, KnownDim m) => Dim m
forall k (d :: k). (KnownDimType d, k ~ Nat, KnownDim d) => Dim d
D @m Dim m -> Dims ds -> TypedList Dim (m :+ ds)
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* Dims ds
ds)
  , Word
m <- KnownDim m => Word
forall k (n :: k). KnownDim n => Word
dimVal' @m
  , Int#
bsE <- case Word
elemsNE of W# Word#
w -> Word# -> Int#
word2Int# Word#
w Int# -> Int# -> Int#
*# Int#
elemSize
  , Int#
bsR <- case Word
elemsNR of W# Word#
w -> Word# -> Int#
word2Int# Word#
w Int# -> Int# -> Int#
*# Int#
elemSize
  , Int#
bsShift <- case Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1 of W# Word#
w -> Word# -> Int#
word2Int# Word#
w Int# -> Int# -> Int#
*# Int#
bsE
  , Int#
bsLim <- case Word
m Word -> Word -> Word
forall a. Num a => a -> a -> a
* Dim (Min n m) -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim (Min n m)
dMinNM of W# Word#
w -> Word# -> Int#
word2Int# Word#
w Int# -> Int# -> Int#
*# Int#
bsE
    = case (State# RealWorld -> (# State# RealWorld, ByteArray# #))
-> (# State# RealWorld, ByteArray# #)
forall o. (State# RealWorld -> o) -> o
runRW#
      ( \State# RealWorld
s0 -> case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
bsR State# RealWorld
s0 of
          (# State# RealWorld
s1, MutableByteArray# RealWorld
mba #) ->
            let go :: Int# -> Int# -> State# RealWorld -> State# RealWorld
go Int#
offSrc Int#
offDst State# RealWorld
s
                  | Int# -> Bool
isTrue# (Int#
offDst Int# -> Int# -> Int#
>=# Int#
bsLim) = State# RealWorld
s
                  | Bool
otherwise = Int# -> Int# -> State# RealWorld -> State# RealWorld
go (Int#
offSrc Int# -> Int# -> Int#
+# Int#
bsE) (Int#
offDst Int# -> Int# -> Int#
+# Int#
bsShift)
                      (ByteArray#
-> Int#
-> MutableByteArray# RealWorld
-> Int#
-> Int#
-> State# RealWorld
-> State# RealWorld
forall d.
ByteArray#
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyByteArray# ByteArray#
xba Int#
offSrc MutableByteArray# RealWorld
mba Int#
offDst Int#
bsE State# RealWorld
s)
            in  MutableByteArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, ByteArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# RealWorld
mba
                  (Int# -> Int# -> State# RealWorld -> State# RealWorld
go (DataFrame t (Min n m :+ ds) -> Int#
forall a. PrimBytes a => a -> Int#
byteOffset DataFrame t (Min n m :+ ds)
x) Int#
0# (MutableByteArray# RealWorld
-> Int# -> Int# -> Int# -> State# RealWorld -> State# RealWorld
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# RealWorld
mba Int#
0# Int#
bsR Int#
0# State# RealWorld
s1))

      ) of (# State# RealWorld
_, ByteArray#
r #) -> CumulDims -> Int# -> ByteArray# -> DataFrame t (n :+ (m :+ ds))
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
steps Int#
0# ByteArray#
r
  | Bool
otherwise
    = String -> DataFrame t (n :+ (m :+ ds))
forall a. HasCallStack => String -> a
error String
"Numeri.DataFrame.Type.asDiag: impossible arguments"
{-# INLINE asDiag #-}

-- Need this for @packDF'@ to make @Int -> c z@ a proper second-order type
-- parameterized by the result type.
newtype Off c z = Off { Off c z -> Int -> c z
runOff :: Int -> c z }

-- | Term-level structure of a @SingleFrame t ds@ is fully determined by its
--   type dimensionality @Typeable ds@.
--   Thus, @gunfold@ does not use its last argument (@Constr@) at all,
--   relying on the structure of the type parameter.
instance (Data t, PrimBytes t, Typeable ds)
      => Data (DataFrame (t :: Type) (ds :: [Nat])) where
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DataFrame t ds -> c (DataFrame t ds)
gfoldl forall d b. Data d => c (d -> b) -> d -> c b
k forall g. g -> c g
z DataFrame t ds
v = case Typeable ds => Dims ds
forall (ds :: [Nat]). Typeable ds => Dims ds
typeableDims @ds of
      Dims ds
U | S x <- DataFrame t ds
v
        -> (t -> DataFrame t '[]) -> c (t -> DataFrame t '[])
forall g. g -> c g
z t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S c (t -> DataFrame t '[]) -> t -> c (DataFrame t '[])
forall d b. Data d => c (d -> b) -> d -> c b
`k` t
x
      Dim y
D :* (Dims ys
Dims :: Dims ns)
        -> case forall k (ys :: [k]) (x :: k) (xs :: [k]).
(Typeable ys, ys ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
forall (x :: Nat) (xs :: [Nat]).
(Typeable ds, ds ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
inferTypeableCons @ds of
          Dict (Typeable y, Typeable ys)
Dict ->
            -- PLZ don't ask me how does this work
            (Dict (Dimensions ys, KnownBackend t ys)
 -> (forall z. (Int -> DataFrame t ys -> z) -> Int -> z)
 -> Int
 -> c (DataFrame t (y : ys)))
-> DataFrame t (y : ys) -> c (DataFrame t (y : ys))
forall t (d :: Nat) (ds :: [Nat]) r.
(PrimBytes t, Dimensions (d : ds)) =>
(Dict (Dimensions ds, KnownBackend t ds)
 -> (forall z. (Int -> DataFrame t ds -> z) -> Int -> z)
 -> Int
 -> r)
-> DataFrame t (d : ds) -> r
unpackDF' (\Dict (Dimensions ys, KnownBackend t ys)
_ forall z. (Int -> DataFrame t ys -> z) -> Int -> z
f -> Off c (DataFrame t (y : ys)) -> Int -> c (DataFrame t (y : ys))
forall k (c :: k -> *) (z :: k). Off c z -> Int -> c z
runOff (Off c (DataFrame t (y : ys)) -> Int -> c (DataFrame t (y : ys)))
-> Off c (DataFrame t (y : ys)) -> Int -> c (DataFrame t (y : ys))
forall a b. (a -> b) -> a -> b
$ (forall r. Off c (DataFrame t ys -> r) -> Off c r)
-> (forall r. r -> Off c r) -> Off c (DataFrame t (y : ys))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF'
                           (\Off c (DataFrame t ys -> r)
g -> (Int -> c r) -> Off c r
forall k (c :: k -> *) (z :: k). (Int -> c z) -> Off c z
Off ((Int -> c r) -> Off c r)
-> ((Int -> DataFrame t ys -> c r) -> Int -> c r)
-> (Int -> DataFrame t ys -> c r)
-> Off c r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> DataFrame t ys -> c r) -> Int -> c r
forall z. (Int -> DataFrame t ys -> z) -> Int -> z
f ((Int -> DataFrame t ys -> c r) -> Off c r)
-> (Int -> DataFrame t ys -> c r) -> Off c r
forall a b. (a -> b) -> a -> b
$ c (DataFrame t ys -> r) -> DataFrame t ys -> c r
forall d b. Data d => c (d -> b) -> d -> c b
k (c (DataFrame t ys -> r) -> DataFrame t ys -> c r)
-> (Int -> c (DataFrame t ys -> r)) -> Int -> DataFrame t ys -> c r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Off c (DataFrame t ys -> r) -> Int -> c (DataFrame t ys -> r)
forall k (c :: k -> *) (z :: k). Off c z -> Int -> c z
runOff Off c (DataFrame t ys -> r)
g)
                           ((Int -> c r) -> Off c r
forall k (c :: k -> *) (z :: k). (Int -> c z) -> Off c z
Off ((Int -> c r) -> Off c r) -> (r -> Int -> c r) -> r -> Off c r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c r -> Int -> c r
forall a b. a -> b -> a
const (c r -> Int -> c r) -> (r -> c r) -> r -> Int -> c r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c r
forall g. g -> c g
z)
                       ) DataFrame t ds
DataFrame t (y : ys)
v
#if IS_UNSOUND_MATCHING_810_900
      Dims ds
_ -> String -> c (DataFrame t ds)
forall a. HasCallStack => String -> a
error String
"DataFrame.gfoldl: impossible arguments"
#endif
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (DataFrame t ds)
gunfold forall b r. Data b => c (b -> r) -> c r
k forall r. r -> c r
z Constr
_ = case Typeable ds => Dims ds
forall (ds :: [Nat]). Typeable ds => Dims ds
typeableDims @ds of
      Dims ds
U      -> c (t -> DataFrame t '[]) -> c (DataFrame t '[])
forall b r. Data b => c (b -> r) -> c r
k ((t -> DataFrame t '[]) -> c (t -> DataFrame t '[])
forall r. r -> c r
z t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S)
      Dim y
D :* (Dims ys
Dims :: Dims ns)
        -> case forall k (ys :: [k]) (x :: k) (xs :: [k]).
(Typeable ys, ys ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
forall (x :: Nat) (xs :: [Nat]).
(Typeable ds, ds ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
inferTypeableCons @ds of Dict (Typeable y, Typeable ys)
Dict -> (forall r. c (DataFrame t ys -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (y : ys))
forall t (d :: Nat) (ds :: [Nat]) (c :: * -> *).
(PrimBytes t, Dimensions (d : ds)) =>
(forall r. c (DataFrame t ds -> r) -> c r)
-> (forall r. r -> c r) -> c (DataFrame t (d : ds))
packDF' forall r. c (DataFrame t ys -> r) -> c r
forall b r. Data b => c (b -> r) -> c r
k forall r. r -> c r
z
#if IS_UNSOUND_MATCHING_810_900
      Dims ds
_ -> String -> c (DataFrame t ds)
forall a. HasCallStack => String -> a
error String
"DataFrame.gunfold: impossible arguments"
#endif
    toConstr :: DataFrame t ds -> Constr
toConstr DataFrame t ds
_ = case Typeable ds => Dims ds
forall (ds :: [Nat]). Typeable ds => Dims ds
typeableDims @ds of
      Dims ds
U      -> Constr
scalarFrameConstr
      Dim y
d :* TypedList Dim ys
_ -> Word -> Constr
singleFrameConstr (Word -> Constr) -> Word -> Constr
forall a b. (a -> b) -> a -> b
$ Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
d
    dataTypeOf :: DataFrame t ds -> DataType
dataTypeOf DataFrame t ds
_ = case Typeable ds => Dims ds
forall (ds :: [Nat]). Typeable ds => Dims ds
typeableDims @ds of
      Dims ds
U      -> [Constr] -> DataType
dataFrameDataType [Constr
scalarFrameConstr]
      Dim y
d :* TypedList Dim ys
_ -> [Constr] -> DataType
dataFrameDataType ([Constr] -> DataType) -> (Word -> [Constr]) -> Word -> DataType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Constr -> [Constr] -> [Constr]
forall a. a -> [a] -> [a]
:[])(Constr -> [Constr]) -> (Word -> Constr) -> Word -> [Constr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Constr
singleFrameConstr (Word -> DataType) -> Word -> DataType
forall a b. (a -> b) -> a -> b
$ Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
d

-- | Term-level structure of a @MultiFrame ts@ is fully determined by its
--   type @Typeable ts@.
--   Thus, @gunfold@ does not use its last argument (@Constr@) at all,
--   relying on the structure of the type parameter.
instance (AllFrames Data ts ds, Typeable ts, Typeable ds)
      => Data (DataFrame (ts :: [Type]) (ds :: [Nat])) where
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DataFrame ts ds -> c (DataFrame ts ds)
gfoldl forall d b. Data d => c (d -> b) -> d -> c b
_ forall g. g -> c g
z DataFrame ts ds
Z = DataFrame ts ds -> c (DataFrame ts ds)
forall g. g -> c g
z DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z
    gfoldl forall d b. Data d => c (d -> b) -> d -> c b
k forall g. g -> c g
z (DataFrame y ds
x :*: DataFrame ys ds
xs) = case forall k (ys :: [k]) (x :: k) (xs :: [k]).
(Typeable ys, ys ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
forall x (xs :: [*]).
(Typeable ts, ts ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
inferTypeableCons @ts of
      Dict (Typeable y, Typeable ys)
Dict -> (DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
-> c (DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
forall g. g -> c g
z DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
(:*:) c (DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
-> DataFrame y ds -> c (DataFrame ys ds -> DataFrame ts ds)
forall d b. Data d => c (d -> b) -> d -> c b
`k` DataFrame y ds
x c (DataFrame ys ds -> DataFrame ts ds)
-> DataFrame ys ds -> c (DataFrame ts ds)
forall d b. Data d => c (d -> b) -> d -> c b
`k` DataFrame ys ds
xs
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (DataFrame ts ds)
gunfold forall b r. Data b => c (b -> r) -> c r
k forall r. r -> c r
z Constr
_ = case Typeable ts => TypeList ts
forall k (xs :: [k]). Typeable xs => TypeList xs
typeables @ts of
      TypeList ts
U      -> DataFrame ts ds -> c (DataFrame ts ds)
forall r. r -> c r
z DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z
      Proxy y
_ :* TypedList Proxy ys
_ -> case forall k (ys :: [k]) (x :: k) (xs :: [k]).
(Typeable ys, ys ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
forall x (xs :: [*]).
(Typeable ts, ts ~ (x : xs)) =>
Dict (Typeable x, Typeable xs)
inferTypeableCons @ts of Dict (Typeable y, Typeable ys)
Dict -> c (DataFrame ys ds -> DataFrame ts ds) -> c (DataFrame ts ds)
forall b r. Data b => c (b -> r) -> c r
k (c (DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
-> c (DataFrame ys ds -> DataFrame ts ds)
forall b r. Data b => c (b -> r) -> c r
k ((DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
-> c (DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds)
forall r. r -> c r
z DataFrame y ds -> DataFrame ys ds -> DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
(:*:)))
    toConstr :: DataFrame ts ds -> Constr
toConstr DataFrame ts ds
Z         = Constr
multiFrameZConstr
    toConstr (DataFrame y ds
_ :*: DataFrame ys ds
_) = Constr
multiFrameConsConstr
    dataTypeOf :: DataFrame ts ds -> DataType
dataTypeOf DataFrame ts ds
_ = [Constr] -> DataType
dataFrameDataType [Constr
multiFrameZConstr, Constr
multiFrameConsConstr]


dataFrameDataType :: [Constr] -> DataType
dataFrameDataType :: [Constr] -> DataType
dataFrameDataType = String -> [Constr] -> DataType
mkDataType String
"Numeric.DataFrame.Type.DataFrame"

scalarFrameConstr :: Constr
scalarFrameConstr :: Constr
scalarFrameConstr
  = DataType -> String -> [String] -> Fixity -> Constr
mkConstr ([Constr] -> DataType
dataFrameDataType [Constr
scalarFrameConstr]) String
"S" [] Fixity
Prefix

singleFrameConstr :: Word -> Constr
singleFrameConstr :: Word -> Constr
singleFrameConstr Word
d
  = DataType -> String -> [String] -> Fixity -> Constr
mkConstr ([Constr] -> DataType
dataFrameDataType [Word -> Constr
singleFrameConstr Word
d]) (String
"DF" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word -> String
forall a. Show a => a -> String
show Word
d) [] Fixity
Prefix

multiFrameZConstr :: Constr
multiFrameZConstr :: Constr
multiFrameZConstr = DataType -> String -> [String] -> Fixity -> Constr
mkConstr
     ([Constr] -> DataType
dataFrameDataType [Constr
multiFrameZConstr, Constr
multiFrameConsConstr])
     String
"Z" [] Fixity
Prefix

multiFrameConsConstr :: Constr
multiFrameConsConstr :: Constr
multiFrameConsConstr = DataType -> String -> [String] -> Fixity -> Constr
mkConstr
     ([Constr] -> DataType
dataFrameDataType [Constr
multiFrameZConstr, Constr
multiFrameConsConstr])
     String
":*:" [] Fixity
Infix


type DFMetaSel = 'G.MetaSel
  'Nothing 'G.NoSourceUnpackedness 'G.NoSourceStrictness 'G.DecidedLazy

type family DFTree (t :: Type) (ds :: [Nat]) (d :: Nat) where
  DFTree t ds 0 = G.U1
  DFTree t ds 1 = G.S1 DFMetaSel (G.Rec0 (DataFrame t ds))
  DFTree t ds n = DFTree t ds (Div n 2) G.:*: DFTree t ds (Div n 2 + Mod n 2)

type family SingleFrameRep (t :: Type) (ds :: [Nat]) :: (Type -> Type) where
  SingleFrameRep t '[]
    = G.C1 ('G.MetaCons "S" 'G.PrefixI 'False) (G.S1 DFMetaSel (G.Rec0 t))
  SingleFrameRep t (d ': ds)
    = G.C1 ('G.MetaCons (AppendSymbol "DF" (ShowNat d)) 'G.PrefixI 'False) (DFTree t ds d)

instance (PrimBytes t, Dimensions ds)
      => G.Generic (DataFrame (t :: Type) (ds :: [Nat])) where
    type Rep (DataFrame t ds) = G.D1
          ('G.MetaData "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
          ( SingleFrameRep t ds )
    from :: DataFrame t ds -> Rep (DataFrame t ds) x
from = SingleFrameRep t ds x
-> M1
     D
     ('MetaData
        "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
     (SingleFrameRep t ds)
     x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (SingleFrameRep t ds x
 -> M1
      D
      ('MetaData
         "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
      (SingleFrameRep t ds)
      x)
-> (DataFrame t ds -> SingleFrameRep t ds x)
-> DataFrame t ds
-> M1
     D
     ('MetaData
        "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
     (SingleFrameRep t ds)
     x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dims ds -> DataFrame t ds -> SingleFrameRep t ds x
forall t (ds :: [Nat]) x.
PrimBytes t =>
Dims ds -> DataFrame t ds -> SingleFrameRep t ds x
fromSingleFrame (Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds)
    to :: Rep (DataFrame t ds) x -> DataFrame t ds
to (G.M1 rep) = Dims ds -> SingleFrameRep t ds x -> DataFrame t ds
forall t (ds :: [Nat]) x.
PrimBytes t =>
Dims ds -> SingleFrameRep t ds x -> DataFrame t ds
toSingleFrame (Dimensions ds => Dims ds
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @ds) SingleFrameRep t ds x
rep

fromSingleFrame :: forall (t :: Type) (ds :: [Nat]) (x :: Type)
                 . PrimBytes t
                => Dims ds
                -> DataFrame t ds
                -> SingleFrameRep t ds x
fromSingleFrame :: Dims ds -> DataFrame t ds -> SingleFrameRep t ds x
fromSingleFrame Dims ds
U (S x) = M1 S DFMetaSel (K1 R t) x
-> M1 C ('MetaCons "S" 'PrefixI 'False) (M1 S DFMetaSel (K1 R t)) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (M1 S DFMetaSel (K1 R t) x
 -> M1
      C ('MetaCons "S" 'PrefixI 'False) (M1 S DFMetaSel (K1 R t)) x)
-> (K1 R t x -> M1 S DFMetaSel (K1 R t) x)
-> K1 R t x
-> M1 C ('MetaCons "S" 'PrefixI 'False) (M1 S DFMetaSel (K1 R t)) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. K1 R t x -> M1 S DFMetaSel (K1 R t) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (K1 R t x
 -> M1
      C ('MetaCons "S" 'PrefixI 'False) (M1 S DFMetaSel (K1 R t)) x)
-> K1 R t x
-> M1 C ('MetaCons "S" 'PrefixI 'False) (M1 S DFMetaSel (K1 R t)) x
forall a b. (a -> b) -> a -> b
$ t -> K1 R t x
forall k i c (p :: k). c -> K1 i c p
G.K1 t
x
fromSingleFrame (dd :: Dim y
dd@Dim y
D :* (Dims ys
Dims :: Dims ds')) DataFrame t ds
x
  | Dict (KnownBackends t ds)
Dict <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
  , Dict (KnownBackends t ys)
Dict <- InferKnownBackend t ys => Dict (KnownBackends t ys)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds'
    = DFTree t ys y x
-> M1
     C
     ('MetaCons (AppendSymbol "DF" (ShowNat y)) 'PrefixI 'False)
     (DFTree t ys y)
     x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (DFTree t ys y x
 -> M1
      C
      ('MetaCons (AppendSymbol "DF" (ShowNat y)) 'PrefixI 'False)
      (DFTree t ys y)
      x)
-> DFTree t ys y x
-> M1
     C
     ('MetaCons (AppendSymbol "DF" (ShowNat y)) 'PrefixI 'False)
     (DFTree t ys y)
     x
forall a b. (a -> b) -> a -> b
$ (t -> DFTree t ys y x)
-> (CumulDims -> Int# -> ByteArray# -> DFTree t ys y x)
-> DataFrame t ds
-> DFTree t ys y x
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent
        (\t
e -> (Word -> DataFrame t ys) -> Word -> Dim y -> DFTree t ys y x
forall (n :: Nat) (ns :: [Nat]).
(Word -> DataFrame t ns) -> Word -> Dim n -> DFTree t ns n x
fillRep @_ @ds' (DataFrame t ys -> Word -> DataFrame t ys
forall a b. a -> b -> a
const (DataFrame t ys -> Word -> DataFrame t ys)
-> DataFrame t ys -> Word -> DataFrame t ys
forall a b. (a -> b) -> a -> b
$ t -> DataFrame t ys
forall t a. PrimArray t a => t -> a
broadcast t
e) Word
0 Dim y
dd)
        (\CumulDims
cdims Int#
off ByteArray#
arr ->
           let cd :: CumulDims
cd = [Word] -> CumulDims
CumulDims ([Word] -> CumulDims) -> ([Word] -> [Word]) -> [Word] -> CumulDims
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word] -> [Word]
forall a. [a] -> [a]
tail ([Word] -> CumulDims) -> [Word] -> CumulDims
forall a b. (a -> b) -> a -> b
$ CumulDims -> [Word]
unCumulDims CumulDims
cdims
               td :: Int#
td = CumulDims -> Int#
cdTotalDim# CumulDims
cd
           in  (Word -> DataFrame t ys) -> Word -> Dim y -> DFTree t ys y x
forall (n :: Nat) (ns :: [Nat]).
(Word -> DataFrame t ns) -> Word -> Dim n -> DFTree t ns n x
fillRep @_ @ds'
                 (\(W# Word#
i) -> CumulDims -> Int# -> ByteArray# -> DataFrame t ys
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
cd (Int#
off Int# -> Int# -> Int#
+# Int#
td Int# -> Int# -> Int#
*# Word# -> Int#
word2Int# Word#
i) ByteArray#
arr) Word
0 Dim y
dd
        ) DataFrame t ds
x
  where
    fillRep :: forall (n :: Nat) (ns :: [Nat])
             . (Word -> DataFrame t ns)
            -> Word
            -> Dim n
            -> DFTree t ns n x
    fillRep :: (Word -> DataFrame t ns) -> Word -> Dim n -> DFTree t ns n x
fillRep Word -> DataFrame t ns
_ Word
_ Dim n
D0 = DFTree t ns n x
forall k (p :: k). U1 p
G.U1
    fillRep Word -> DataFrame t ns
f Word
i Dim n
D1 = K1 R (DataFrame t ns) x -> M1 S DFMetaSel (K1 R (DataFrame t ns)) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (K1 R (DataFrame t ns) x
 -> M1 S DFMetaSel (K1 R (DataFrame t ns)) x)
-> (DataFrame t ns -> K1 R (DataFrame t ns) x)
-> DataFrame t ns
-> M1 S DFMetaSel (K1 R (DataFrame t ns)) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame t ns -> K1 R (DataFrame t ns) x
forall k i c (p :: k). c -> K1 i c p
G.K1 (DataFrame t ns -> M1 S DFMetaSel (K1 R (DataFrame t ns)) x)
-> DataFrame t ns -> M1 S DFMetaSel (K1 R (DataFrame t ns)) x
forall a b. (a -> b) -> a -> b
$ Word -> DataFrame t ns
f Word
i
    fillRep Word -> DataFrame t ns
f Word
i Dim n
d
        | Dict
  (DFTree t ns n
   ~ (DFTree t ns (Div n 2) :*: DFTree t ns (Div n 2 + Mod n 2)))
Dict <- Dict
  (DFTree t ns n
   ~ (DFTree t ns (Div n 2) :*: DFTree t ns (Div n 2 + Mod n 2)))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @(Type -> Type)
            @(DFTree t ns n)
            @(DFTree t ns (Div n 2) G.:*: DFTree t ns (Div n 2 + Mod n 2))
          = (Word -> DataFrame t ns)
-> Word -> Dim (Div n 2) -> DFTree t ns (Div n 2) x
forall (n :: Nat) (ns :: [Nat]).
(Word -> DataFrame t ns) -> Word -> Dim n -> DFTree t ns n x
fillRep Word -> DataFrame t ns
f Word
i Dim (Div n 2)
d2 DFTree t ns (Div n 2) x
-> DFTree t ns (Div n 2 + Mod n 2) x
-> (:*:)
     (DFTree t ns (Div n 2)) (DFTree t ns (Div n 2 + Mod n 2)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
G.:*: (Word -> DataFrame t ns)
-> Word
-> Dim (Div n 2 + Mod n 2)
-> DFTree t ns (Div n 2 + Mod n 2) x
forall (n :: Nat) (ns :: [Nat]).
(Word -> DataFrame t ns) -> Word -> Dim n -> DFTree t ns n x
fillRep Word -> DataFrame t ns
f (Word
i Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Dim (Div n 2) -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim (Div n 2)
d2) Dim (Div n 2 + Mod n 2)
d2'
      where
        d2 :: Dim (Div n 2)
d2  = Dim n -> Dim 2 -> Dim (Div n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (Div n m)
divDim Dim n
d Dim 2
forall (n :: Nat). (n ~ 2) => Dim n
D2
        d2' :: Dim (Div n 2 + Mod n 2)
d2' = Dim (Div n 2)
d2 Dim (Div n 2) -> Dim (Mod n 2) -> Dim (Div n 2 + Mod n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (n + m)
`plusDim` Dim n -> Dim 2 -> Dim (Mod n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (Mod n m)
modDim Dim n
d Dim 2
forall (n :: Nat). (n ~ 2) => Dim n
D2
#if IS_UNSOUND_MATCHING_810_900
fromSingleFrame Dims ds
_ DataFrame t ds
_ = String -> SingleFrameRep t ds x
forall a. HasCallStack => String -> a
error String
"fromSingleFrame: impossible arguments"
#endif

toSingleFrame :: forall (t :: Type) (ds :: [Nat]) (x :: Type)
               . PrimBytes t
              => Dims ds
              -> SingleFrameRep t ds x
              -> DataFrame t ds
toSingleFrame :: Dims ds -> SingleFrameRep t ds x -> DataFrame t ds
toSingleFrame Dims ds
U (G.M1 (G.M1 (G.K1 x))) = t -> DataFrame t '[]
forall t. t -> DataFrame t '[]
S t
x
toSingleFrame (dd :: Dim y
dd@Dim y
D :* (Dims ys
Dims :: Dims ds')) (G.M1 rep)
  | Dict (KnownBackends t ds)
Dict  <- InferKnownBackend t ds => Dict (KnownBackends t ds)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds
  , Dict (KnownBackends t ys)
Dict  <- InferKnownBackend t ys => Dict (KnownBackends t ys)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @ds'
  , Int#
els   <- case Dim y -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim y
dd of W# Word#
w -> Word# -> Int#
word2Int# Word#
w
  , Int#
asize <- DataFrame t ys -> Int#
forall a. PrimBytes a => a -> Int#
byteSize @(DataFrame t ds') DataFrame t ys
forall a. HasCallStack => a
undefined
    = (State# RealWorld -> DataFrame t ds) -> DataFrame t ds
forall o. (State# RealWorld -> o) -> o
runRW#
    ( \State# RealWorld
s0 -> case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableByteArray# RealWorld #)
forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# (Int#
asize Int# -> Int# -> Int#
*# Int#
els) State# RealWorld
s0 of
       (# State# RealWorld
s1, MutableByteArray# RealWorld
mba #)
         | State# RealWorld
s2 <- (Word -> DataFrame t ys -> State# RealWorld -> State# RealWorld)
-> Word
-> Dim y
-> DFTree t ys y x
-> State# RealWorld
-> State# RealWorld
forall (n :: Nat) (ns :: [Nat]) s.
(Word -> DataFrame t ns -> State# s -> State# s)
-> Word -> Dim n -> DFTree t ns n x -> State# s -> State# s
fillDF @_ @ds'
                  (\(W# Word#
i) DataFrame t ys
df -> MutableByteArray# RealWorld
-> Int# -> DataFrame t ys -> State# RealWorld -> State# RealWorld
forall a s.
PrimBytes a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeBytes MutableByteArray# RealWorld
mba (Int#
asize Int# -> Int# -> Int#
*# Word# -> Int#
word2Int# Word#
i) DataFrame t ys
df)
                  Word
0 Dim y
dd DFTree t ys y x
rep State# RealWorld
s1
         , (# State# RealWorld
_, ByteArray#
ba #) <- MutableByteArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, ByteArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# RealWorld
mba State# RealWorld
s2
           -> Int# -> ByteArray# -> DataFrame t ds
forall a. PrimBytes a => Int# -> ByteArray# -> a
fromBytes Int#
0# ByteArray#
ba
    )
  where
    fillDF :: forall (n :: Nat) (ns :: [Nat]) s
            . (Word -> DataFrame t ns -> State# s -> State# s)
           -> Word
           -> Dim n
           -> DFTree t ns n x
           -> State# s -> State# s
    fillDF :: (Word -> DataFrame t ns -> State# s -> State# s)
-> Word -> Dim n -> DFTree t ns n x -> State# s -> State# s
fillDF Word -> DataFrame t ns -> State# s -> State# s
_ Word
_ Dim n
D0 DFTree t ns n x
_ State# s
s               = State# s
s
    fillDF Word -> DataFrame t ns -> State# s -> State# s
f Word
i Dim n
D1 (G.M1 (G.K1 e)) State# s
s = Word -> DataFrame t ns -> State# s -> State# s
f Word
i DataFrame t ns
e State# s
s
    fillDF Word -> DataFrame t ns -> State# s -> State# s
f Word
i Dim n
d    DFTree t ns n x
xy             State# s
s
      | Dict
  (DFTree t ns n
   ~ (DFTree t ns (Div n 2) :*: DFTree t ns (Div n 2 + Mod n 2)))
Dict <- Dict
  (DFTree t ns n
   ~ (DFTree t ns (Div n 2) :*: DFTree t ns (Div n 2 + Mod n 2)))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @(Type -> Type)
          @(DFTree t ns n)
          @(DFTree t ns (Div n 2) G.:*: DFTree t ns (Div n 2 + Mod n 2))
      , x G.:*: y <- DFTree t ns n x
xy
        = (Word -> DataFrame t ns -> State# s -> State# s)
-> Word
-> Dim (Div n 2 + Mod n 2)
-> DFTree t ns (Div n 2 + Mod n 2) x
-> State# s
-> State# s
forall (n :: Nat) (ns :: [Nat]) s.
(Word -> DataFrame t ns -> State# s -> State# s)
-> Word -> Dim n -> DFTree t ns n x -> State# s -> State# s
fillDF Word -> DataFrame t ns -> State# s -> State# s
f (Word
i Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Dim (Div n 2) -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim (Div n 2)
d2) Dim (Div n 2 + Mod n 2)
d2' DFTree t ns (Div n 2 + Mod n 2) x
y ((Word -> DataFrame t ns -> State# s -> State# s)
-> Word
-> Dim (Div n 2)
-> DFTree t ns (Div n 2) x
-> State# s
-> State# s
forall (n :: Nat) (ns :: [Nat]) s.
(Word -> DataFrame t ns -> State# s -> State# s)
-> Word -> Dim n -> DFTree t ns n x -> State# s -> State# s
fillDF Word -> DataFrame t ns -> State# s -> State# s
f Word
i Dim (Div n 2)
d2 DFTree t ns (Div n 2) x
x State# s
s)
      where
        d2 :: Dim (Div n 2)
d2  = Dim n -> Dim 2 -> Dim (Div n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (Div n m)
divDim Dim n
d Dim 2
forall (n :: Nat). (n ~ 2) => Dim n
D2
        d2' :: Dim (Div n 2 + Mod n 2)
d2' = Dim (Div n 2)
d2 Dim (Div n 2) -> Dim (Mod n 2) -> Dim (Div n 2 + Mod n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (n + m)
`plusDim` Dim n -> Dim 2 -> Dim (Mod n 2)
forall (n :: Nat) (m :: Nat). Dim n -> Dim m -> Dim (Mod n m)
modDim Dim n
d Dim 2
forall (n :: Nat). (n ~ 2) => Dim n
D2
#if IS_UNSOUND_MATCHING_810_900
toSingleFrame Dims ds
_ SingleFrameRep t ds x
_ = String -> DataFrame t ds
forall a. HasCallStack => String -> a
error String
"toSingleFrame: impossible arguments"
#endif
{-# INLINE toSingleFrame #-}

type family MultiFrameRepNil (ts :: [Type]) :: (Type -> Type) where
    MultiFrameRepNil '[]      = G.C1 ('G.MetaCons "Z" 'G.PrefixI 'False) G.U1
    MultiFrameRepNil (_ ': _) = G.Rec0 Void

type family MultiFrameRepCons (ts :: [Type]) (ds :: [Nat]) :: (Type -> Type) where
    MultiFrameRepCons '[]       _  = G.Rec0 Void
    MultiFrameRepCons (t ': ts) ds = G.C1
      ('G.MetaCons ":*:" ('G.InfixI 'G.RightAssociative 6) 'False)
      ( G.S1 DFMetaSel
           (G.Rec0 (DataFrame t ds))
       G.:*:
        G.S1 DFMetaSel
           (G.Rec0 (DataFrame ts ds))
      )

instance G.Generic (DataFrame (ts :: [Type]) (ds :: [Nat])) where
    type Rep (DataFrame ts ds) = G.D1
          ('G.MetaData "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
          ( MultiFrameRepNil ts G.:+: MultiFrameRepCons ts ds )
    from :: DataFrame ts ds -> Rep (DataFrame ts ds) x
from  DataFrame ts ds
Z         = (:+:) (M1 C ('MetaCons "Z" 'PrefixI 'False) U1) (Rec0 Void) x
-> M1
     D
     ('MetaData
        "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
     (M1 C ('MetaCons "Z" 'PrefixI 'False) U1 :+: Rec0 Void)
     x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (M1 C ('MetaCons "Z" 'PrefixI 'False) U1 x
-> (:+:) (M1 C ('MetaCons "Z" 'PrefixI 'False) U1) (Rec0 Void) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
G.L1 (U1 x -> M1 C ('MetaCons "Z" 'PrefixI 'False) U1 x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 U1 x
forall k (p :: k). U1 p
G.U1))
    from (DataFrame y ds
x :*: DataFrame ys ds
xs) = (:+:)
  (Rec0 Void)
  (M1
     C
     ('MetaCons ":*:" ('InfixI 'RightAssociative 6) 'False)
     (M1 S DFMetaSel (K1 R (DataFrame y ds))
      :*: M1 S DFMetaSel (K1 R (DataFrame ys ds))))
  x
-> M1
     D
     ('MetaData
        "DataFrame" "Numeric.DataFrame.Type" "easytensor" 'False)
     (Rec0 Void
      :+: M1
            C
            ('MetaCons ":*:" ('InfixI 'RightAssociative 6) 'False)
            (M1 S DFMetaSel (K1 R (DataFrame y ds))
             :*: M1 S DFMetaSel (K1 R (DataFrame ys ds))))
     x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (M1
  C
  ('MetaCons ":*:" ('InfixI 'RightAssociative 6) 'False)
  (M1 S DFMetaSel (K1 R (DataFrame y ds))
   :*: M1 S DFMetaSel (K1 R (DataFrame ys ds)))
  x
-> (:+:)
     (Rec0 Void)
     (M1
        C
        ('MetaCons ":*:" ('InfixI 'RightAssociative 6) 'False)
        (M1 S DFMetaSel (K1 R (DataFrame y ds))
         :*: M1 S DFMetaSel (K1 R (DataFrame ys ds))))
     x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
G.R1 ((:*:)
  (M1 S DFMetaSel (K1 R (DataFrame y ds)))
  (M1 S DFMetaSel (K1 R (DataFrame ys ds)))
  x
-> M1
     C
     ('MetaCons ":*:" ('InfixI 'RightAssociative 6) 'False)
     (M1 S DFMetaSel (K1 R (DataFrame y ds))
      :*: M1 S DFMetaSel (K1 R (DataFrame ys ds)))
     x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (K1 R (DataFrame y ds) x -> M1 S DFMetaSel (K1 R (DataFrame y ds)) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (DataFrame y ds -> K1 R (DataFrame y ds) x
forall k i c (p :: k). c -> K1 i c p
G.K1 DataFrame y ds
x) M1 S DFMetaSel (K1 R (DataFrame y ds)) x
-> M1 S DFMetaSel (K1 R (DataFrame ys ds)) x
-> (:*:)
     (M1 S DFMetaSel (K1 R (DataFrame y ds)))
     (M1 S DFMetaSel (K1 R (DataFrame ys ds)))
     x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
G.:*: K1 R (DataFrame ys ds) x
-> M1 S DFMetaSel (K1 R (DataFrame ys ds)) x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
G.M1 (DataFrame ys ds -> K1 R (DataFrame ys ds) x
forall k i c (p :: k). c -> K1 i c p
G.K1 DataFrame ys ds
xs))))
    to :: Rep (DataFrame ts ds) x -> DataFrame ts ds
to (G.M1 (G.L1 _))
      | Dict (ts ~ '[])
Dict <- Dict (ts ~ '[])
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @[Type] @ts @'[] = DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]). (xs ~ '[]) => DataFrame xs ns
Z
    to (G.M1 (G.R1 xxs))
      | Dict (ts ~ (Head ts : Tail ts))
Dict <- Dict (ts ~ (Head ts : Tail ts))
forall k (a :: k) (b :: k). Dict (a ~ b)
unsafeEqTypes @[Type] @ts @(Head ts ': Tail ts)
      , G.M1 (G.M1 (G.K1 x) G.:*: G.M1 (G.K1 xs)) <- MultiFrameRepCons ts ds x
xxs = DataFrame (Head ts) ds
x DataFrame (Head ts) ds -> DataFrame (Tail ts) ds -> DataFrame ts ds
forall (xs :: [*]) (ns :: [Nat]) y (ys :: [*]).
(xs ~ (y : ys)) =>
DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
:*: DataFrame (Tail ts) ds
xs



instance (AllFrames Eq ts ds, AllFrames Ord ts ds)
      => Ord (DataFrame (ts :: [Type]) ds) where
    compare :: DataFrame ts ds -> DataFrame ts ds -> Ordering
compare DataFrame ts ds
Z DataFrame ts ds
Z                   = Ordering
EQ
    compare (DataFrame y ds
a :*: DataFrame ys ds
as) (DataFrame y ds
b :*: DataFrame ys ds
bs) = DataFrame y ds -> DataFrame y ds -> Ordering
forall a. Ord a => a -> a -> Ordering
compare DataFrame y ds
a DataFrame y ds
DataFrame y ds
b Ordering -> Ordering -> Ordering
forall a. Semigroup a => a -> a -> a
<> DataFrame ys ds -> DataFrame ys ds -> Ordering
forall a. Ord a => a -> a -> Ordering
compare DataFrame ys ds
as DataFrame ys ds
DataFrame ys ds
bs


withFixedDF1 :: forall (l :: Type) (ts :: l) (xns :: [XNat])
                       (rep :: RuntimeRep) (r :: TYPE rep)
              . xns ~ Map 'N (DimsBound xns)
             => ( forall (ns :: [Nat])
               . ( All KnownDimType xns, FixedDims xns ns
                 , Dimensions ns
                 , KnownBackends ts ns
                 , ns ~ DimsBound xns
                 , xns ~ Map 'N ns
                 ) => DataFrame ts ns -> r
              ) -> DataFrame ts xns -> r