{-# LANGUAGE AllowAmbiguousTypes     #-}
{-# LANGUAGE DataKinds               #-}
{-# LANGUAGE FlexibleContexts        #-}
{-# LANGUAGE FlexibleInstances       #-}
{-# LANGUAGE FunctionalDependencies  #-}
{-# LANGUAGE InstanceSigs            #-}
{-# LANGUAGE MagicHash               #-}
{-# LANGUAGE MultiParamTypeClasses   #-}
{-# LANGUAGE PolyKinds               #-}
{-# LANGUAGE RankNTypes              #-}
{-# LANGUAGE ScopedTypeVariables     #-}
{-# LANGUAGE TypeApplications        #-}
{-# LANGUAGE TypeFamilies            #-}
{-# LANGUAGE TypeOperators           #-}
{-# LANGUAGE UndecidableInstances    #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
{- |
Module      :  Numeric.DataFrame.SubSpace
Copyright   :  (c) Artem Chirkin
License     :  BSD3

This module provides a flexible interface to manipulate parts of a DataFrame.

==== A note on indexing and slicing

When you index or slice dataframes, the left part of the dimension list
(@as@ for indexing, plus @b@ for slicing) determines the mechanics of accessing
sub-dataframes.
If compiler knows all dimensions at compile time, it can guarantee that the
operation is safe (provided with valid indices).
Otherwise, you can get an `OutOfDimBounds` exception at runtime.

When all dimensions in the indexing subspace satisfy @d :: Nat@ or @d ~ N n@,
slicing functions are safe to use, but you need some type-level proof for GHC
that the indices align.

When any of the dimensions are unknown (@d ~ XN m@), these functions are unsafe
-- they can yield an `OutOfDimBounds` exception if you give a bad index.
But they are easy to use (no type-level proof needed).

 -}

module Numeric.DataFrame.SubSpace
  ( -- $indexingSafety
    -- * Class definition
    SubSpace (SubSpaceCtx), CanSlice
    -- * Simple interface
    --
    --   All functions in this section are named @sxxx@, where @s@ stands for
    --   "simple". These allow using all functions of `SubSpace` with indexing
    --   dimensionality @as@ fixed to a single dim @(as ~ '[a])@.
    --   Use these functions if you are tired of @TypeApplications@ or find the
    --   error messages too cryptic.
  , sindexOffset, supdateOffset
  , (.!), slookup, supdate, sslice, ssliceMaybe, supdateSlice
  , sewgen, siwgen, sewmap, siwmap, sewzip, siwzip
  , selement, selementWise, selementWise_, sindexWise, sindexWise_
  , sewfoldl, sewfoldl', sewfoldr, sewfoldr', sewfoldMap
  , siwfoldl, siwfoldl', siwfoldr, siwfoldr', siwfoldMap
    -- * Flexible interface
    --
    --   Functions in this section allow you pick, fold, iterate, or do whatever
    --   you want with arbitrary sub-dataframe dimensionalities:
    --   e.g. a DataFrame of rank 3 can be processed as an 1D array of matrices
    --   or a matrix of vectors, or a 3D array of scalars.
    --   Often, you would need @TypeApplications@ to specify explicitly at least
    --   the indexing subspace (parameter @as@).
  , joinDataFrame, indexOffset, updateOffset
  , index, Numeric.DataFrame.SubSpace.lookup
  , update, slice, sliceMaybe, updateSlice
  , ewgen, iwgen, ewmap, iwmap, ewzip, iwzip
  , element, elementWise, elementWise_, indexWise, indexWise_
  , ewfoldl, ewfoldl', ewfoldr, ewfoldr', ewfoldMap
  , iwfoldl, iwfoldl', iwfoldr, iwfoldr', iwfoldMap
  ) where

import           Control.Arrow                        (first)
import           Control.Monad
import           Control.Monad.ST
import           Data.Kind
import           GHC.Base                             (Int (..), (+#))
import           Numeric.DataFrame.Internal.PrimArray
import           Numeric.DataFrame.ST
import           Numeric.DataFrame.Type
import           Numeric.Dimensions
import qualified Numeric.TypedList                    as TL
import           Unsafe.Coerce

-- | Unsafely get a sub-dataframe by its primitive element offset.
--   The offset is not checked to be aligned to the space structure or for bounds.
--
--   Warning: this function is utterly unsafe -- it does not even throw an exception if
--            the offset is too big; you just get an undefined behavior.
sindexOffset ::
       forall t a bs
     . SubSpace t '[a] bs (a :+ bs)
    => Int -- ^ Prim element offset
    -> DataFrame t (a :+ bs) -> DataFrame t bs
sindexOffset :: Int -> DataFrame t (a :+ bs) -> DataFrame t bs
sindexOffset = SubSpace t '[a] bs (a :+ bs) =>
Int -> DataFrame t (a :+ bs) -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset @t @'[a] @bs @(a :+ bs)
{-# INLINE sindexOffset #-}

-- | Unsafely update a sub-dataframe by its primitive element offset.
--   The offset is not checked to be aligned to the space structure or for bounds.
--
--   Warning: this function is utterly unsafe -- it does not even throw an exception if
--            the offset is too big; you just get an undefined behavior.
supdateOffset ::
       forall t a bs
     . SubSpace t '[a] bs (a :+ bs)
    => Int -- ^ Prim element offset
    -> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
supdateOffset :: Int
-> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
supdateOffset = SubSpace t '[a] bs (a :+ bs) =>
Int
-> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffset @t @'[a] @bs @(a :+ bs)
{-# INLINE supdateOffset #-}

-- | Get an element by its index in the dataframe.
--
--   If (@a ~ XN m@) then this function is unsafe and can throw
--   an `OutOfDimBounds` exception.
--   Otherwise, its safety is guaranteed by the type system.
(.!) ::
       forall t a bs
     . SubSpace t '[a] bs (a :+ bs)
    => DataFrame t (a :+ bs) -> Idx a -> DataFrame t bs
.! :: DataFrame t (a :+ bs) -> Idx a -> DataFrame t bs
(.!) DataFrame t (a :+ bs)
x Idx a
i = Idxs '[a] -> DataFrame t (a :+ bs) -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index @t @'[a] @bs @(a :+ bs) (Idx a
i Idx a -> TypedList Idx '[] -> Idxs '[a]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U) DataFrame t (a :+ bs)
x
{-# INLINE (.!) #-}
infixl 4 .!

-- | Set a new value to an element.
--
--   If (@a ~ XN m@) and the index falls outside of the DataFrame dim,
--   then this function returns the original DataFrame.
supdate ::
       forall t a bs
     . SubSpace t '[a] bs (a :+ bs)
    => Idx a -> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
supdate :: Idx a
-> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
supdate = SubSpace t '[a] bs (a :+ bs) =>
Idxs '[a]
-> DataFrame t bs -> DataFrame t (a :+ bs) -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
update @t @'[a] @bs @(a :+ bs) (Idxs '[a]
 -> DataFrame t bs
 -> DataFrame t (a :+ bs)
 -> DataFrame t (a :+ bs))
-> (Idx a -> Idxs '[a])
-> Idx a
-> DataFrame t bs
-> DataFrame t (a :+ bs)
-> DataFrame t (a :+ bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx a -> TypedList Idx '[] -> Idxs '[a]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:*TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE[1] supdate #-}

-- | Map a function over each element of DataFrame.
sewmap ::
       forall t a bs s bs'
     . (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs'))
    => (DataFrame s bs' -> DataFrame t bs)
    -> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
sewmap :: (DataFrame s bs' -> DataFrame t bs)
-> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
sewmap = (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs')) =>
(DataFrame s bs' -> DataFrame t bs)
-> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmap @t @'[a] @bs @(a :+ bs) @s @bs' @(a :+ bs')
{-# INLINE sewmap #-}

-- | Map a function over each element with its index of DataFrame.
siwmap ::
       forall t a bs s bs'
     . (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs'))
    => (Idx a -> DataFrame s bs' -> DataFrame t bs)
    -> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
siwmap :: (Idx a -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
siwmap Idx a -> DataFrame s bs' -> DataFrame t bs
f = (Idxs '[a] -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s (a :+ bs') -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmap @t @'[a] @bs @(a :+ bs) @s @bs' @(a :+ bs') (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame s bs' -> DataFrame t bs
f Idx a
Idx y
i)
{-# INLINE[1] siwmap #-}

-- | Generate a DataFrame by repeating an element.
sewgen ::
       forall t a bs
     . (SubSpace t '[a] bs (a :+ bs), Dimensions '[a])
    => DataFrame t bs -> DataFrame t (a :+ bs)
sewgen :: DataFrame t bs -> DataFrame t (a :+ bs)
sewgen = (SubSpace t '[a] bs (a :+ bs), Dimensions '[a]) =>
DataFrame t bs -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgen @t @'[a] @bs @(a :+ bs)
{-# INLINE sewgen #-}

-- | Generate a DataFrame by iterating a function (index -> element).
siwgen ::
       forall t a bs
     . (SubSpace t '[a] bs (a :+ bs), Dimensions '[a])
    => (Idx a -> DataFrame t bs) -> DataFrame t (a :+ bs)
siwgen :: (Idx a -> DataFrame t bs) -> DataFrame t (a :+ bs)
siwgen Idx a -> DataFrame t bs
f = (Idxs '[a] -> DataFrame t bs) -> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen @t @'[a] @bs @(a :+ bs) (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame t bs
f Idx a
Idx y
i)
{-# INLINE[1] siwgen #-}

-- | Left-associative lazy fold of a DataFrame.
--   Same rules apply as for `foldl`.
sewfoldl ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldl :: (b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldl = SubSpace t '[a] bs (a :+ bs) =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl @t @'[a] @bs @(a :+ bs) @b
{-# INLINE sewfoldl #-}

-- | Left-associative strict fold of a DataFrame.
--   Same rules apply as for `foldl'`.
sewfoldl' ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldl' :: (b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldl' = SubSpace t '[a] bs (a :+ bs) =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl' @t @'[a] @bs @(a :+ bs) @b
{-# INLINE sewfoldl' #-}

-- | Left-associative lazy fold of a DataFrame with an index.
--   Same rules apply as for `foldl`.
siwfoldl ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (Idx a -> b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
siwfoldl :: (Idx a -> b -> DataFrame t bs -> b)
-> b -> DataFrame t (a :+ bs) -> b
siwfoldl Idx a -> b -> DataFrame t bs -> b
f = (Idxs '[a] -> b -> DataFrame t bs -> b)
-> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl @t @'[a] @bs @(a :+ bs) @b (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> b -> DataFrame t bs -> b
f Idx a
Idx y
i)
{-# INLINE[1] siwfoldl #-}

-- | Left-associative strict fold of a DataFrame with an index.
--   Same rules apply as for `foldl'`.
siwfoldl' ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (Idx a -> b -> DataFrame t bs -> b) -> b -> DataFrame t (a :+ bs) -> b
siwfoldl' :: (Idx a -> b -> DataFrame t bs -> b)
-> b -> DataFrame t (a :+ bs) -> b
siwfoldl' Idx a -> b -> DataFrame t bs -> b
f = (Idxs '[a] -> b -> DataFrame t bs -> b)
-> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl' @t @'[a] @bs @(a :+ bs) @b (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> b -> DataFrame t bs -> b
f Idx a
Idx y
i)
{-# INLINE[1] siwfoldl' #-}

-- | Right-associative lazy fold of a DataFrame.
--   Same rules apply as for `foldr`.
sewfoldr ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldr :: (DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldr = SubSpace t '[a] bs (a :+ bs) =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr @t @'[a] @bs @(a :+ bs) @b
{-# INLINE sewfoldr #-}

-- | Right-associative strict fold of a DataFrame.
--   Same rules apply as for `foldr'`.
sewfoldr' ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldr' :: (DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
sewfoldr' = SubSpace t '[a] bs (a :+ bs) =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr' @t @'[a] @bs @(a :+ bs) @b
{-# INLINE sewfoldr' #-}

-- | Right-associative lazy fold of a DataFrame with an index.
--   Same rules apply as for `foldr`.
siwfoldr ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (Idx a -> DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
siwfoldr :: (Idx a -> DataFrame t bs -> b -> b)
-> b -> DataFrame t (a :+ bs) -> b
siwfoldr Idx a -> DataFrame t bs -> b -> b
f = (Idxs '[a] -> DataFrame t bs -> b -> b)
-> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr @t @'[a] @bs @(a :+ bs) @b (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame t bs -> b -> b
f Idx a
Idx y
i)
{-# INLINE[1] siwfoldr #-}

-- | Right-associative strict fold of a DataFrame with an index.
--   Same rules apply as for `foldr'`.
siwfoldr' ::
       forall t a bs b
     . SubSpace t '[a] bs (a :+ bs)
    => (Idx a -> DataFrame t bs -> b -> b) -> b -> DataFrame t (a :+ bs) -> b
siwfoldr' :: (Idx a -> DataFrame t bs -> b -> b)
-> b -> DataFrame t (a :+ bs) -> b
siwfoldr' Idx a -> DataFrame t bs -> b -> b
f = (Idxs '[a] -> DataFrame t bs -> b -> b)
-> b -> DataFrame t (a :+ bs) -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr' @t @'[a] @bs @(a :+ bs) @b (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame t bs -> b -> b
f Idx a
Idx y
i)
{-# INLINE[1] siwfoldr' #-}

-- | Apply an applicative functor on each element (Lens-like traversal).
selementWise ::
       forall t a bs s bs' f
     . (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs'), Applicative f)
    => (DataFrame s bs' -> f (DataFrame t bs))
    -> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
selementWise :: (DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
selementWise = (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs'),
 Applicative f) =>
(DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, SubSpace s as bs' asbs', Applicative f) =>
(DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
elementWise @t @'[a] @bs @(a :+ bs) @s @bs' @(a :+ bs') @f
{-# INLINE selementWise #-}

-- | Apply an applicative functor on each element with its index
--     (Lens-like indexed traversal).
sindexWise ::
       forall t a bs s bs' f
     . (SubSpace t '[a] bs (a :+ bs), SubSpace s '[a] bs' (a :+ bs'), Applicative f)
    => (Idx a -> DataFrame s bs' -> f (DataFrame t bs))
    -> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
sindexWise :: (Idx a -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
sindexWise Idx a -> DataFrame s bs' -> f (DataFrame t bs)
f = (Idxs '[a] -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s (a :+ bs') -> f (DataFrame t (a :+ bs))
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, SubSpace s as bs' asbs', Applicative f) =>
(Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWise @t @'[a] @bs @(a :+ bs) @s @bs' @(a :+ bs') @f (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame s bs' -> f (DataFrame t bs)
f Idx a
Idx y
i)
{-# INLINE[1] sindexWise #-}

-- | Apply an applicative functor on each element (Lens-like traversal)
selementWise_ ::
       forall t a bs f b
     . (SubSpace t '[a] bs (a :+ bs), Applicative f)
    => (DataFrame t bs -> f b) -> DataFrame t (a :+ bs) -> f ()
selementWise_ :: (DataFrame t bs -> f b) -> DataFrame t (a :+ bs) -> f ()
selementWise_ = (SubSpace t '[a] bs (a :+ bs), Applicative f) =>
(DataFrame t bs -> f b) -> DataFrame t (a :+ bs) -> f ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) (f :: * -> *) b.
(SubSpace t as bs asbs, Applicative f) =>
(DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
elementWise_ @t @'[a] @bs @(a :+ bs) @f @b
{-# INLINE selementWise_ #-}

-- | Apply an applicative functor on each element with its index
--     (Lens-like indexed traversal)
sindexWise_ ::
       forall t a bs f b
    . (SubSpace t '[a] bs (a :+ bs), Applicative f)
   => (Idx a -> DataFrame t bs -> f b) -> DataFrame t (a :+ bs) -> f ()
sindexWise_ :: (Idx a -> DataFrame t bs -> f b) -> DataFrame t (a :+ bs) -> f ()
sindexWise_ Idx a -> DataFrame t bs -> f b
f = (Idxs '[a] -> DataFrame t bs -> f b)
-> DataFrame t (a :+ bs) -> f ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) (f :: * -> *) b.
(SubSpace t as bs asbs, Applicative f) =>
(Idxs as -> DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
indexWise_ @t @'[a] @bs @(a :+ bs) @f @b (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame t bs -> f b
f Idx a
Idx y
i)
{-# INLINE sindexWise_ #-}

-- | Apply a functor over a single element (simple lens)
--
--   If (@a ~ XN m@) and the index falls outside of the DataFrame Dim, the
--   argument Functor is not called and the result is @pure@ original DataFrame.
selement ::
       forall t a bs f
     . (SubSpace t '[a] bs (a :+ bs), Applicative f)
    => Idx a
    -> (DataFrame t bs -> f (DataFrame t bs))
    -> DataFrame t (a :+ bs) -> f (DataFrame t (a :+ bs))
selement :: Idx a
-> (DataFrame t bs -> f (DataFrame t bs))
-> DataFrame t (a :+ bs)
-> f (DataFrame t (a :+ bs))
selement = (SubSpace t '[a] bs (a :+ bs), Applicative f) =>
Idxs '[a]
-> (DataFrame t bs -> f (DataFrame t bs))
-> DataFrame t (a :+ bs)
-> f (DataFrame t (a :+ bs))
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, Applicative f) =>
Idxs as
-> (DataFrame t bs -> f (DataFrame t bs))
-> DataFrame t asbs
-> f (DataFrame t asbs)
element @t @'[a] @bs @(a :+ bs) @f (Idxs '[a]
 -> (DataFrame t bs -> f (DataFrame t bs))
 -> DataFrame t (a :+ bs)
 -> f (DataFrame t (a :+ bs)))
-> (Idx a -> Idxs '[a])
-> Idx a
-> (DataFrame t bs -> f (DataFrame t bs))
-> DataFrame t (a :+ bs)
-> f (DataFrame t (a :+ bs))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx a -> TypedList Idx '[] -> Idxs '[a]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE selement #-}

-- | Map each element of the DataFrame to a monoid,
--    and combine the results.
sewfoldMap ::
       forall t a bs m
     . (SubSpace t '[a] bs (a :+ bs), Monoid m)
    => (DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
sewfoldMap :: (DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
sewfoldMap = (SubSpace t '[a] bs (a :+ bs), Monoid m) =>
(DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) m.
(SubSpace t as bs asbs, Monoid m) =>
(DataFrame t bs -> m) -> DataFrame t asbs -> m
ewfoldMap @t @'[a] @bs @(a :+ bs) @m
{-# INLINE sewfoldMap #-}

-- | Map each element of the DataFrame and its index to a monoid,
--    and combine the results.
siwfoldMap ::
       forall t a bs m
     . (SubSpace t '[a] bs (a :+ bs), Monoid m)
    => (Idx a -> DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
siwfoldMap :: (Idx a -> DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
siwfoldMap Idx a -> DataFrame t bs -> m
f = (Idxs '[a] -> DataFrame t bs -> m) -> DataFrame t (a :+ bs) -> m
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) m.
(SubSpace t as bs asbs, Monoid m) =>
(Idxs as -> DataFrame t bs -> m) -> DataFrame t asbs -> m
iwfoldMap @t @'[a] @bs @(a :+ bs) @m (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame t bs -> m
f Idx a
Idx y
i)
{-# INLINE[1] siwfoldMap #-}

-- | Zip two spaces on a specified subspace element-wise (without index)
sewzip ::
       forall t a bs l bsL r bsR
     . (SubSpace t '[a] bs (a :+ bs), SubSpace l '[a] bsL (a :+ bsL), SubSpace r '[a] bsR (a :+ bsR))
    => (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
    -> DataFrame l (a :+ bsL) -> DataFrame r (a :+ bsR) -> DataFrame t (a :+ bs)
sewzip :: (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l (a :+ bsL)
-> DataFrame r (a :+ bsR)
-> DataFrame t (a :+ bs)
sewzip = (SubSpace t '[a] bs (a :+ bs), SubSpace l '[a] bsL (a :+ bsL),
 SubSpace r '[a] bsR (a :+ bsR)) =>
(DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l (a :+ bsL)
-> DataFrame r (a :+ bsR)
-> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) l (bsL :: [k])
       (asbsL :: [k]) r (bsR :: [k]) (asbsR :: [k]).
(SubSpace t as bs asbs, SubSpace l as bsL asbsL,
 SubSpace r as bsR asbsR) =>
(DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
ewzip @t @'[a] @bs @(a :+ bs) @l @bsL @(a :+ bsL) @r @bsR @(a :+ bsR)
{-# INLINE sewzip #-}

-- | Zip two spaces on a specified subspace index-wise (with index)
siwzip ::
       forall t a bs l bsL r bsR
     . (SubSpace t '[a] bs (a :+ bs), SubSpace l '[a] bsL (a :+ bsL), SubSpace r '[a] bsR (a :+ bsR))
    => (Idx a -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
    -> DataFrame l (a :+ bsL) -> DataFrame r (a :+ bsR) -> DataFrame t (a :+ bs)
siwzip :: (Idx a -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l (a :+ bsL)
-> DataFrame r (a :+ bsR)
-> DataFrame t (a :+ bs)
siwzip Idx a -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
f = (Idxs '[a] -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l (a :+ bsL)
-> DataFrame r (a :+ bsR)
-> DataFrame t (a :+ bs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) l (bsL :: [k])
       (asbsL :: [k]) r (bsR :: [k]) (asbsR :: [k]).
(SubSpace t as bs asbs, SubSpace l as bsL asbsL,
 SubSpace r as bsR asbsR) =>
(Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
iwzip @t @'[a] @bs @(a :+ bs) @l @bsL @(a :+ bsL) @r @bsR @(a :+ bsR) (\(Idx y
i :* TypedList Idx ys
U) -> Idx a -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
f Idx a
Idx y
i)
{-# INLINE siwzip #-}

-- | Flatten a nested DataFrame, analogous to `Control.Monad.join`.
joinDataFrame ::
       forall t as bs asbs
     . (SubSpace t as bs asbs, PrimBytes (DataFrame t bs))
    => DataFrame (DataFrame t bs) as -> DataFrame t asbs
joinDataFrame :: DataFrame (DataFrame t bs) as -> DataFrame t asbs
joinDataFrame = (SubSpace t as bs asbs, PrimBytes (DataFrame t bs)) =>
DataFrame (DataFrame t bs) as -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, PrimBytes (DataFrame t bs)) =>
DataFrame (DataFrame t bs) as -> DataFrame t asbs
joinDataFrameI @_ @t @as @bs @asbs
{-# INLINE[1] joinDataFrame #-}

-- | Unsafely get a sub-dataframe by its primitive element offset.
--   The offset is not checked to be aligned to the space structure or for bounds.
--
--   Warning: this function is utterly unsafe -- it does not even throw an exception if
--            the offset is too big; you just get an undefined behavior.
indexOffset ::
       forall t as bs asbs
     . SubSpace t as bs asbs
    => Int -- ^ Prim element offset
    -> DataFrame t asbs -> DataFrame t bs
indexOffset :: Int -> DataFrame t asbs -> DataFrame t bs
indexOffset = SubSpace t as bs asbs => Int -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffsetI @_ @t @as @bs @asbs
{-# INLINE[1] indexOffset #-}

-- | Unsafely update a sub-dataframe by its primitive element offset.
--   The offset is not checked to be aligned to the space structure or for bounds.
--
--   Warning: this function is utterly unsafe -- it does not even throw an exception if
--            the offset is too big; you just get an undefined behavior.
updateOffset ::
       forall t as bs asbs
     . SubSpace t as bs asbs
    => Int -- ^ Prim element offset
    -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffset :: Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffset = SubSpace t as bs asbs =>
Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffsetI @_ @t @as @bs @asbs
{-# INLINE[1] updateOffset #-}

-- | Get an element by its index in the dataframe.
--
--   If any of the dims in @as@ is unknown (@a ~ XN m@),
--   then this function is unsafe and can throw an `OutOfDimBounds` exception.
--   Otherwise, its safety is guaranteed by the type system.
index ::
       forall t as bs asbs
     . SubSpace t as bs asbs
    => Idxs as -> DataFrame t asbs -> DataFrame t bs
index :: Idxs as -> DataFrame t asbs -> DataFrame t bs
index = SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
indexI @_ @t @as @bs @asbs
{-# INLINE[1] index #-}

-- | Set a new value to an element.
--
--   If any of the dims in @as@ is unknown (@a ~ XN m@),
--   you may happen to update data beyond dataframe bounds.
--   In this case, the original DataFrame is returned.
update ::
       forall t as bs asbs
     . SubSpace t as bs asbs
    => Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
update :: Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
update = SubSpace t as bs asbs =>
Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateI @_ @t @as @bs @asbs
{-# INLINE[1] update #-}

-- | Map a function over each element of DataFrame.
ewmap ::
       forall t as bs asbs s bs' asbs'
     . (SubSpace t as bs asbs, SubSpace s as bs' asbs')
    => (DataFrame s bs' -> DataFrame t bs)
    -> DataFrame s asbs' -> DataFrame t asbs
ewmap :: (DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmap = SubSpace s as bs' asbs' =>
(DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmapI @_ @t @as @bs @asbs @s @bs' @asbs'
{-# INLINE[1] ewmap #-}

-- | Map a function over each element with its index of DataFrame.
iwmap ::
       forall t as bs asbs s bs' asbs'
     . (SubSpace t as bs asbs, SubSpace s as bs' asbs')
    => (Idxs as -> DataFrame s bs' -> DataFrame t bs)
    -> DataFrame s asbs' -> DataFrame t asbs
iwmap :: (Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmap = SubSpace s as bs' asbs' =>
(Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmapI @_ @t @as @bs @asbs @s @bs' @asbs'
{-# INLINE[1] iwmap #-}

-- | Generate a DataFrame by repeating an element.
ewgen ::
       forall t as bs asbs
     . (SubSpace t as bs asbs, Dimensions as)
    => DataFrame t bs -> DataFrame t asbs
ewgen :: DataFrame t bs -> DataFrame t asbs
ewgen = (SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgenI @_ @t @as @bs @asbs
{-# INLINE[1] ewgen #-}

-- | Generate a DataFrame by iterating a function (index -> element).
iwgen ::
       forall t as bs asbs
     . (SubSpace t as bs asbs, Dimensions as)
    => (Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen :: (Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen = (SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgenI @_ @t @as @bs @asbs
{-# INLINE[1] iwgen #-}

-- | Left-associative lazy fold of a DataFrame.
--   Same rules apply as for `foldl`.
ewfoldl ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl :: (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl = (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldlI @_ @t @as @bs @asbs @b
{-# INLINE[1] ewfoldl #-}

-- | Left-associative strict fold of a DataFrame.
--   Same rules apply as for `foldl'`.
ewfoldl' ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl' :: (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl' b -> DataFrame t bs -> b
f b
z0 DataFrame t asbs
xs = (DataFrame t bs -> (b -> b) -> b -> b)
-> (b -> b) -> DataFrame t asbs -> b -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr DataFrame t bs -> (b -> b) -> b -> b
f' b -> b
forall a. a -> a
id DataFrame t asbs
xs b
z0
  where
    f' :: DataFrame t bs -> (b -> b) -> b -> b
f' DataFrame t bs
x b -> b
k b
z = b -> b
k (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$! b -> DataFrame t bs -> b
f b
z DataFrame t bs
x
{-# INLINE ewfoldl' #-}

-- | Left-associative lazy fold of a DataFrame with an index.
--   Same rules apply as for `foldl`.
iwfoldl ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl :: (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl = (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldlI @_ @t @as @bs @asbs @b
{-# INLINE[1] iwfoldl #-}

-- | Left-associative strict fold of a DataFrame with an index.
--   Same rules apply as for `foldl'`.
iwfoldl' ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl' :: (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl' Idxs as -> b -> DataFrame t bs -> b
f b
z0 DataFrame t asbs
xs = (Idxs as -> DataFrame t bs -> (b -> b) -> b -> b)
-> (b -> b) -> DataFrame t asbs -> b -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr Idxs as -> DataFrame t bs -> (b -> b) -> b -> b
f' b -> b
forall a. a -> a
id DataFrame t asbs
xs b
z0
  where
    f' :: Idxs as -> DataFrame t bs -> (b -> b) -> b -> b
f' Idxs as
i DataFrame t bs
x b -> b
k b
z = b -> b
k (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$! Idxs as -> b -> DataFrame t bs -> b
f Idxs as
i b
z DataFrame t bs
x
{-# INLINE[1] iwfoldl' #-}

-- | Right-associative lazy fold of a DataFrame.
--   Same rules apply as for `foldr`.
ewfoldr ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr :: (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr = (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldrI @_ @t @as @bs @asbs @b
{-# INLINE[1] ewfoldr #-}

-- | Right-associative strict fold of a DataFrame.
--   Same rules apply as for `foldr'`.
ewfoldr' ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr' :: (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr' DataFrame t bs -> b -> b
f b
z0 DataFrame t asbs
xs = ((b -> b) -> DataFrame t bs -> b -> b)
-> (b -> b) -> DataFrame t asbs -> b -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl (b -> b) -> DataFrame t bs -> b -> b
f' b -> b
forall a. a -> a
id DataFrame t asbs
xs b
z0
  where
    f' :: (b -> b) -> DataFrame t bs -> b -> b
f' b -> b
k DataFrame t bs
x b
z = b -> b
k (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$! DataFrame t bs -> b -> b
f DataFrame t bs
x b
z
{-# INLINE ewfoldr' #-}

-- | Right-associative lazy fold of a DataFrame with an index.
--   Same rules apply as for `foldr`.
iwfoldr ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr :: (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr = (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldrI @_ @t @as @bs @asbs @b
{-# INLINE[1] iwfoldr #-}

-- | Right-associative strict fold of a DataFrame with an index.
--   Same rules apply as for `foldr'`.
iwfoldr' ::
       forall t as bs asbs b
     . SubSpace t as bs asbs
    => (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr' :: (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr' Idxs as -> DataFrame t bs -> b -> b
f b
z0 DataFrame t asbs
xs = (Idxs as -> (b -> b) -> DataFrame t bs -> b -> b)
-> (b -> b) -> DataFrame t asbs -> b -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl Idxs as -> (b -> b) -> DataFrame t bs -> b -> b
f' b -> b
forall a. a -> a
id DataFrame t asbs
xs b
z0
  where
    f' :: Idxs as -> (b -> b) -> DataFrame t bs -> b -> b
f' Idxs as
i b -> b
k DataFrame t bs
x b
z = b -> b
k (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$! Idxs as -> DataFrame t bs -> b -> b
f Idxs as
i DataFrame t bs
x b
z
{-# INLINE[1] iwfoldr' #-}

-- | Apply an applicative functor on each element (Lens-like traversal).
elementWise ::
       forall t as bs asbs s bs' asbs' f
     . (SubSpace t as bs asbs, SubSpace s as bs' asbs', Applicative f)
    => (DataFrame s bs' -> f (DataFrame t bs))
    -> DataFrame s asbs' -> f (DataFrame t asbs)
elementWise :: (DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
elementWise = (Applicative f, SubSpace s as bs' asbs') =>
(DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, Applicative f, SubSpace s as bs' asbs') =>
(DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
elementWiseI @_ @t @as @bs @asbs @s @bs' @asbs' @f
{-# INLINE[1] elementWise #-}

-- | Apply an applicative functor on each element with its index
--     (Lens-like indexed traversal).
indexWise ::
       forall t as bs asbs s bs' asbs' f
     . (SubSpace t as bs asbs, SubSpace s as bs' asbs', Applicative f)
    => (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
    -> DataFrame s asbs' -> f (DataFrame t asbs)
indexWise :: (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWise = (Applicative f, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, Applicative f, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWiseI @_ @t @as @bs @asbs @s @bs' @asbs' @f
{-# INLINE[1] indexWise #-}

-- | Apply an applicative functor on each element (Lens-like traversal)
elementWise_ ::
       forall t as bs asbs f b
     . (SubSpace t as bs asbs, Applicative f)
    => (DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
elementWise_ :: (DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
elementWise_ DataFrame t bs -> f b
f = (DataFrame t bs -> f () -> f ())
-> f () -> DataFrame t asbs -> f ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr (f b -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (f b -> f () -> f ())
-> (DataFrame t bs -> f b) -> DataFrame t bs -> f () -> f ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame t bs -> f b
f) (() -> f ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
{-# INLINE elementWise_ #-}

-- | Apply an applicative functor on each element with its index
--     (Lens-like indexed traversal)
indexWise_ ::
       forall t as bs asbs f b
    . (SubSpace t as bs asbs, Applicative f)
   => (Idxs as -> DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
indexWise_ :: (Idxs as -> DataFrame t bs -> f b) -> DataFrame t asbs -> f ()
indexWise_ Idxs as -> DataFrame t bs -> f b
f = (Idxs as -> DataFrame t bs -> f () -> f ())
-> f () -> DataFrame t asbs -> f ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr (\Idxs as
i -> f b -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (f b -> f () -> f ())
-> (DataFrame t bs -> f b) -> DataFrame t bs -> f () -> f ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Idxs as -> DataFrame t bs -> f b
f Idxs as
i) (() -> f ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
{-# INLINE indexWise_ #-}

-- | Apply a functor over a single element (simple lens)
--
--   If any of the dims in @as@ is unknown (@a ~ XN m@) and any of the
--   corresponding indices fall outside of the DataFrame Dims, then the
--   argument Functor is not called and the result is @pure@ original DataFrame.
element ::
       forall t as bs asbs f
     . (SubSpace t as bs asbs, Applicative f)
    => Idxs as
    -> (DataFrame t bs -> f (DataFrame t bs))
    -> DataFrame t asbs -> f (DataFrame t asbs)
element :: Idxs as
-> (DataFrame t bs -> f (DataFrame t bs))
-> DataFrame t asbs
-> f (DataFrame t asbs)
element Idxs as
i DataFrame t bs -> f (DataFrame t bs)
f DataFrame t asbs
df = case KnownDimKind k => DimKind k
forall k. KnownDimKind k => DimKind k
dimKind @(KindOfEl asbs) of
  DimKind k
DimKNat -> (DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs)
-> DataFrame t asbs -> DataFrame t bs -> DataFrame t asbs
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
update Idxs as
i) DataFrame t asbs
df (DataFrame t bs -> DataFrame t asbs)
-> f (DataFrame t bs) -> f (DataFrame t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataFrame t bs -> f (DataFrame t bs)
f (Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame t asbs
df)
  DimKind k
DimKXNat
    | XFrame (dfN :: DataFrame t asbsN) <- DataFrame t asbs
df
    , Just Int
off <- CumulDims -> Idxs as -> Maybe Int
forall k (ns :: [k]). CumulDims -> Idxs ns -> Maybe Int
cdIxM (Dims ns -> DataFrame t ns -> CumulDims
forall t a k (ns :: [k]).
PrimArray t a =>
Dims ns -> a -> CumulDims
getSteps (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) DataFrame t ns
dfN) Idxs as
i
      -> (DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs)
-> DataFrame t asbs -> DataFrame t bs -> DataFrame t asbs
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffset Int
off) DataFrame t asbs
df (DataFrame t bs -> DataFrame t asbs)
-> f (DataFrame t bs) -> f (DataFrame t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataFrame t bs -> f (DataFrame t bs)
f (Int -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset Int
off DataFrame t asbs
df)
    | Bool
otherwise
      -> DataFrame t asbs -> f (DataFrame t asbs)
forall (f :: * -> *) a. Applicative f => a -> f a
pure DataFrame t asbs
df
{-# INLINE element #-}


-- | Map each element of the DataFrame to a monoid,
--    and combine the results.
ewfoldMap ::
       forall t as bs asbs m
     . (SubSpace t as bs asbs, Monoid m)
    => (DataFrame t bs -> m) -> DataFrame t asbs -> m
ewfoldMap :: (DataFrame t bs -> m) -> DataFrame t asbs -> m
ewfoldMap DataFrame t bs -> m
f = (DataFrame t bs -> m -> m) -> m -> DataFrame t asbs -> m
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr (m -> m -> m
forall a. Monoid a => a -> a -> a
mappend (m -> m -> m) -> (DataFrame t bs -> m) -> DataFrame t bs -> m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame t bs -> m
f) m
forall a. Monoid a => a
mempty
{-# INLINE ewfoldMap #-}

-- | Map each element of the DataFrame and its index to a monoid,
--    and combine the results.
iwfoldMap ::
       forall t as bs asbs m
     . (SubSpace t as bs asbs, Monoid m)
    => (Idxs as -> DataFrame t bs -> m) -> DataFrame t asbs -> m
iwfoldMap :: (Idxs as -> DataFrame t bs -> m) -> DataFrame t asbs -> m
iwfoldMap Idxs as -> DataFrame t bs -> m
f = (Idxs as -> DataFrame t bs -> m -> m) -> m -> DataFrame t asbs -> m
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr (\Idxs as
i -> m -> m -> m
forall a. Monoid a => a -> a -> a
mappend (m -> m -> m) -> (DataFrame t bs -> m) -> DataFrame t bs -> m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Idxs as -> DataFrame t bs -> m
f Idxs as
i) m
forall a. Monoid a => a
mempty
{-# INLINE iwfoldMap #-}

-- | Zip two spaces on a specified subspace element-wise (without index)
ewzip :: forall t as bs asbs l bsL asbsL r bsR asbsR
     . (SubSpace t as bs asbs, SubSpace l as bsL asbsL, SubSpace r as bsR asbsR)
    => (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
    -> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
ewzip :: (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
ewzip = (Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) l (bsL :: [k])
       (asbsL :: [k]) r (bsR :: [k]) (asbsR :: [k]).
(SubSpace t as bs asbs, SubSpace l as bsL asbsL,
 SubSpace r as bsR asbsR) =>
(Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
iwzip ((Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
 -> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs)
-> ((DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
    -> Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL
-> DataFrame r asbsR
-> DataFrame t asbs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
forall a b. a -> b -> a
const
{-# INLINE ewzip #-}

-- | Zip two spaces on a specified subspace index-wise (with index).
iwzip :: forall t as bs asbs l bsL asbsL r bsR asbsR
     . (SubSpace t as bs asbs, SubSpace l as bsL asbsL, SubSpace r as bsR asbsR)
    => (Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
    -> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
iwzip :: (Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame r asbsR -> DataFrame t asbs
iwzip Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
f DataFrame l asbsL
dfl DataFrame r asbsR
dfr = case KnownDimKind k => DimKind k
forall k. KnownDimKind k => DimKind k
dimKind @(KindOfEl asbs) of
  DimKind k
DimKNat -> (Idxs as -> DataFrame l bsL -> DataFrame t bs)
-> DataFrame l asbsL -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmap (\Idxs as
i DataFrame l bsL
x -> Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
f Idxs as
i DataFrame l bsL
x (Idxs as -> DataFrame r asbsR -> DataFrame r bsR
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame r asbsR
dfr)) DataFrame l asbsL
dfl
  DimKind k
DimKXNat
    | XFrame (_ :: DataFrame l asbsLN) <- DataFrame l asbsL
dfl
    , XFrame (_ :: DataFrame r asbsRN) <- DataFrame r asbsR
dfr
    , Dims asbs
asbs <- [Word] -> Dims asbs
forall a b. a -> b
unsafeCoerce -- minimum spans
        ([Word] -> Dims asbs) -> [Word] -> Dims asbs
forall a b. (a -> b) -> a -> b
$ (Word -> Word -> Word) -> [Word] -> [Word] -> [Word]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Word -> Word -> Word
forall a. Ord a => a -> a -> a
min (Dims ns -> [Word]
forall k (xs :: [k]). Dims xs -> [Word]
listDims (Dims ns -> [Word]) -> Dims ns -> [Word]
forall a b. (a -> b) -> a -> b
$ Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsLN) (Dims ns -> [Word]
forall k (xs :: [k]). Dims xs -> [Word]
listDims (Dims ns -> [Word]) -> Dims ns -> [Word]
forall a b. (a -> b) -> a -> b
$ Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsRN) :: Dims asbs
    , Dims bs
bs <- (Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs)
    , Dims as
as <- (Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as)
      -> Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @('Just (DimsBound bs)) @'Nothing Dims as
Dims as
as Dims bs
Dims bs
bs Dims asbs
Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn,
   MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) -> case () of
            ()
_ | Dict (KnownBackends t asbsn)
Dict <- InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn
              , Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
             -> DataFrame t asbsn -> DataFrame t asbs
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 ((Idxs asn -> DataFrame t bsn) -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen @t @asn @bsn @asbsn
                         (\Idxs asn
iN -> let i :: Idxs as
i = Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs Idxs asn
iN
                                 in  DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame (Idxs as -> DataFrame l bsL -> DataFrame r bsR -> DataFrame t bs
f Idxs as
Idxs as
i (Idxs as -> DataFrame l asbsL -> DataFrame l bsL
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame l asbsL
DataFrame l asbsL
dfl) (Idxs as -> DataFrame r asbsR -> DataFrame r bsR
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame r asbsR
DataFrame r asbsR
dfr))
                         )
                       )
{-# INLINE iwzip #-}

-- | DataFrames indexed by Nats and XNats require slightly different sets of
--   constraints to be sliced.
--   This family hides the difference, so that I could write one function for
--   both kinds.
type family CanSlice (t :: Type) (asbs :: [k])  :: Constraint where
  CanSlice t (asbs :: [Nat])
    = ( PrimArray t (DataFrame t asbs), Dimensions asbs )
  CanSlice t (asbs :: [XNat])
    = ( )

-- | Get a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `sindex`.
--
--   If (@b ~ XN m@) then this function is unsafe and can throw
--   an `OutOfDimBounds` exception.
--   Otherwise, its safety is guaranteed by the type system.
sslice ::
       forall t b bi bd bs
     . ( KnownDimKind (KindOfEl bs)
       , CanSlice t (b :+ bs)
       , SubFrameIndexCtx b bi bd, KnownDim bd
       , PrimArray t (DataFrame t (bd :+ bs)))
    => Idx bi -> DataFrame t (b :+ bs) -> DataFrame t (bd :+ bs)
sslice :: Idx bi -> DataFrame t (b :+ bs) -> DataFrame t (bd :+ bs)
sslice = (KnownDimKind k, CanSlice t (b :+ bs), SubFrameIndexCtx b bi bd,
 KnownDim bd, ConcatList '[] (b :+ bs) (b :+ bs),
 PrimArray t (DataFrame t (bd :+ bs))) =>
Idxs ('[] +: bi) -> DataFrame t (b :+ bs) -> DataFrame t (bd :+ bs)
forall k t (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k])
       (asbs :: [k]).
(KnownDimKind k, CanSlice t asbs, SubFrameIndexCtx b bi bd,
 KnownDim bd, ConcatList as (b :+ bs) asbs,
 PrimArray t (DataFrame t (bd :+ bs))) =>
Idxs (as +: bi) -> DataFrame t asbs -> DataFrame t (bd :+ bs)
slice @t @b @bi @bd @'[] @bs @(b :+ bs) (TypedList Idx '[bi]
 -> DataFrame t (b :+ bs) -> DataFrame t (bd :+ bs))
-> (Idx bi -> TypedList Idx '[bi])
-> Idx bi
-> DataFrame t (b :+ bs)
-> DataFrame t (bd :+ bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx bi -> TypedList Idx '[] -> TypedList Idx '[bi]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE[1] sslice #-}

-- | Update a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `supdate`.
--
--   If (@b ~ XN m@) and (@Idx bi + Dim bd > Dim b@), this function updates only as
--   many elements as fits into the dataframe along this dimension (possibly none).
supdateSlice ::
       forall t b bi bd bs
     . ( KnownDimKind (KindOfEl bs)
       , CanSlice t (b :+ bs)
       , SubFrameIndexCtx b bi bd
       , KnownDim bd, ExactDims bs
       , PrimArray t (DataFrame t (bd :+ bs)))
    => Idx bi -> DataFrame t (bd :+ bs)
    -> DataFrame t (b :+ bs) -> DataFrame t (b :+ bs)
supdateSlice :: Idx bi
-> DataFrame t (bd :+ bs)
-> DataFrame t (b :+ bs)
-> DataFrame t (b :+ bs)
supdateSlice = (KnownDimKind k, CanSlice t (b :+ bs), SubFrameIndexCtx b bi bd,
 KnownDim bd, ExactDims bs, ConcatList '[] (b :+ bs) (b :+ bs),
 PrimArray t (DataFrame t (bd :+ bs))) =>
Idxs ('[] +: bi)
-> DataFrame t (bd :+ bs)
-> DataFrame t (b :+ bs)
-> DataFrame t (b :+ bs)
forall k t (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k])
       (asbs :: [k]).
(KnownDimKind k, CanSlice t asbs, SubFrameIndexCtx b bi bd,
 KnownDim bd, ExactDims bs, ConcatList as (b :+ bs) asbs,
 PrimArray t (DataFrame t (bd :+ bs))) =>
Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> DataFrame t asbs -> DataFrame t asbs
updateSlice @t @b @bi @bd @'[] @bs @(b :+ bs) (TypedList Idx '[bi]
 -> DataFrame t (bd :+ bs)
 -> DataFrame t (b :+ bs)
 -> DataFrame t (b :+ bs))
-> (Idx bi -> TypedList Idx '[bi])
-> Idx bi
-> DataFrame t (bd :+ bs)
-> DataFrame t (b :+ bs)
-> DataFrame t (b :+ bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx bi -> TypedList Idx '[] -> TypedList Idx '[bi]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE[1] supdateSlice #-}

-- | Get a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `index`.
--
--   If any of the dims in @as@ or @b@ is unknown (@a ~ XN m@),
--   then this function is unsafe and can throw an `OutOfDimBounds` exception.
--   Otherwise, its safety is guaranteed by the type system.
slice ::
       forall (t :: Type) b bi bd as bs asbs
     . ( KnownDimKind (KindOfEl asbs)
       , CanSlice t asbs
       , SubFrameIndexCtx b bi bd, KnownDim bd
       , ConcatList as (b :+ bs) asbs
       , PrimArray t (DataFrame t (bd :+ bs)))
    => Idxs (as +: bi) -> DataFrame t asbs -> DataFrame t (bd :+ bs)
slice :: Idxs (as +: bi) -> DataFrame t asbs -> DataFrame t (bd :+ bs)
slice Idxs (as +: bi)
i = case KnownDimKind k => DimKind k
forall k. KnownDimKind k => DimKind k
dimKind @(KindOfEl asbs) of
  DimKind k
DimKNat
    -> (t -> DataFrame t (bd :+ bs))
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t (bd :+ bs))
-> DataFrame t asbs
-> DataFrame t (bd :+ bs)
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t (bd :+ bs)
forall t a. PrimArray t a => t -> a
broadcast
    (\CumulDims
steps Int#
off0 ByteArray#
ba ->
      let (Int
off, CumulDims
bsteps) = Int -> CumulDims -> Idxs (as +: bi) -> Dim bd -> (Int, CumulDims)
forall k1 k2 (ns :: [k1]) (idxN :: k1) (subN :: k2).
Int
-> CumulDims -> Idxs (ns +: idxN) -> Dim subN -> (Int, CumulDims)
getOffAndStepsSub (Int# -> Int
I# Int#
off0) CumulDims
steps Idxs (as +: bi)
i (KnownDim bd => Dim bd
forall k (n :: k). KnownDim n => Dim n
dim @bd)
      in CumulDims -> Int# -> ByteArray# -> DataFrame t (bd :+ bs)
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
bsteps (case Int
off of I# Int#
o -> Int#
o) ByteArray#
ba
    )
  DimKind k
DimKXNat
    -> \(XFrame (df :: DataFrame t asbsN)) -> (t -> DataFrame t (bd :+ bs))
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t (bd :+ bs))
-> DataFrame t ns
-> DataFrame t (bd :+ bs)
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t (bd :+ bs)
forall t a. PrimArray t a => t -> a
broadcast
    (\CumulDims
steps Int#
off0 ByteArray#
ba ->
      let (Int
off, CumulDims
bsteps) = Int -> CumulDims -> Idxs (as +: bi) -> Dim bd -> (Int, CumulDims)
forall k1 k2 (ns :: [k1]) (idxN :: k1) (subN :: k2).
Int
-> CumulDims -> Idxs (ns +: idxN) -> Dim subN -> (Int, CumulDims)
getOffAndStepsSub (Int# -> Int
I# Int#
off0) CumulDims
steps Idxs (as +: bi)
i (KnownDim bd => Dim bd
forall k (n :: k). KnownDim n => Dim n
dim @bd)
      in CumulDims -> Int# -> ByteArray# -> DataFrame t (bd :+ bs)
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
bsteps (case Int
off of I# Int#
o -> Int#
o) ByteArray#
ba
    ) DataFrame t ns
df
{-# INLINE[1] slice #-}

-- | Update a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `update`.
--
--   If any of the dims in @as@ is unknown (@a ~ XN m@),
--   you may happen to update data beyond dataframe bounds.
--   In this case, the original DataFrame is returned.
--   If (@b ~ XN m@) and (@Idx bi + Dim bd > Dim b@), this function updates only as
--   many elements as fits into the dataframe along this dimension (possibly none).
updateSlice ::
       forall (t :: Type) b bi bd as bs asbs
     . ( KnownDimKind (KindOfEl asbs)
       , CanSlice t asbs
       , SubFrameIndexCtx b bi bd
       , KnownDim bd, ExactDims bs
       , ConcatList as (b :+ bs) asbs
       , PrimArray t (DataFrame t (bd :+ bs)))
    => Idxs (as +: bi) -> DataFrame t (bd :+ bs)
    -> DataFrame t asbs -> DataFrame t asbs
updateSlice :: Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> DataFrame t asbs -> DataFrame t asbs
updateSlice Idxs (as +: bi)
i DataFrame t (bd :+ bs)
bdbsDf DataFrame t asbs
asbsDf = case KnownDimKind k => DimKind k
forall k. KnownDimKind k => DimKind k
dimKind @(KindOfEl asbs) of
  DimKind k
DimKNat -> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
      STDataFrame s t asbs
asbsM <- DataFrame t asbs -> ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(Dimensions ns, PrimArray t (DataFrame t ns)) =>
DataFrame t ns -> ST s (STDataFrame s t ns)
thawDataFrame DataFrame t asbs
asbsDf
      Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> STDataFrame s t asbs -> ST s ()
forall k t (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k])
       (asbs :: [k]) s.
(SubFrameIndexCtx b bi bd, KnownDim bd, ExactDims bs,
 PrimArray t (DataFrame t (bd :+ bs)),
 ConcatList as (b :+ bs) asbs) =>
Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> STDataFrame s t asbs -> ST s ()
copyDataFrame Idxs (as +: bi)
i DataFrame t (bd :+ bs)
bdbsDf STDataFrame s t asbs
asbsM
      STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
  DimKind k
DimKXNat
    | (XFrame (asbsDfN :: DataFrame t asbsN)) <- DataFrame t asbs
asbsDf -> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
      STDataFrame s t ns
asbsM <- DataFrame t ns -> ST s (STDataFrame s t ns)
forall k t (ns :: [k]) s.
(Dimensions ns, PrimArray t (DataFrame t ns)) =>
DataFrame t ns -> ST s (STDataFrame s t ns)
thawDataFrame @t @asbsN DataFrame t ns
asbsDfN
      Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> STDataFrame s t asbs -> ST s ()
forall k t (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k])
       (asbs :: [k]) s.
(SubFrameIndexCtx b bi bd, KnownDim bd, ExactDims bs,
 PrimArray t (DataFrame t (bd :+ bs)),
 ConcatList as (b :+ bs) asbs) =>
Idxs (as +: bi)
-> DataFrame t (bd :+ bs) -> STDataFrame s t asbs -> ST s ()
copyDataFrame Idxs (as +: bi)
i DataFrame t (bd :+ bs)
bdbsDf (STDataFrame s t ns -> STDataFrame s t asbs
forall t (xns :: [XNat]) (ns :: [Nat]) s.
FixedDims xns ns =>
STDataFrame s t ns -> STDataFrame s t xns
castDataFrame @t @asbs STDataFrame s t ns
asbsM)
      DataFrame t ns -> DataFrame t asbs
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 asbs)
-> ST s (DataFrame t ns) -> ST s (DataFrame t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STDataFrame s t ns -> ST s (DataFrame t ns)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t ns
asbsM
{-# INLINE[1] updateSlice #-}


-- | Get an element by its index in the dataframe.
--   This is a safe alternative to `(.!)` function when the index dimension
--   is not known at compile time (@a ~ XN m@).
slookup ::
       forall t (a :: XNat) (bs :: [XNat])
     . (All KnownDimType bs, PrimBytes t)
    => Idx a -> DataFrame t (a :+ bs) -> Maybe (DataFrame t bs)
slookup :: Idx a -> DataFrame t (a :+ bs) -> Maybe (DataFrame t bs)
slookup = (ConcatList '[a] bs (a :+ bs), All KnownDimType bs, PrimBytes t) =>
Idxs '[a] -> DataFrame t (a :+ bs) -> Maybe (DataFrame t bs)
forall t (as :: [XNat]) (bs :: [XNat]) (asbs :: [XNat]).
(ConcatList as bs asbs, All KnownDimType bs, PrimBytes t) =>
Idxs as -> DataFrame t asbs -> Maybe (DataFrame t bs)
Numeric.DataFrame.SubSpace.lookup @t @'[a] @bs @(a :+ bs) (Idxs '[a] -> DataFrame t (a :+ bs) -> Maybe (DataFrame t bs))
-> (Idx a -> Idxs '[a])
-> Idx a
-> DataFrame t (a :+ bs)
-> Maybe (DataFrame t bs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx a -> TypedList Idx '[] -> Idxs '[a]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:*TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE slookup #-}

-- | Get an element by its index in the dataframe.
--   This is a safe alternative to `index` function when some of the dimensions
--   are not known at compile time (@d ~ XN m@).
lookup ::
       forall t (as :: [XNat]) (bs :: [XNat]) (asbs :: [XNat])
     . (ConcatList as bs asbs, All KnownDimType bs, PrimBytes t)
    => Idxs as -> DataFrame t asbs -> Maybe (DataFrame t bs)
lookup :: Idxs as -> DataFrame t asbs -> Maybe (DataFrame t bs)
lookup Idxs as
i (XFrame (df :: DataFrame t asbsN))
  | Dims ns
asbsN <- Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN
  , Just Int
off <- CumulDims -> Idxs as -> Maybe Int
forall k (ns :: [k]). CumulDims -> Idxs ns -> Maybe Int
cdIxM (Dims ns -> DataFrame t ns -> CumulDims
forall t a k (ns :: [k]).
PrimArray t a =>
Dims ns -> a -> CumulDims
getSteps Dims ns
asbsN DataFrame t ns
df) Idxs as
i
  , Dims asbs
asbs <- Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims Dims ns
asbsN :: Dims asbs
  , (Dims as
as, Dims bs
bs) <- Idxs as -> Dims asbs -> (Dims as, Dims bs)
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]) (f :: k -> *).
ConcatList as bs asbs =>
TypedList f as -> Dims asbs -> (Dims as, Dims bs)
prefSufDims Idxs as
i Dims asbs
asbs
    = Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> Maybe (DataFrame t bs))
-> Maybe (DataFrame t bs)
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN) Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> Maybe (DataFrame t bs))
 -> Maybe (DataFrame t bs))
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> Maybe (DataFrame t bs))
-> Maybe (DataFrame t bs)
forall a b. (a -> b) -> a -> b
$
        \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
_ :: Dims asbsn)
          -> case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
            Dict (KnownBackends t bsn)
Dict -> DataFrame t bs -> Maybe (DataFrame t bs)
forall a. a -> Maybe a
Just (DataFrame t bsn -> DataFrame t bs
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 (Int -> DataFrame t asbsn -> DataFrame t bsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset @t @asn @bsn @asbsn Int
off DataFrame t ns
DataFrame t asbsn
df))
  | Bool
otherwise = Maybe (DataFrame t bs)
forall a. Maybe a
Nothing
{-# INLINE lookup #-}

-- | Get a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `slookup`.
--
--   This is a safe alternative to `sslice` function when the slice dimension
--   is not known at compile time (@b ~ XN m@).
ssliceMaybe ::
       forall (t :: Type) (b :: XNat) (bi :: XNat) (bd :: XNat) (bs :: [XNat])
     . ( SubFrameIndexCtx b bi bd, KnownDim bd
       , All KnownDimType bs, PrimBytes t)
    => Idx bi -> DataFrame t (b :+ bs) -> Maybe (DataFrame t (bd :+ bs))
ssliceMaybe :: Idx bi -> DataFrame t (b :+ bs) -> Maybe (DataFrame t (bd :+ bs))
ssliceMaybe = (SubFrameIndexCtx b bi bd, KnownDim bd,
 ConcatList '[] (b :+ bs) (b :+ bs), All KnownDimType bs,
 PrimBytes t) =>
Idxs ('[] +: bi)
-> DataFrame t (b :+ bs) -> Maybe (DataFrame t (bd :+ bs))
forall t (b :: XNat) (bi :: XNat) (bd :: XNat) (as :: [XNat])
       (bs :: [XNat]) (asbs :: [XNat]).
(SubFrameIndexCtx b bi bd, KnownDim bd,
 ConcatList as (b :+ bs) asbs, All KnownDimType bs, PrimBytes t) =>
Idxs (as +: bi)
-> DataFrame t asbs -> Maybe (DataFrame t (bd :+ bs))
sliceMaybe @t @b @bi @bd @'[] @bs @(b :+ bs) (TypedList Idx '[bi]
 -> DataFrame t (b :+ bs) -> Maybe (DataFrame t (bd :+ bs)))
-> (Idx bi -> TypedList Idx '[bi])
-> Idx bi
-> DataFrame t (b :+ bs)
-> Maybe (DataFrame t (bd :+ bs))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idx bi -> TypedList Idx '[] -> TypedList Idx '[bi]
forall k (f :: k -> *) (xs :: [k]) (y :: k) (ys :: [k]).
(xs ~ (y : ys)) =>
f y -> TypedList f ys -> TypedList f xs
:* TypedList Idx '[]
forall k (f :: k -> *) (xs :: [k]). (xs ~ '[]) => TypedList f xs
U)
{-# INLINE ssliceMaybe #-}


-- | Get a few contiguous elements.
--
--   In a sense, this is just a more complicated version of `lookup`.
--
--   This is a safe alternative to `slice` function when some of the dimensions
--   are not known at compile time (@d ~ XN m@).
sliceMaybe ::
       forall (t :: Type) (b :: XNat) bi bd as bs asbs
     . ( SubFrameIndexCtx b bi bd, KnownDim bd
       , ConcatList as (b :+ bs) asbs
       , All KnownDimType bs, PrimBytes t)
    => Idxs (as +: bi) -> DataFrame t asbs -> Maybe (DataFrame t (bd :+ bs))
sliceMaybe :: Idxs (as +: bi)
-> DataFrame t asbs -> Maybe (DataFrame t (bd :+ bs))
sliceMaybe Idxs (as +: bi)
i (XFrame (df :: DataFrame t asbsN))
  | Dims ns
asbsN <- Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN
  , Dim bd
bd <- KnownDim bd => Dim bd
forall k (n :: k). KnownDim n => Dim n
dim @bd
  , Dict
  (KnownDim (DimBound bd), KnownDimType bd,
   FixedDim bd (DimBound bd))
Dict <- ( ((KnownDim (DimBound bd), ExactDim bd, KnownDimType bd,
  FixedDim bd (DimBound bd)) =>
 Dict
   (KnownDim (DimBound bd), KnownDimType bd,
    FixedDim bd (DimBound bd)))
-> Dict
     (KnownDim (DimBound bd), KnownDimType bd,
      FixedDim bd (DimBound bd))
forall (d :: XNat) r.
KnownDim d =>
((KnownDim (DimBound d), ExactDim d, KnownDimType d,
  FixedDim d (DimBound d)) =>
 r)
-> r
withKnownXDim @bd (KnownDim (DimBound bd), ExactDim bd, KnownDimType bd,
 FixedDim bd (DimBound bd)) =>
Dict
  (KnownDim (DimBound bd), KnownDimType bd,
   FixedDim bd (DimBound bd))
forall (a :: Constraint). a => Dict a
Dict
      :: Dict (KnownDim (DimBound bd), KnownDimType bd, FixedDim bd (DimBound bd)))
  , Just (I# Int#
off0, bsteps :: CumulDims
bsteps@(CumulDims (Word
bbN:Word
bN:[Word]
_)))
      <- Int
-> CumulDims -> Idxs (as +: bi) -> Dim bd -> Maybe (Int, CumulDims)
forall k1 k2 (ns :: [k1]) (idxN :: k1) (subN :: k2).
Int
-> CumulDims
-> Idxs (ns +: idxN)
-> Dim subN
-> Maybe (Int, CumulDims)
getOffAndStepsSubM Int
0 (Dims ns -> DataFrame t ns -> CumulDims
forall t a k (ns :: [k]).
PrimArray t a =>
Dims ns -> a -> CumulDims
getSteps Dims ns
asbsN DataFrame t ns
df) Idxs (as +: bi)
i Dim bd
bd
  , Word
bbN Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
bN Word -> Word -> Word
forall a. Num a => a -> a -> a
* Dim bd -> Word
forall k (x :: k). Dim x -> Word
dimVal Dim bd
bd -- is there enough elements?
  , Dims asbs
asbs <- Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims Dims ns
asbsN :: Dims asbs
  , XDims (Dims ns
Dims :: Dims bsN) <-
      [Word] -> Dims bs
forall a b. a -> b
unsafeCoerce ([Word] -> [Word] -> [Word]
dropSome (Idxs (as +: bi) -> [Word]
forall k (ds :: [k]). Idxs ds -> [Word]
listIdxs Idxs (as +: bi)
i) (Dims asbs -> [Word]
forall k (xs :: [k]). Dims xs -> [Word]
listDims Dims asbs
asbs)) :: Dims bs
  , Dict (KnownBackends t (DimBound bd : ns))
Dict <- InferKnownBackend t (DimBound bd : ns) =>
Dict (KnownBackends t (DimBound bd : ns))
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @(DimBound bd ': bsN)
    = DataFrame t (bd :+ bs) -> Maybe (DataFrame t (bd :+ bs))
forall a. a -> Maybe a
Just (DataFrame t (bd :+ bs) -> Maybe (DataFrame t (bd :+ bs)))
-> DataFrame t (bd :+ bs) -> Maybe (DataFrame t (bd :+ bs))
forall a b. (a -> b) -> a -> b
$ DataFrame t (DimBound bd : ns) -> DataFrame t (bd :+ bs)
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 @_ @t @(bd :+ bs) @(DimBound bd ': bsN)
              ((t -> DataFrame t (DimBound bd : ns))
-> (CumulDims
    -> Int# -> ByteArray# -> DataFrame t (DimBound bd : ns))
-> DataFrame t ns
-> DataFrame t (DimBound bd : ns)
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t (DimBound bd : ns)
forall t a. PrimArray t a => t -> a
broadcast
                (\CumulDims
_ Int#
off -> CumulDims -> Int# -> ByteArray# -> DataFrame t (DimBound bd : ns)
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems CumulDims
bsteps (Int#
off0 Int# -> Int# -> Int#
+# Int#
off)) DataFrame t ns
df)
  | Bool
otherwise = Maybe (DataFrame t (bd :+ bs))
forall a. Maybe a
Nothing
{-# INLINE sliceMaybe #-}


-- | Operations on DataFrames
--
-- @as@ is an indexing dimensionality
--
-- @bs@ is an element dimensionality
--
-- @t@ is an underlying data type (i.e. Float, Int, Double)
--
class ( ConcatList as bs asbs
      , SubSpaceCtx t as bs asbs
      , PrimBytes t
      , KnownDimKind k
      ) => SubSpace (t :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k])
                    | asbs as -> bs, asbs bs -> as, as bs -> asbs where
    type SubSpaceCtx t as bs asbs :: Constraint

    joinDataFrameI :: PrimBytes (DataFrame t bs)
                   => DataFrame (DataFrame t bs) as -> DataFrame t asbs
    indexOffsetI :: Int -> DataFrame t asbs -> DataFrame t bs
    updateOffsetI :: Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
    indexI :: Idxs as -> DataFrame t asbs -> DataFrame t bs
    updateI :: Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
    ewmapI  :: forall s (bs' :: [k]) (asbs' :: [k])
             . SubSpace s as bs' asbs'
            => (DataFrame s bs' -> DataFrame t bs)
            -> DataFrame s asbs' -> DataFrame t asbs
    iwmapI  :: forall s (bs' :: [k]) (asbs' :: [k])
             . SubSpace s as bs' asbs'
            => (Idxs as -> DataFrame s bs' -> DataFrame t bs)
            -> DataFrame s asbs' -> DataFrame t asbs
    ewgenI :: Dimensions as => DataFrame t bs -> DataFrame t asbs
    iwgenI :: Dimensions as => (Idxs as -> DataFrame t bs) -> DataFrame t asbs
    ewfoldlI :: (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
    iwfoldlI :: (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
    ewfoldrI :: (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
    iwfoldrI :: (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
    elementWiseI :: forall (s :: Type) (bs' :: [k]) (asbs' :: [k]) (f :: Type -> Type)
                  . (Applicative f, SubSpace s as bs' asbs')
                 => (DataFrame s bs' -> f (DataFrame t bs))
                 -> DataFrame s asbs' -> f (DataFrame t asbs)
    elementWiseI = (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, Applicative f, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWiseI ((Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
 -> DataFrame s asbs' -> f (DataFrame t asbs))
-> ((DataFrame s bs' -> f (DataFrame t bs))
    -> Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> (DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs'
-> f (DataFrame t asbs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DataFrame s bs' -> f (DataFrame t bs))
-> Idxs as -> DataFrame s bs' -> f (DataFrame t bs)
forall a b. a -> b -> a
const
    {-# INLINE elementWiseI #-}
    indexWiseI :: forall (s :: Type) (bs' :: [k]) (asbs' :: [k]) (f :: Type -> Type)
                . (Applicative f, SubSpace s as bs' asbs')
               => (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
               -> DataFrame s asbs' -> f (DataFrame t asbs)

instance ( ConcatList as bs asbs
         , SubSpaceCtx t as bs asbs
         ) => SubSpace t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) where
    type SubSpaceCtx t as bs asbs
      = ( Dimensions as, Dimensions bs, Dimensions asbs
        , PrimArray t (DataFrame t asbs), PrimArray t (DataFrame t bs))

    joinDataFrameI :: DataFrame (DataFrame t bs) as -> DataFrame t asbs
joinDataFrameI
      | Dict (KnownBackends (DataFrame t bs) as)
Dict <- InferKnownBackend (DataFrame t bs) as =>
Dict (KnownBackends (DataFrame t bs) as)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @(DataFrame t bs) @as
        = (DataFrame t bs -> DataFrame t asbs)
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t asbs)
-> DataFrame (DataFrame t bs) as
-> DataFrame t asbs
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent DataFrame t bs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgenI
            (\CumulDims
steps -> CumulDims -> Int# -> ByteArray# -> DataFrame t asbs
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems (CumulDims
steps CumulDims -> CumulDims -> CumulDims
forall a. Monoid a => a -> a -> a
`mappend` Dims bs -> CumulDims
forall k (ns :: [k]). Dims ns -> CumulDims
cumulDims (Dimensions bs => Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @bs)))

    indexOffsetI :: Int -> DataFrame t asbs -> DataFrame t bs
indexOffsetI (I# Int#
off) = (t -> DataFrame t bs)
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t bs)
-> DataFrame t asbs
-> DataFrame t bs
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast
      (\CumulDims
steps Int#
off0 -> CumulDims -> Int# -> ByteArray# -> DataFrame t bs
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems (Dims as -> CumulDims -> CumulDims
forall (ns :: [Nat]). Dims ns -> CumulDims -> CumulDims
dropPref (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as) CumulDims
steps) (Int#
off0 Int# -> Int# -> Int#
+# Int#
off))
    {-# INLINE indexOffsetI #-}

    updateOffsetI :: Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffsetI Int
off DataFrame t bs
bs DataFrame t asbs
asbs = (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        STDataFrame s t asbs
asbsM <- DataFrame t asbs -> ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(Dimensions ns, PrimArray t (DataFrame t ns)) =>
DataFrame t ns -> ST s (STDataFrame s t ns)
thawDataFrame DataFrame t asbs
asbs
        Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(Dimensions bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrameOff Int
off DataFrame t bs
bs STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE updateOffsetI #-}

    indexI :: Idxs as -> DataFrame t asbs -> DataFrame t bs
indexI Idxs as
i = (t -> DataFrame t bs)
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t bs)
-> DataFrame t asbs
-> DataFrame t bs
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast
      (\CumulDims
steps Int#
off0 -> CumulDims -> Int# -> ByteArray# -> DataFrame t bs
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems (Dims as -> CumulDims -> CumulDims
forall (ns :: [Nat]). Dims ns -> CumulDims -> CumulDims
dropPref (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as) CumulDims
steps)
         (case CumulDims -> Idxs as -> Int
forall k (ns :: [k]). CumulDims -> Idxs ns -> Int
cdIx CumulDims
steps Idxs as
i of I# Int#
off -> Int#
off0 Int# -> Int# -> Int#
+# Int#
off))
    {-# INLINE indexI #-}

    updateI :: Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateI Idxs as
i DataFrame t bs
bs DataFrame t asbs
asbs = (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        STDataFrame s t asbs
asbsM <- DataFrame t asbs -> ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(Dimensions ns, PrimArray t (DataFrame t ns)) =>
DataFrame t ns -> ST s (STDataFrame s t ns)
thawDataFrame DataFrame t asbs
asbs
        Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(ExactDims bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrame' Idxs as
i DataFrame t bs
bs STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE updateI #-}

    ewmapI :: (DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmapI (DataFrame s bs' -> DataFrame t bs
f :: DataFrame s bs' -> DataFrame t bs) (DataFrame s asbs'
asbs' :: DataFrame s asbs')
      = case DataFrame s asbs' -> Either s CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame s asbs'
asbs' of
      Left s
e  -> DataFrame t bs -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgen (DataFrame s bs' -> DataFrame t bs
f (s -> DataFrame s bs'
forall t a. PrimArray t a => t -> a
broadcast s
e))
      Right CumulDims
_ -> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        let asTD :: Int
asTD  = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimensions as => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @as ) :: Int
            bsTD :: Int
bsTD  = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimensions bs => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @bs ) :: Int
            bs'TD :: Int
bs'TD = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimensions bs' => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @bs') :: Int
        STDataFrame s t asbs
asbsM <- ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(PrimBytes t, Dimensions ns) =>
ST s (STDataFrame s t ns)
newDataFrame
        [Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..Int
asTDInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
i ->
          Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(Dimensions bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrameOff (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
bsTD) (DataFrame s bs' -> DataFrame t bs
f (Int -> DataFrame s asbs' -> DataFrame s bs'
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
bs'TD) DataFrame s asbs'
asbs')) STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE ewmapI #-}

    iwmapI :: (Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmapI Idxs as -> DataFrame s bs' -> DataFrame t bs
f (DataFrame s asbs'
asbs' :: DataFrame s asbs')
      = case DataFrame s asbs' -> Either s CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame s asbs'
asbs' of
      Left s
e  -> (Idxs as -> DataFrame t bs) -> DataFrame t asbs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen ((Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s bs' -> Idxs as -> DataFrame t bs
forall a b c. (a -> b -> c) -> b -> a -> c
flip Idxs as -> DataFrame s bs' -> DataFrame t bs
f (s -> DataFrame s bs'
forall t a. PrimArray t a => t -> a
broadcast s
e))
      Right CumulDims
_ -> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        STDataFrame s t asbs
asbsM <- ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(PrimBytes t, Dimensions ns) =>
ST s (STDataFrame s t ns)
newDataFrame
        [Idxs as] -> (Idxs as -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Idxs as
forall a. Bounded a => a
minBound..Idxs as
forall a. Bounded a => a
maxBound] ((Idxs as -> ST s ()) -> ST s ())
-> (Idxs as -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Idxs as
i ->
          Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(ExactDims bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrame' Idxs as
i (Idxs as -> DataFrame s bs' -> DataFrame t bs
f Idxs as
i (Idxs as -> DataFrame s asbs' -> DataFrame s bs'
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame s asbs'
asbs')) STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE iwmapI #-}

    ewgenI :: DataFrame t bs -> DataFrame t asbs
ewgenI DataFrame t bs
bs = case DataFrame t bs -> Either t CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame t bs
bs of
      Left t
a -> t -> DataFrame t asbs
forall t a. PrimArray t a => t -> a
broadcast t
a
      Right CumulDims
bsSteps -> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        let asTD :: Int
asTD = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimensions as => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @as) :: Int
            bsTD :: Int
bsTD = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CumulDims -> Word
cdTotalDim CumulDims
bsSteps)
        STDataFrame s t asbs
asbsM <- ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(PrimBytes t, Dimensions ns) =>
ST s (STDataFrame s t ns)
newDataFrame
        [Int] -> (Int -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0, Int
bsTD .. Int
asTD Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
bsTD  Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
o -> Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(Dimensions bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrameOff Int
o DataFrame t bs
bs STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE ewgenI #-}

    iwgenI :: (Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgenI Idxs as -> DataFrame t bs
f = (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
        STDataFrame s t asbs
asbsM <- ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(PrimBytes t, Dimensions ns) =>
ST s (STDataFrame s t ns)
newDataFrame
        [Idxs as] -> (Idxs as -> ST s ()) -> ST s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Idxs as
forall a. Bounded a => a
minBound..Idxs as
forall a. Bounded a => a
maxBound] ((Idxs as -> ST s ()) -> ST s ())
-> (Idxs as -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Idxs as
i -> Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(ExactDims bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrame' Idxs as
i (Idxs as -> DataFrame t bs
f Idxs as
i) STDataFrame s t asbs
asbsM
        STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
asbsM
    {-# INLINE iwgenI #-}

    ewfoldlI :: (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldlI b -> DataFrame t bs -> b
f b
x0 DataFrame t asbs
asbs = case DataFrame t asbs -> Either t CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame t asbs
asbs of
      Left t
a ->
        let b :: DataFrame t bs
b = t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast t
a
            go :: Int -> b
go Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0     = b
x0
                 | Bool
otherwise = b -> DataFrame t bs -> b
f (Int -> b
go (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)) DataFrame t bs
b
        in  Int -> b
go (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimensions as => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @as) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 :: Int)
      Right CumulDims
asbsSteps ->
        let bsSteps :: CumulDims
bsSteps = Dims as -> CumulDims -> CumulDims
forall (ns :: [Nat]). Dims ns -> CumulDims -> CumulDims
dropPref (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as) CumulDims
asbsSteps
            bsLen :: Int
bsLen   = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CumulDims -> Word
cdTotalDim CumulDims
bsSteps)) :: Int
            asbsLen :: Int
asbsLen = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CumulDims -> Word
cdTotalDim CumulDims
asbsSteps) :: Int
            go :: Int -> b
go Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0     = b
x0
                 | Bool
otherwise = b -> DataFrame t bs -> b
f (Int -> b
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bsLen)) (Int -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset Int
i DataFrame t asbs
asbs)
        in  Int -> b
go (Int
asbsLen Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bsLen)
    {-# INLINE ewfoldlI #-}

    iwfoldlI :: (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldlI Idxs as -> b -> DataFrame t bs -> b
f b
x0 DataFrame t asbs
asbs
      | Bool -> Bool
not (Dims as -> Bool
forall k (ns :: [k]). Dims ns -> Bool
nonVoidDims (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as)) = b
x0
      | Bool
otherwise = case DataFrame t asbs -> Either t CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame t asbs
asbs of
        Left t
a ->
          let b :: DataFrame t bs
b = t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast t
a
              go :: Idxs as -> b
go Idxs as
i | Idxs as
i Idxs as -> Idxs as -> Bool
forall a. Eq a => a -> a -> Bool
== Idxs as
forall a. Bounded a => a
minBound = Idxs as -> b -> DataFrame t bs -> b
f Idxs as
i b
x0 DataFrame t bs
b
                   | Bool
otherwise     = Idxs as -> b -> DataFrame t bs -> b
f Idxs as
i (Idxs as -> b
go (Idxs as -> Idxs as
forall a. Enum a => a -> a
pred Idxs as
i)) DataFrame t bs
b
          in  Idxs as -> b
go Idxs as
forall a. Bounded a => a
maxBound
        Right CumulDims
_ ->
          let go :: Idxs as -> b
go Idxs as
i | Idxs as
i Idxs as -> Idxs as -> Bool
forall a. Eq a => a -> a -> Bool
== Idxs as
forall a. Bounded a => a
minBound = Idxs as -> b -> DataFrame t bs -> b
f Idxs as
i b
x0 (Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame t asbs
asbs)
                   | Bool
otherwise     = Idxs as -> b -> DataFrame t bs -> b
f Idxs as
i (Idxs as -> b
go (Idxs as -> Idxs as
forall a. Enum a => a -> a
pred Idxs as
i)) (Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame t asbs
asbs)
          in  Idxs as -> b
go Idxs as
forall a. Bounded a => a
maxBound
    {-# INLINE iwfoldlI #-}

    ewfoldrI :: (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldrI DataFrame t bs -> b -> b
f b
x0 DataFrame t asbs
asbs = case DataFrame t asbs -> Either t CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame t asbs
asbs of
        Left t
a ->
          let b :: DataFrame t bs
b = t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast t
a
              go :: Word -> b
go Word
i | Word
i Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Dimensions as => Word
forall k (xs :: [k]). Dimensions xs => Word
totalDim' @as = b
x0
                   | Bool
otherwise          = DataFrame t bs -> b -> b
f DataFrame t bs
b (Word -> b
go (Word
iWord -> Word -> Word
forall a. Num a => a -> a -> a
+Word
1))
          in  Word -> b
go Word
0
        Right CumulDims
asbsSteps ->
          let bsSteps :: CumulDims
bsSteps = Dims as -> CumulDims -> CumulDims
forall (ns :: [Nat]). Dims ns -> CumulDims -> CumulDims
dropPref (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as) CumulDims
asbsSteps
              bsLen :: Int
bsLen   = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CumulDims -> Word
cdTotalDim CumulDims
bsSteps)) :: Int
              asbsLen :: Int
asbsLen = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CumulDims -> Word
cdTotalDim CumulDims
asbsSteps) :: Int
              go :: Int -> b
go Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
asbsLen = b
x0
                   | Bool
otherwise    = DataFrame t bs -> b -> b
f (Int -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset Int
i DataFrame t asbs
asbs) (Int -> b
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
bsLen))
          in  Int -> b
go Int
0
    {-# INLINE ewfoldrI #-}

    iwfoldrI :: (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldrI Idxs as -> DataFrame t bs -> b -> b
f b
x0 DataFrame t asbs
asbs
      | Bool -> Bool
not (Dims as -> Bool
forall k (ns :: [k]). Dims ns -> Bool
nonVoidDims (Dimensions as => Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @as)) = b
x0
      | Bool
otherwise = case DataFrame t asbs -> Either t CumulDims
forall t a. PrimArray t a => a -> Either t CumulDims
uniqueOrCumulDims DataFrame t asbs
asbs of
        Left t
a ->
          let b :: DataFrame t bs
b = t -> DataFrame t bs
forall t a. PrimArray t a => t -> a
broadcast t
a
              go :: Idxs as -> b
go Idxs as
i | Idxs as
i Idxs as -> Idxs as -> Bool
forall a. Eq a => a -> a -> Bool
== Idxs as
forall a. Bounded a => a
maxBound = Idxs as -> DataFrame t bs -> b -> b
f Idxs as
i DataFrame t bs
b b
x0
                   | Bool
otherwise     = Idxs as -> DataFrame t bs -> b -> b
f Idxs as
i DataFrame t bs
b (Idxs as -> b
go (Idxs as -> Idxs as
forall a. Enum a => a -> a
succ Idxs as
i))
          in  Idxs as -> b
go Idxs as
forall a. Bounded a => a
minBound
        Right CumulDims
_ ->
          let go :: Idxs as -> b
go Idxs as
i | Idxs as
i Idxs as -> Idxs as -> Bool
forall a. Eq a => a -> a -> Bool
== Idxs as
forall a. Bounded a => a
maxBound = Idxs as -> DataFrame t bs -> b -> b
f Idxs as
i (Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame t asbs
asbs) b
x0
                   | Bool
otherwise     = Idxs as -> DataFrame t bs -> b -> b
f Idxs as
i (Idxs as -> DataFrame t asbs -> DataFrame t bs
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index Idxs as
i DataFrame t asbs
asbs) (Idxs as -> b
go (Idxs as -> Idxs as
forall a. Enum a => a -> a
succ Idxs as
i))
          in  Idxs as -> b
go Idxs as
forall a. Bounded a => a
minBound
    {-# INLINE iwfoldrI #-}

    indexWiseI :: (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWiseI (Idxs as -> DataFrame s bs' -> f (DataFrame t bs)
f :: Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
        = (MakingDF t asbs -> DataFrame t asbs)
-> f (MakingDF t asbs) -> f (DataFrame t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MakingDF t asbs -> DataFrame t asbs
mkSTDF (f (MakingDF t asbs) -> f (DataFrame t asbs))
-> (DataFrame s asbs' -> f (MakingDF t asbs))
-> DataFrame s asbs'
-> f (DataFrame t asbs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Idxs as
 -> DataFrame s bs' -> f (MakingDF t asbs) -> f (MakingDF t asbs))
-> f (MakingDF t asbs) -> DataFrame s asbs' -> f (MakingDF t asbs)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr Idxs as
-> DataFrame s bs' -> f (MakingDF t asbs) -> f (MakingDF t asbs)
fST (MakingDF t asbs -> f (MakingDF t asbs)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MakingDF t asbs -> f (MakingDF t asbs))
-> MakingDF t asbs -> f (MakingDF t asbs)
forall a b. (a -> b) -> a -> b
$ (forall s. STDataFrame s t asbs -> ST s ()) -> MakingDF t asbs
forall k t (asbs :: [k]).
(forall s. STDataFrame s t asbs -> ST s ()) -> MakingDF t asbs
MakingDF (ST s () -> STDataFrame s t asbs -> ST s ()
forall a b. a -> b -> a
const (() -> ST s ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())))
      where
        mkSTDF :: MakingDF t asbs -> DataFrame t asbs
        mkSTDF :: MakingDF t asbs -> DataFrame t asbs
mkSTDF MakingDF t asbs
st = (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs)
-> (forall s. ST s (DataFrame t asbs)) -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ do
          STDataFrame s t asbs
df <- ST s (STDataFrame s t asbs)
forall k t (ns :: [k]) s.
(PrimBytes t, Dimensions ns) =>
ST s (STDataFrame s t ns)
newDataFrame
          MakingDF t asbs -> STDataFrame s t asbs -> ST s ()
forall t k (asbs :: [k]).
MakingDF t asbs -> forall s. STDataFrame s t asbs -> ST s ()
getMDF MakingDF t asbs
st STDataFrame s t asbs
df
          STDataFrame s t asbs -> ST s (DataFrame t asbs)
forall k t (ns :: [k]) s.
PrimArray t (DataFrame t ns) =>
STDataFrame s t ns -> ST s (DataFrame t ns)
unsafeFreezeDataFrame STDataFrame s t asbs
df
        fST :: Idxs as -> DataFrame s bs'
            -> f (MakingDF t asbs) -> f (MakingDF t asbs)
        fST :: Idxs as
-> DataFrame s bs' -> f (MakingDF t asbs) -> f (MakingDF t asbs)
fST Idxs as
i DataFrame s bs'
bs' f (MakingDF t asbs)
asbsSTF
          = (\DataFrame t bs
r MakingDF t asbs
st -> (forall s. STDataFrame s t asbs -> ST s ()) -> MakingDF t asbs
forall k t (asbs :: [k]).
(forall s. STDataFrame s t asbs -> ST s ()) -> MakingDF t asbs
MakingDF (\STDataFrame s t asbs
x -> Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s.
(ExactDims bs, PrimArray t (DataFrame t bs),
 ConcatList as bs asbs) =>
Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s ()
copyDataFrame' Idxs as
i DataFrame t bs
r STDataFrame s t asbs
x ST s () -> ST s () -> ST s ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MakingDF t asbs -> STDataFrame s t asbs -> ST s ()
forall t k (asbs :: [k]).
MakingDF t asbs -> forall s. STDataFrame s t asbs -> ST s ()
getMDF MakingDF t asbs
st STDataFrame s t asbs
x))
             (DataFrame t bs -> MakingDF t asbs -> MakingDF t asbs)
-> f (DataFrame t bs) -> f (MakingDF t asbs -> MakingDF t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Idxs as -> DataFrame s bs' -> f (DataFrame t bs)
f Idxs as
i DataFrame s bs'
bs' f (MakingDF t asbs -> MakingDF t asbs)
-> f (MakingDF t asbs) -> f (MakingDF t asbs)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (MakingDF t asbs)
asbsSTF
    {-# INLINE indexWiseI #-}

-- | Hide ST monad state with a DataFrame in works inside a plain type.
newtype MakingDF t asbs
  = MakingDF { MakingDF t asbs -> forall s. STDataFrame s t asbs -> ST s ()
getMDF :: forall s . STDataFrame s t asbs -> ST s () }

-- | Checks if all of the dimensions are non-zero.
nonVoidDims :: Dims ns -> Bool
nonVoidDims :: Dims ns -> Bool
nonVoidDims = (Word -> Bool) -> [Word] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Word
0 Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<) ([Word] -> Bool) -> (Dims ns -> [Word]) -> Dims ns -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dims ns -> [Word]
forall k (xs :: [k]). Dims xs -> [Word]
listDims

dropPref :: Dims (ns :: [Nat]) -> CumulDims -> CumulDims
dropPref :: Dims ns -> CumulDims -> CumulDims
dropPref Dims ns
ds = [Word] -> CumulDims
CumulDims ([Word] -> CumulDims)
-> (CumulDims -> [Word]) -> CumulDims -> CumulDims
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word] -> [Word] -> [Word]
dropSome (Dims ns -> [Word]
forall k (xs :: [k]). Dims xs -> [Word]
listDims Dims ns
ds) ([Word] -> [Word]) -> (CumulDims -> [Word]) -> CumulDims -> [Word]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CumulDims -> [Word]
unCumulDims

dropSome :: [Word] -> [Word] -> [Word]
dropSome :: [Word] -> [Word] -> [Word]
dropSome []     [Word]
xs = [Word]
xs
dropSome (Word
_:[Word]
as) [Word]
xs = [Word] -> [Word] -> [Word]
dropSome [Word]
as ([Word] -> [Word]
forall a. [a] -> [a]
tail [Word]
xs)

instance ( ConcatList as bs asbs
         , SubSpaceCtx t as bs asbs
         ) => SubSpace t (as :: [XNat]) (bs :: [XNat]) (asbs :: [XNat]) where
    type SubSpaceCtx t as bs asbs
      = ( Dimensions bs, PrimBytes t, ExactDims bs
        , All KnownDimType as, All KnownDimType bs, All KnownDimType asbs)

    joinDataFrameI :: DataFrame (DataFrame t bs) as -> DataFrame t asbs
joinDataFrameI (XFrame (df :: DataFrame (DataFrame t bs) asN)) =
      let as :: Dims as
as   = Dims ns -> Dims as
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asN) :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just ns) asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @('Just asN) @('Just (DimsBound bs)) @'Nothing
                              Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq ('Just ns) asn,
   MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just ns) asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) -> case () of
            ()
_ | Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
              , Dict (KnownBackends t asbsn)
Dict <- InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn
                -> (All KnownDimType asbs, FixedDims asbs asbsn, Dimensions asbsn,
 KnownBackends t asbsn) =>
DataFrame t asbsn -> DataFrame t asbs
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 @_ @t @asbs @asbsn (DataFrame t asbsn -> DataFrame t asbs)
-> DataFrame t asbsn -> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$ (DataFrame t bs -> DataFrame t asbsn)
-> (CumulDims -> Int# -> ByteArray# -> DataFrame t asbsn)
-> DataFrame (DataFrame t bs) ns
-> DataFrame t asbsn
forall t a r.
PrimArray t a =>
(t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
withArrayContent
                                                -- know for sure its DataFrame t bsn
                    ((SubSpace t asn bsn asbsn, Dimensions asn) =>
DataFrame t bsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgen @t @asn @bsn @asbsn (DataFrame t bsn -> DataFrame t asbsn)
-> (DataFrame t bs -> DataFrame t bsn)
-> DataFrame t bs
-> DataFrame t asbsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame)
                    (\CumulDims
steps -> CumulDims -> Int# -> ByteArray# -> DataFrame t asbsn
forall t a. PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
fromElems (CumulDims
steps CumulDims -> CumulDims -> CumulDims
forall a. Monoid a => a -> a -> a
`mappend` Dims bs -> CumulDims
forall k (ns :: [k]). Dims ns -> CumulDims
cumulDims (Dimensions bs => Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @bs)))
                    DataFrame (DataFrame t bs) ns
df
    {-# INLINE joinDataFrameI #-}

    indexOffsetI :: Int -> DataFrame t asbs -> DataFrame t bs
indexOffsetI Int
off (XFrame (df :: DataFrame t asbsN)) =
      let bs :: Dims bs
bs = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          as :: Dims as
as = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
-> DataFrame t bs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @('Just (DimsBound bs)) @('Just asbsN)
                              Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn,
   MayEq ('Just (DimsBound bs)) bsn, MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
 -> DataFrame t bs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn,
     MayEq ('Just (DimsBound bs)) bsn, MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
-> DataFrame t bs
forall a b. (a -> b) -> a -> b
$
           \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn)
             -> case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
               Dict (KnownBackends t bsn)
Dict -> DataFrame t bsn -> DataFrame t bs
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 (Int -> DataFrame t asbsn -> DataFrame t bsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t asbs -> DataFrame t bs
indexOffset @t @asn @bsn @asbsn Int
off DataFrame t ns
DataFrame t asbsn
df)
    {-# INLINE indexOffsetI #-}

    updateOffsetI :: Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffsetI Int
off (XFrame (bsDf :: DataFrame t bsN))
                      (XFrame (asbsDf :: DataFrame t asbsN)) =
      let bs :: Dims bs
bs = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          as :: Dims as
as = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @('Just bsN) @('Just asbsN)
                              Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
           \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn)
             -> DataFrame t asbsn -> DataFrame t asbs
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 (Int -> DataFrame t bsn -> DataFrame t asbsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Int -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateOffset @t @asn @bsn @asbsn Int
off DataFrame t ns
DataFrame t bsn
bsDf DataFrame t ns
DataFrame t asbsn
asbsDf)
    {-# INLINE updateOffsetI #-}

    indexI :: Idxs as -> DataFrame t asbs -> DataFrame t bs
indexI Idxs as
i (XFrame (df :: DataFrame t asbsN)) =
      let bs :: Dims bs
bs = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          as :: Dims as
as = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
-> DataFrame t bs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN)
                              Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
 -> DataFrame t bs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t bs)
-> DataFrame t bs
forall a b. (a -> b) -> a -> b
$
           \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn)
             -> case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
               Dict (KnownBackends t bsn)
Dict -> DataFrame t bsn -> DataFrame t bs
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 (Idxs asn -> DataFrame t asbsn -> DataFrame t bsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t asbs -> DataFrame t bs
index @t @asn @bsn @asbsn (Idxs as -> Idxs asn
forall (ds :: [XNat]) (ns :: [Nat]).
(FixedDims ds ns, Dimensions ns) =>
Idxs ds -> Idxs ns
unsafeUnliftIdxs Idxs as
i) DataFrame t ns
DataFrame t asbsn
df)
    {-# INLINE indexI #-}

    updateI :: Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
updateI Idxs as
i (XFrame (bsDf :: DataFrame t bsN))
              (XFrame (asbsDf :: DataFrame t asbsN)) =
      let bs :: Dims bs
bs = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          as :: Dims as
as = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @('Just bsN) @('Just asbsN)
                              Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
           \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn)
             -> DataFrame t asbsn -> DataFrame t asbs
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 (Idxs asn
-> DataFrame t bsn -> DataFrame t asbsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
SubSpace t as bs asbs =>
Idxs as -> DataFrame t bs -> DataFrame t asbs -> DataFrame t asbs
update @t @asn @bsn @asbsn (Idxs as -> Idxs asn
forall (ds :: [XNat]) (ns :: [Nat]).
(FixedDims ds ns, Dimensions ns) =>
Idxs ds -> Idxs ns
unsafeUnliftIdxs Idxs as
i) DataFrame t ns
DataFrame t bsn
bsDf DataFrame t ns
DataFrame t asbsn
asbsDf)
    {-# INLINE updateI #-}

    ewmapI  :: forall s (bs' :: [XNat]) (asbs' :: [XNat])
             . SubSpace s as bs' asbs'
            => (DataFrame s bs' -> DataFrame t bs)
            -> DataFrame s asbs' -> DataFrame t asbs
    ewmapI :: (DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmapI DataFrame s bs' -> DataFrame t bs
f (XFrame (df :: DataFrame s asbsN')) =
      let bs :: Dims bs
bs    = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          bs' :: Dims bs'
bs'   = Dims bs'
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs'
          as :: Dims as
as    = Dims bs' -> Dims asbs' -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs'
bs' Dims asbs'
asbs' :: Dims as
          asbs' :: Dims asbs'
asbs' = Dims ns -> Dims asbs'
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN') :: Dims asbs'
          asbs :: Dims asbs
asbs  = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs'
-> Dims asbs'
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN')
                              Dims as
as Dims bs'
bs' Dims asbs'
asbs' ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
   FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
         \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn') (Dims asbsn
Dims :: Dims asbsn') ->
         Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @('Just asn) @'Nothing @'Nothing
                                Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
   MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
         \(Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
           case InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn of
            Dict (KnownBackends t asbsn)
Dict
             | Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
             , Dict (KnownBackends s bsn)
Dict <- InferKnownBackend s bsn => Dict (KnownBackends s bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @s @bsn'
             -> DataFrame t asbsn -> DataFrame t asbs
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 s bsn -> DataFrame t bsn)
-> DataFrame s asbsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
ewmap @t @asn @bsn @asbsn @s @bsn' @asbsn'
                        (DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame (DataFrame t bs -> DataFrame t bsn)
-> (DataFrame s bsn -> DataFrame t bs)
-> DataFrame s bsn
-> DataFrame t bsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame s bs' -> DataFrame t bs
f (DataFrame s bs' -> DataFrame t bs)
-> (DataFrame s bsn -> DataFrame s bs')
-> DataFrame s bsn
-> DataFrame t bs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataFrame s bsn -> DataFrame s bs'
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 s ns
DataFrame s asbsn
df)
    {-# INLINE ewmapI #-}

    iwmapI  :: forall s (bs' :: [XNat]) (asbs' :: [XNat])
             . SubSpace s as bs' asbs'
            => (Idxs as -> DataFrame s bs' -> DataFrame t bs)
            -> DataFrame s asbs' -> DataFrame t asbs
    iwmapI :: (Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmapI Idxs as -> DataFrame s bs' -> DataFrame t bs
f (XFrame (df :: DataFrame s asbsN')) =
      let bs :: Dims bs
bs    = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          bs' :: Dims bs'
bs'   = Dims bs'
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs'
          as :: Dims as
as    = Dims bs' -> Dims asbs' -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs'
bs' Dims asbs'
asbs' :: Dims as
          asbs' :: Dims asbs'
asbs' = Dims ns -> Dims asbs'
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN') :: Dims asbs'
          asbs :: Dims asbs
asbs  = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs'
-> Dims asbs'
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN')
                              Dims as
as Dims bs'
bs' Dims asbs'
asbs' ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
   FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
         \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn') (Dims asbsn
Dims :: Dims asbsn') ->
         Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @('Just asn) @'Nothing @'Nothing
                                Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
   MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
         \(Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) -> case () of
           ()
_ | Dict (KnownBackends t asbsn)
Dict <- InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn
             , Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
             , Dict (KnownBackends s bsn)
Dict <- InferKnownBackend s bsn => Dict (KnownBackends s bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @s @bsn'
               -> DataFrame t asbsn -> DataFrame t asbs
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 ((Idxs asn -> DataFrame s bsn -> DataFrame t bsn)
-> DataFrame s asbsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]).
(SubSpace t as bs asbs, SubSpace s as bs' asbs') =>
(Idxs as -> DataFrame s bs' -> DataFrame t bs)
-> DataFrame s asbs' -> DataFrame t asbs
iwmap @t @asn @bsn @asbsn @s @bsn' @asbsn'
                           (\Idxs asn
i DataFrame s bsn
x -> DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame (Idxs as -> DataFrame s bs' -> DataFrame t bs
f (Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs Idxs asn
i) (DataFrame s bsn -> DataFrame s bs'
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 s bsn
x))) DataFrame s ns
DataFrame s asbsn
df)
    {-# INLINE iwmapI #-}


    ewgenI :: DataFrame t bs -> DataFrame t asbs
ewgenI (XFrame (df :: DataFrame t bsN)) =
      let as :: Dims as
as   = Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @('Just bsN) @'Nothing Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
   MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq ('Just ns) bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
            case InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn of
              Dict (KnownBackends t asbsn)
Dict -> DataFrame t asbsn -> DataFrame t asbs
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 bsn -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
DataFrame t bs -> DataFrame t asbs
ewgen @t @asn @bsn @asbsn DataFrame t ns
DataFrame t bsn
df)
    {-# INLINE ewgenI #-}

    iwgenI :: (Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgenI Idxs as -> DataFrame t bs
f =
      let as :: Dims as
as   = Dims as
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @'Nothing Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
 -> DataFrame t asbs)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> DataFrame t asbs)
-> DataFrame t asbs
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) -> case () of
            ()
_ | Dict (KnownBackends t asbsn)
Dict <- InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn
              , Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
                 -> DataFrame t asbsn -> DataFrame t asbs
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 ((Idxs asn -> DataFrame t bsn) -> DataFrame t asbsn
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]).
(SubSpace t as bs asbs, Dimensions as) =>
(Idxs as -> DataFrame t bs) -> DataFrame t asbs
iwgen @t @asn @bsn @asbsn (DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame (DataFrame t bs -> DataFrame t bsn)
-> (Idxs asn -> DataFrame t bs) -> Idxs asn -> DataFrame t bsn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Idxs as -> DataFrame t bs
f (Idxs as -> DataFrame t bs)
-> (Idxs asn -> Idxs as) -> Idxs asn -> DataFrame t bs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs))
    {-# INLINE iwgenI #-}

    ewfoldlI :: (b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldlI b -> DataFrame t bs -> b
f b
x0 (XFrame (df :: DataFrame s asbsN)) =
      let as :: Dims as
as   = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN) Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> b)
 -> b)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
           case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
             Dict (KnownBackends t bsn)
Dict -> (b -> DataFrame t bsn -> b) -> b -> DataFrame t asbsn -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
ewfoldl @t @asn @bsn @asbsn (\b
b DataFrame t bsn
x -> b -> DataFrame t bs -> b
f b
b (DataFrame t bsn -> DataFrame t bs
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 bsn
x)) b
x0 DataFrame t ns
DataFrame t asbsn
df
    {-# INLINE ewfoldlI #-}

    iwfoldlI :: (Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldlI Idxs as -> b -> DataFrame t bs -> b
f b
x0 (XFrame (df :: DataFrame s asbsN)) =
      let as :: Dims as
as   = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN) Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> b)
 -> b)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
           case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
             Dict (KnownBackends t bsn)
Dict -> (Idxs asn -> b -> DataFrame t bsn -> b)
-> b -> DataFrame t asbsn -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> b -> DataFrame t bs -> b) -> b -> DataFrame t asbs -> b
iwfoldl @t @asn @bsn @asbsn
                       (\Idxs asn
i b
b DataFrame t bsn
x -> Idxs as -> b -> DataFrame t bs -> b
f (Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs Idxs asn
i) b
b (DataFrame t bsn -> DataFrame t bs
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 bsn
x)) b
x0 DataFrame t ns
DataFrame t asbsn
df
    {-# INLINE iwfoldlI #-}

    ewfoldrI :: (DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldrI DataFrame t bs -> b -> b
f b
x0 (XFrame (df :: DataFrame s asbsN)) =
      let as :: Dims as
as   = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN) Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> b)
 -> b)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
           case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
             Dict (KnownBackends t bsn)
Dict -> (DataFrame t bsn -> b -> b) -> b -> DataFrame t asbsn -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
ewfoldr @t @asn @bsn @asbsn (\DataFrame t bsn
x -> DataFrame t bs -> b -> b
f (DataFrame t bsn -> DataFrame t bs
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 bsn
x)) b
x0 DataFrame t ns
DataFrame t asbsn
df
    {-# INLINE ewfoldrI #-}

    iwfoldrI :: (Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldrI Idxs as -> DataFrame t bs -> b -> b
f b
x0 (XFrame (df :: DataFrame s asbsN)) =
      let as :: Dims as
as   = Dims bs -> Dims asbs -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs
bs Dims asbs
asbs :: Dims as
          bs :: Dims bs
bs   = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          asbs :: Dims asbs
asbs = Dims ns -> Dims asbs
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN) :: Dims asbs
      in Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN) Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> b)
 -> b)
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> b)
-> b
forall a b. (a -> b) -> a -> b
$
          \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) ->
           case InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn of
             Dict (KnownBackends t bsn)
Dict -> (Idxs asn -> DataFrame t bsn -> b -> b)
-> b -> DataFrame t asbsn -> b
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) b.
SubSpace t as bs asbs =>
(Idxs as -> DataFrame t bs -> b -> b) -> b -> DataFrame t asbs -> b
iwfoldr @t @asn @bsn @asbsn
                       (\Idxs asn
i DataFrame t bsn
x -> Idxs as -> DataFrame t bs -> b -> b
f (Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs Idxs asn
i) (DataFrame t bsn -> DataFrame t bs
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 bsn
x)) b
x0 DataFrame t ns
DataFrame t asbsn
df
    {-# INLINE iwfoldrI #-}

    indexWiseI :: forall s (bs' :: [XNat]) (asbs' :: [XNat]) f
                . (Applicative f, SubSpace s as bs' asbs')
               => (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
               -> DataFrame s asbs' -> f (DataFrame t asbs)
    indexWiseI :: (Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWiseI Idxs as -> DataFrame s bs' -> f (DataFrame t bs)
f (XFrame (df :: DataFrame s asbsN')) =
      let bs :: Dims bs
bs    = Dims bs
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs
          bs' :: Dims bs'
bs'   = Dims bs'
forall k (ds :: [k]). Dimensions ds => Dims ds
dims :: Dims bs'
          as :: Dims as
as    = Dims bs' -> Dims asbs' -> Dims as
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims bs -> Dims asbs -> Dims as
dropSufDims Dims bs'
bs' Dims asbs'
asbs' :: Dims as
          asbs' :: Dims asbs'
asbs' = Dims ns -> Dims asbs'
forall (ds :: [XNat]) (ns :: [Nat]).
(KnownDimKind XNat, FixedDims ds ns) =>
Dims ns -> Dims ds
XDims (Dimensions ns => Dims ns
forall k (ds :: [k]). Dimensions ds => Dims ds
dims @asbsN') :: Dims asbs'
          asbs :: Dims asbs
asbs  = Dims as -> Dims bs -> Dims asbs
forall k (as :: [k]) (bs :: [k]) (asbs :: [k]).
ConcatList as bs asbs =>
Dims as -> Dims bs -> Dims asbs
concatDims Dims as
as Dims bs
bs :: Dims asbs
      in Dims as
-> Dims bs'
-> Dims asbs'
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
-> f (DataFrame t asbs)
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @'Nothing @'Nothing @('Just asbsN')
                              Dims as
as Dims bs'
bs' Dims asbs'
asbs' ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
   FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
   MayEq ('Just ns) asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
 -> f (DataFrame t asbs))
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs' bsn,
     FixedDims asbs' asbsn, MayEq 'Nothing asn, MayEq 'Nothing bsn,
     MayEq ('Just ns) asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
-> f (DataFrame t asbs)
forall a b. (a -> b) -> a -> b
$
         \(Dims asn
Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn') (Dims asbsn
Dims :: Dims asbsn') ->
         Dims as
-> Dims bs
-> Dims asbs
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
-> f (DataFrame t asbs)
forall (asm :: Maybe [Nat]) (bsm :: Maybe [Nat])
       (asbsm :: Maybe [Nat]) (asx :: [XNat]) (bsx :: [XNat])
       (asbsx :: [XNat]) r.
Dims asx
-> Dims bsx
-> Dims asbsx
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims asx asn, FixedDims bsx bsn,
     FixedDims asbsx asbsn, MayEq asm asn, MayEq bsm bsn,
     MayEq asbsm asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> r)
-> r
withLiftedConcatList @('Just asn) @'Nothing @'Nothing
                                Dims as
as Dims bs
bs Dims asbs
asbs ((forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
  (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
   FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
   MayEq 'Nothing asbsn) =>
  Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
 -> f (DataFrame t asbs))
-> (forall (asn :: [Nat]) (bsn :: [Nat]) (asbsn :: [Nat]).
    (ConcatList asn bsn asbsn, FixedDims as asn, FixedDims bs bsn,
     FixedDims asbs asbsn, MayEq ('Just asn) asn, MayEq 'Nothing bsn,
     MayEq 'Nothing asbsn) =>
    Dims asn -> Dims bsn -> Dims asbsn -> f (DataFrame t asbs))
-> f (DataFrame t asbs)
forall a b. (a -> b) -> a -> b
$
         \(Dims :: Dims asn) (Dims bsn
Dims :: Dims bsn) (Dims asbsn
Dims :: Dims asbsn) -> case () of
           ()
_ | Dict (KnownBackends t asbsn)
Dict <- InferKnownBackend t asbsn => Dict (KnownBackends t asbsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @asbsn
             , Dict (KnownBackends t bsn)
Dict <- InferKnownBackend t bsn => Dict (KnownBackends t bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @t @bsn
             , Dict (KnownBackends s bsn)
Dict <- InferKnownBackend s bsn => Dict (KnownBackends s bsn)
forall k (t :: k) (ds :: [Nat]).
InferKnownBackend t ds =>
Dict (KnownBackends t ds)
inferKnownBackend @s @bsn'
               -> DataFrame t asbsn -> DataFrame t asbs
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 asbsn -> DataFrame t asbs)
-> f (DataFrame t asbsn) -> f (DataFrame t asbs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                         ((Idxs asn -> DataFrame s bsn -> f (DataFrame t bsn))
-> DataFrame s asbsn -> f (DataFrame t asbsn)
forall k t (as :: [k]) (bs :: [k]) (asbs :: [k]) s (bs' :: [k])
       (asbs' :: [k]) (f :: * -> *).
(SubSpace t as bs asbs, SubSpace s as bs' asbs', Applicative f) =>
(Idxs as -> DataFrame s bs' -> f (DataFrame t bs))
-> DataFrame s asbs' -> f (DataFrame t asbs)
indexWise @t @asn @bsn @asbsn @s @bsn' @asbsn'
                           (\Idxs asn
i DataFrame s bsn
x -> DataFrame t bs -> DataFrame t bsn
forall t (xns :: [XNat]) (ns :: [Nat]).
(ExactDims xns, FixedDims xns ns) =>
DataFrame t xns -> DataFrame t ns
unliftXFrame (DataFrame t bs -> DataFrame t bsn)
-> f (DataFrame t bs) -> f (DataFrame t bsn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Idxs as -> DataFrame s bs' -> f (DataFrame t bs)
f (Idxs asn -> Idxs as
forall (ds :: [XNat]) (ns :: [Nat]).
FixedDims ds ns =>
Idxs ns -> Idxs ds
liftIdxs Idxs asn
i) (DataFrame s bsn -> DataFrame s bs'
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 s bsn
x)) DataFrame s ns
DataFrame s asbsn
df
                         )
    {-# INLINE indexWiseI #-}

dropSufDims :: ConcatList as bs asbs
            => Dims bs -> Dims asbs -> Dims as
dropSufDims :: Dims bs -> Dims asbs -> Dims as
dropSufDims = ([Word] -> [Word] -> [Word]) -> Dims bs -> Dims asbs -> Dims as
forall a b. a -> b
unsafeCoerce [Word] -> [Word] -> [Word]
dropSuf
  where
    dropSuf :: [Word] -> [Word] -> [Word]
    dropSuf :: [Word] -> [Word] -> [Word]
dropSuf [Word]
bs [Word]
asbs = ([Word], [Word]) -> [Word]
forall a b. (a, b) -> a
fst (([Word], [Word]) -> [Word]) -> ([Word], [Word]) -> [Word]
forall a b. (a -> b) -> a -> b
$ (Word -> ([Word], [Word]) -> ([Word], [Word]))
-> ([Word], [Word]) -> [Word] -> ([Word], [Word])
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Word -> ([Word], [Word]) -> ([Word], [Word])
f ([], [Word]
bs) [Word]
asbs
    f :: Word -> ([Word], [Word]) -> ([Word], [Word])
    f :: Word -> ([Word], [Word]) -> ([Word], [Word])
f Word
x ([Word]
as, [])  = (Word
xWord -> [Word] -> [Word]
forall a. a -> [a] -> [a]
:[Word]
as,[])
    f Word
_ ([Word]
_, Word
_:[Word]
rs) = ([], [Word]
rs)

prefSufDims :: ConcatList as bs asbs
             => TypedList f as -> Dims asbs -> (Dims as, Dims bs)
prefSufDims :: TypedList f as -> Dims asbs -> (Dims as, Dims bs)
prefSufDims = ([Word] -> [Word] -> ([Word], [Word]))
-> TypedList f as -> Dims asbs -> (Dims as, Dims bs)
forall a b. a -> b
unsafeCoerce [Word] -> [Word] -> ([Word], [Word])
f
  where
    f :: [Word] -> [Word] -> ([Word], [Word])
    f :: [Word] -> [Word] -> ([Word], [Word])
f  []      [Word]
asbs   = ([], [Word]
asbs)
    f (Word
_:[Word]
is) ~(Word
a:[Word]
sbs) = ([Word] -> [Word]) -> ([Word], [Word]) -> ([Word], [Word])
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Word
aWord -> [Word] -> [Word]
forall a. a -> [a] -> [a]
:) ([Word] -> [Word] -> ([Word], [Word])
f [Word]
is [Word]
sbs)

concatDims