Safe Haskell | None |
---|---|
Language | Haskell2010 |
The core easytensor
types.
Synopsis
- data SomeDataFrame (t :: l) = forall (ns :: [Nat]).(Dimensions ns, KnownBackends t ns) => SomeDataFrame (DataFrame t ns)
- data DataFrame' (xs :: [k]) (t :: l)
- data family DataFrame (t :: l) (xs :: [k])
- pattern Z :: forall (xs :: [Type]) (ns :: [Nat]). () => xs ~ '[] => DataFrame xs ns
- pattern (:*:) :: forall (xs :: [Type]) (ns :: [Nat]). () => forall (y :: Type) (ys :: [Type]). xs ~ (y ': ys) => DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns
- pattern S :: forall (t :: Type). t -> DataFrame t ('[] :: [Nat])
- pattern DF2 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (2 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t (2 ': ds)
- pattern DF3 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (3 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (3 ': ds)
- pattern DF4 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (4 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (4 ': ds)
- pattern DF5 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (5 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (5 ': ds)
- pattern DF6 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (6 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (6 ': ds)
- pattern DF7 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (7 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (7 ': ds)
- pattern DF8 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (8 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (8 ': ds)
- pattern DF9 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (9 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (9 ': ds)
- scalar :: t -> DataFrame t ('[] :: [Nat])
- unScalar :: DataFrame t ('[] :: [Nat]) -> t
- class IndexFrame t d ds where
- type family SubFrameIndexCtx (d :: k) (idxN :: k) (subN :: k) :: Constraint where ...
- type family PackDF (t :: Type) (ds :: [Nat]) (d :: Nat) (r :: Type) :: Type where ...
- packDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d ': ds)) => PackDF t ds d (DataFrame t (d ': ds))
- unpackDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]) (rep :: RuntimeRep) (r :: TYPE rep). (PrimBytes t, Dimensions (d ': ds)) => PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r) -> DataFrame t (d ': ds) -> r
- appendDF :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n, KnownDim m) => DataFrame t (n :+ ds) -> DataFrame t (m :+ ds) -> DataFrame t ((n + m) :+ ds)
- consDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t ds -> DataFrame t (n :+ ds) -> DataFrame t ((n + 1) :+ ds)
- snocDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t (n :+ ds) -> DataFrame t ds -> DataFrame t ((n + 1) :+ ds)
- fromFlatList :: forall (t :: Type) (ds :: [Nat]). PrimArray t (DataFrame t ds) => Dims ds -> t -> [t] -> DataFrame t ds
- fromListWithDefault :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d ': ds)) => DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d ': ds)
- fromList :: forall (t :: Type) (ds :: [Nat]) (xds :: [XNat]). (PrimBytes t, Dimensions ds, xds ~ Map N ds, ds ~ UnMap N xds) => [DataFrame t ds] -> DataFrame t (XN 0 ': xds)
- constrainDF :: forall (ds :: [XNat]) (ys :: [XNat]) t. (BoundedDims ds, All KnownDimType ds) => DataFrame t ys -> Maybe (DataFrame t ds)
- asDiag :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (Dimensions ds, KnownDim n, KnownDim m, KnownBackend t (Min n m :+ ds), KnownBackend t (n :+ (m :+ ds)), PrimBytes t) => DataFrame t (Min n m :+ ds) -> DataFrame t (n :+ (m :+ ds))
- class KnownBackend t ds (BackendFamily t ds) => KnownBackend t (ds :: [Nat])
- type DFBackend (t :: Type) (ds :: [Nat]) = Backend I t ds (BackendFamily t ds)
- type family KnownBackends (ts :: l) (ns :: [Nat]) :: Constraint where ...
- class InferKnownBackend t (ds :: [Nat]) where
- inferKnownBackend :: Dict (KnownBackends t ds)
- inferPrimElem :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). KnownBackend t (d ': ds) => DataFrame t (d ': ds) -> Dict (PrimBytes t)
- data Dim (x :: k) where
- pattern D :: KnownDimType d => (KindOf d ~ Nat, KnownDim d) => Dim d
- pattern D1 :: () => n ~ 1 => Dim n
- pattern D25 :: () => n ~ 25 => Dim n
- pattern D24 :: () => n ~ 24 => Dim n
- pattern D23 :: () => n ~ 23 => Dim n
- pattern D22 :: () => n ~ 22 => Dim n
- pattern D21 :: () => n ~ 21 => Dim n
- pattern D20 :: () => n ~ 20 => Dim n
- pattern D19 :: () => n ~ 19 => Dim n
- pattern D18 :: () => n ~ 18 => Dim n
- pattern D17 :: () => n ~ 17 => Dim n
- pattern D16 :: () => n ~ 16 => Dim n
- pattern D15 :: () => n ~ 15 => Dim n
- pattern D14 :: () => n ~ 14 => Dim n
- pattern D13 :: () => n ~ 13 => Dim n
- pattern D12 :: () => n ~ 12 => Dim n
- pattern D11 :: () => n ~ 11 => Dim n
- pattern D10 :: () => n ~ 10 => Dim n
- pattern D9 :: () => n ~ 9 => Dim n
- pattern D8 :: () => n ~ 8 => Dim n
- pattern D7 :: () => n ~ 7 => Dim n
- pattern D6 :: () => n ~ 6 => Dim n
- pattern D5 :: () => n ~ 5 => Dim n
- pattern D4 :: () => n ~ 4 => Dim n
- pattern D3 :: () => n ~ 3 => Dim n
- pattern D2 :: () => n ~ 2 => Dim n
- pattern D0 :: () => n ~ 0 => Dim n
- pattern Dx :: forall k d (m :: Nat) n. KnownDimType d => forall. (d ~~ XN m, m <= n) => Dim n -> Dim d
- pattern Dn :: KnownDimType d => d ~~ N n => Dim n -> Dim d
- data Idx (d :: k)
- data Nat
- data XNat
- type N = 'N
- type XN = 'XN
- type Dims = TypedList (Dim :: k -> Type)
- type Idxs = TypedList (Idx :: k -> Type)
- data TypedList (f :: k -> Type) (xs :: [k]) where
- pattern Empty :: () => xs ~ ('[] :: [k]) => TypedList f xs
- pattern Reverse :: forall k f xs sx. () => ReverseList xs sx => TypedList f sx -> TypedList f xs
- pattern Snoc :: forall k f xs sy (y :: k). () => SnocList sy y xs => TypedList f sy -> f y -> TypedList f xs
- pattern Cons :: forall k f xs (y :: k) ys. () => xs ~ (y ': ys) => f y -> TypedList f ys -> TypedList f xs
- pattern TypeList :: () => RepresentableList xs => TypeList xs
- pattern (:*) :: forall k f xs (y :: k) ys. () => xs ~ (y ': ys) => f y -> TypedList f ys -> TypedList f xs
- pattern U :: () => xs ~ ('[] :: [k]) => TypedList f xs
- pattern Dims :: forall k ds (ns :: [Nat]). KnownDimKind (KindOfEl ds) => forall. (ds ~~ ns, Dimensions ns) => Dims ds
- pattern KnownDims :: () => (All (KnownDim :: Nat -> Constraint) ds, All (BoundedDim :: Nat -> Constraint) ds, RepresentableList ds, Dimensions ds) => Dims ds
- pattern XDims :: KnownDimKind (KindOfEl ds) => FixedDims ds ns => Dims ns -> Dims ds
- pattern XIdxs :: (FixedDims ds ns, Dimensions ns) => Idxs ns -> Idxs ds
- class PrimTagged a => PrimBytes a
- bSizeOf :: (PrimBytes a, Num b) => a -> b
- bAlignOf :: (PrimBytes a, Num b) => a -> b
- bFieldOffsetOf :: forall (name :: Symbol) (a :: Type) (b :: Type). (PrimBytes a, Elem name (PrimFields a), KnownSymbol name, Num b) => a -> b
- class PrimBytes t => PrimArray t a | a -> t
- ixOff :: PrimArray t a => Int -> a -> t
Data types
data SomeDataFrame (t :: l) Source #
Data frame that has an unknown dimensionality at compile time. Pattern-match against its constructor to get a Nat-indexed data frame
forall (ns :: [Nat]).(Dimensions ns, KnownBackends t ns) => SomeDataFrame (DataFrame t ns) |
Instances
data DataFrame' (xs :: [k]) (t :: l) Source #
DataFrame with its type arguments swapped.
Instances
(Data (DataFrame t xs), Typeable t, Typeable xs, Typeable k, Typeable l) => Data (DataFrame' xs t) Source # | |
Defined in Numeric.DataFrame.Type gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DataFrame' xs t -> c (DataFrame' xs t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (DataFrame' xs t) # toConstr :: DataFrame' xs t -> Constr # dataTypeOf :: DataFrame' xs t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (DataFrame' xs t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (DataFrame' xs t)) # gmapT :: (forall b. Data b => b -> b) -> DataFrame' xs t -> DataFrame' xs t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DataFrame' xs t -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DataFrame' xs t -> r # gmapQ :: (forall d. Data d => d -> u) -> DataFrame' xs t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> DataFrame' xs t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> DataFrame' xs t -> m (DataFrame' xs t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DataFrame' xs t -> m (DataFrame' xs t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DataFrame' xs t -> m (DataFrame' xs t) # |
data family DataFrame (t :: l) (xs :: [k]) Source #
Keep data in a primitive data frame and maintain information about Dimensions in the type system
Instances
pattern Z :: forall (xs :: [Type]) (ns :: [Nat]). () => xs ~ '[] => DataFrame xs ns Source #
Empty MultiFrame
pattern (:*:) :: forall (xs :: [Type]) (ns :: [Nat]). () => forall (y :: Type) (ys :: [Type]). xs ~ (y ': ys) => DataFrame y ns -> DataFrame ys ns -> DataFrame xs ns infixr 6 Source #
Constructing a MultiFrame
using DataFrame columns
pattern S :: forall (t :: Type). t -> DataFrame t ('[] :: [Nat]) Source #
A scalar DataFrame is just a newtype wrapper on a value.
pattern DF2 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (2 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t (2 ': ds) Source #
pattern DF3 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (3 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (3 ': ds) Source #
pattern DF4 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (4 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (4 ': ds) Source #
pattern DF5 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (5 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (5 ': ds) Source #
pattern DF6 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (6 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (6 ': ds) Source #
pattern DF7 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (7 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (7 ': ds) Source #
pattern DF8 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (8 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (8 ': ds) Source #
pattern DF9 :: forall (t :: Type) (ds :: [Nat]). (PrimBytes t, Dimensions (9 ': ds)) => (Dimensions ds, KnownBackend t ds) => DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t ds -> DataFrame t (9 ': ds) Source #
class IndexFrame t d ds where Source #
Index one dimension deep into a DataFrame
.
(!) :: DataFrame t (d ': ds) -> Word -> DataFrame t ds Source #
Index one dimension deep into a DataFrame
.
Note, this function does not provide indexing safety at the type level;
it throws an OutOfDimBounds
exception if an index is out of bounds
(unless unsafeindices
package flag is enabled, which is even more dangerous).
Instances
(PrimArray t (DataFrame t (d ': ds)), KnownDim d, KnownBackend t ds) => IndexFrame (t :: Type) (d :: Nat) (ds :: [Nat]) Source # | |
PrimBytes t => IndexFrame (t :: Type) (xd :: XNat) (xds :: [XNat]) Source # | |
(PrimArray t (DataFrame t '[d]), KnownDim d) => IndexFrame (t :: Type) (d :: Nat) ('[] :: [Nat]) Source # | |
(RepresentableList ts, All PrimBytes ts) => IndexFrame (ts :: [Type]) (xd :: XNat) (xds :: [XNat]) Source # | |
IndexFrame ('[] :: [Type]) (d :: Nat) (ds :: [Nat]) Source # | |
(IndexFrame t d ds, IndexFrame ts d ds) => IndexFrame (t ': ts :: [Type]) (d :: Nat) (ds :: [Nat]) Source # | |
type family SubFrameIndexCtx (d :: k) (idxN :: k) (subN :: k) :: Constraint where ... Source #
This type family describes two strategies for dealing with dimensions when
slicing a DataFrame
.
If the original space dimension (d
) is fixed at compile time
(d :: Nat
or d ~ N n
), then we enforce the safety of a slicing operation
with types:
the index space is bounded by the size of the original space
minus the subframe size.
If the original space dimension (d
) is not fixed (d ~ XN m
), then we give up.
Just let the user do the slicing as easy as possible, and throw an OutOfDimBounds
exception at runtime if the index plus the sliced size is greater than the
original size of the DataFrame.
Flexible assembling and disassembling
packDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d ': ds)) => PackDF t ds d (DataFrame t (d ': ds)) Source #
Takes d
arguments of type DataFrame t ds
and produce a DataFrame t (d ': ds)
.
NB: always use TypeApplications
extension with this function to apply all
type arguments!
Otherwise, a very dumb type family PackDF
will not infer the types for you.
The following example creates a Matrix Double 12 3
filled with twelve
3D vectors (using fromInteger
of Vector Double 3
):
>>>
packDF @Double @12 @'[3] 1 2 3 4 5 6 7 8 9 10 11 12
packDF
and unpackDF
together serve as a generic constructor for a DataFrame
of an arbitrary (statically known) size.
unpackDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]) (rep :: RuntimeRep) (r :: TYPE rep). (PrimBytes t, Dimensions (d ': ds)) => PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r) -> DataFrame t (d ': ds) -> r Source #
Takes a function (e.g. a constructor) with d+1
argument (df1, df2, .. dfd, Dict)
and a DataFrame t (d ': ds)
.
Feeds the dataframe elements into that function.
For example, you can pass a tuple to this function, and get all dataframe elements
(and some dictionaries -- useful evidence to work with element frames)
NB: always use TypeApplications
extension with this function to apply all
type arguments!
Otherwise, a very dumb type family PackDF
will not infer the types for you.
The following example unpacks a 3D vector
(created using fromInteger
of Vector Double 3
)
into a 4-tuple with three scalars and one Dict:
>>>
unpackDF @Double @3 @'[] (,,,) 2
packDF
and unpackDF
together serve as a generic constructor for a DataFrame
of an arbitrary (statically known) size.
appendDF :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n, KnownDim m) => DataFrame t (n :+ ds) -> DataFrame t (m :+ ds) -> DataFrame t ((n + m) :+ ds) Source #
consDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t ds -> DataFrame t (n :+ ds) -> DataFrame t ((n + 1) :+ ds) Source #
snocDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t (n :+ ds) -> DataFrame t ds -> DataFrame t ((n + 1) :+ ds) Source #
fromFlatList :: forall (t :: Type) (ds :: [Nat]). PrimArray t (DataFrame t ds) => Dims ds -> t -> [t] -> DataFrame t ds Source #
Construct a DataFrame from a flat list.
The values are filled according to the DataFrame layout: row-by-row and further from the last dimension (least significant) to the first dimension (most significant).
If the argument list is shorter than totalDim
, then the rest of the frame
is padded with a default value (second argument).
If the argument list is longer than totalDim
, then unused values are dropped.
If you want, you can pass an infinite list as an argument, i.e. the following
is a valid use:
>>>
fromFlatList (dims :: Dims '[2,5]) 0 [6,8..]
fromListWithDefault :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d ': ds)) => DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d ': ds) Source #
Construct a DataFrame from a list of smaller DataFrames.
If the argument list is shorter than d
, then the rest of the frame
is padded with a default value (first argument).
If the argument list is longer than d
, then unused values are dropped.
If you want, you can pass an infinite list as an argument.
fromList :: forall (t :: Type) (ds :: [Nat]) (xds :: [XNat]). (PrimBytes t, Dimensions ds, xds ~ Map N ds, ds ~ UnMap N xds) => [DataFrame t ds] -> DataFrame t (XN 0 ': xds) Source #
Construct a dynamic DataFrame from a list of smaller DataFrames.
Pattern-match against the resulting XFrame
to find out its dimensionality.
You must not provide an infinite list as an argument.
constrainDF :: forall (ds :: [XNat]) (ys :: [XNat]) t. (BoundedDims ds, All KnownDimType ds) => DataFrame t ys -> Maybe (DataFrame t ds) Source #
Try to convert between XNat
-indexed DataFrames.
This is useful for imposing restrictions on unknown DataFrames, e.g. increasing the minimum number of elements.
asDiag :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (Dimensions ds, KnownDim n, KnownDim m, KnownBackend t (Min n m :+ ds), KnownBackend t (n :+ (m :+ ds)), PrimBytes t) => DataFrame t (Min n m :+ ds) -> DataFrame t (n :+ (m :+ ds)) Source #
Place elements of a vector on the main diagonal of a matrix; fill the rest of the matrix with zeroes.
Note, this function is naturally generalized onto higher dimensions (which can be seen from the type signature).
Note, the argument of this function does not fully determine its result type.
This may cause some obscure type errors.
Specify type parameters n
and m
explicitly or make sure the result type is fixed.
Infer type class instances
class KnownBackend t ds (BackendFamily t ds) => KnownBackend t (ds :: [Nat]) Source #
Instances
KnownBackend t ds (BackendFamily t ds) => KnownBackend t ds Source # | |
Defined in Numeric.DataFrame.Internal.Backend |
type DFBackend (t :: Type) (ds :: [Nat]) = Backend I t ds (BackendFamily t ds) Source #
Implementation behind the DataFrame
type family KnownBackends (ts :: l) (ns :: [Nat]) :: Constraint where ... Source #
I use this kind-polymorphic constraint to generalize XFrame
and SomeDataFrame
over SingleFrame
and MultiFrame
.
KnownBackends (t :: Type) ns = KnownBackend t ns | |
KnownBackends ('[] :: [Type]) _ = () | |
KnownBackends (t ': ts :: [Type]) ns = (KnownBackend t ns, KnownBackends ts ns) |
class InferKnownBackend t (ds :: [Nat]) where Source #
Allow inferring KnownBackends
if you know the dimensions and the element types.
inferKnownBackend :: Dict (KnownBackends t ds) Source #
Infer KnownBackends
if you know the dimensions and the element types.
Instances
(PrimBytes t, Dimensions ds) => InferKnownBackend (t :: Type) ds Source # | |
Defined in Numeric.DataFrame.Type inferKnownBackend :: Dict (KnownBackends t ds) Source # | |
(RepresentableList ts, All PrimBytes ts, Dimensions ds) => InferKnownBackend (ts :: [Type]) ds Source # | |
Defined in Numeric.DataFrame.Type inferKnownBackend :: Dict (KnownBackends ts ds) Source # |
inferPrimElem :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). KnownBackend t (d ': ds) => DataFrame t (d ': ds) -> Dict (PrimBytes t) Source #
Evidence that the elements of the DataFrame are PrimBytes.
Re-exports
Singleton type to store type-level dimension value.
On the one hand, it can be used to let type-inference system know
relations between type-level naturals.
On the other hand, this is just a newtype wrapper on the Word
type.
Usually, the type parameter of Dim
is either Nat
or XNat
.
If dimensionality of your data is known in advance, use Nat
;
if you know the size of some dimensions, but do not know the size
of others, use XNat
s to represent them.
pattern D :: KnownDimType d => (KindOf d ~ Nat, KnownDim d) => Dim d | Match against this pattern to bring |
pattern D1 :: () => n ~ 1 => Dim n | Match |
pattern D25 :: () => n ~ 25 => Dim n | Match |
pattern D24 :: () => n ~ 24 => Dim n | Match |
pattern D23 :: () => n ~ 23 => Dim n | Match |
pattern D22 :: () => n ~ 22 => Dim n | Match |
pattern D21 :: () => n ~ 21 => Dim n | Match |
pattern D20 :: () => n ~ 20 => Dim n | Match |
pattern D19 :: () => n ~ 19 => Dim n | Match |
pattern D18 :: () => n ~ 18 => Dim n | Match |
pattern D17 :: () => n ~ 17 => Dim n | Match |
pattern D16 :: () => n ~ 16 => Dim n | Match |
pattern D15 :: () => n ~ 15 => Dim n | Match |
pattern D14 :: () => n ~ 14 => Dim n | Match |
pattern D13 :: () => n ~ 13 => Dim n | Match |
pattern D12 :: () => n ~ 12 => Dim n | Match |
pattern D11 :: () => n ~ 11 => Dim n | Match |
pattern D10 :: () => n ~ 10 => Dim n | Match |
pattern D9 :: () => n ~ 9 => Dim n | Match |
pattern D8 :: () => n ~ 8 => Dim n | Match |
pattern D7 :: () => n ~ 7 => Dim n | Match |
pattern D6 :: () => n ~ 6 => Dim n | Match |
pattern D5 :: () => n ~ 5 => Dim n | Match |
pattern D4 :: () => n ~ 4 => Dim n | Match |
pattern D3 :: () => n ~ 3 => Dim n | Match |
pattern D2 :: () => n ~ 2 => Dim n | Match |
pattern D0 :: () => n ~ 0 => Dim n | Match |
pattern Dx :: forall k d (m :: Nat) n. KnownDimType d => forall. (d ~~ XN m, m <= n) => Dim n -> Dim d |
|
pattern Dn :: KnownDimType d => d ~~ N n => Dim n -> Dim d | Statically known |
Instances
Eq (Dims ds) | |
Eq (Dims ds) | |
Eq (Dim n) | |
Eq (Dim x) | |
Typeable d => Data (Dim d) | |
Defined in Numeric.Dimensions.Dim gfoldl :: (forall d0 b. Data d0 => c (d0 -> b) -> d0 -> c b) -> (forall g. g -> c g) -> Dim d -> c (Dim d) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Dim d) # dataTypeOf :: Dim d -> DataType # dataCast1 :: Typeable t => (forall d0. Data d0 => c (t d0)) -> Maybe (c (Dim d)) # dataCast2 :: Typeable t => (forall d0 e. (Data d0, Data e) => c (t d0 e)) -> Maybe (c (Dim d)) # gmapT :: (forall b. Data b => b -> b) -> Dim d -> Dim d # gmapQl :: (r -> r' -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Dim d -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Dim d -> r # gmapQ :: (forall d0. Data d0 => d0 -> u) -> Dim d -> [u] # gmapQi :: Int -> (forall d0. Data d0 => d0 -> u) -> Dim d -> u # gmapM :: Monad m => (forall d0. Data d0 => d0 -> m d0) -> Dim d -> m (Dim d) # gmapMp :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Dim d -> m (Dim d) # gmapMo :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Dim d -> m (Dim d) # | |
Ord (Dims ds) | |
Ord (Dims ds) | |
Ord (Dim n) | |
Ord (Dim x) | |
BoundedDims xs => Read (Dims xs) | |
BoundedDim x => Read (Dim x) | |
Show (Dims xs) | |
Show (Dim x) | |
KnownDim d => Generic (Dim d) | |
type Rep (Dim d) | |
This type is used to index a single dimension.
(k ~ Nat) =>
the range of indices is from0
tod-1
.(d ~ N n) =>
the range of indices is from0
ton-1
.(d ~ XN m) =>
the range of indices is from0
tomaxBound :: Word
.
That is, using Idx (n :: Nat)
or Idx (N n)
is guaranteed to be safe by the
type system.
But an index of type Idx (XN m)
can have any value, and using it may yield
an OutOfDimBounds
exception -- just the same as a generic index
function that
takes a plain Int
or Word
as an argument.
Thus, if you have data indexed by (XN m)
, I would suggest to use lookup
-like
functions that return Maybe
. You're warned.
Instances
BoundedDim d => Bounded (Idx d) | |
BoundedDims ds => Bounded (Idxs ds) | |
KnownDim n => Enum (Idx n) | |
Defined in Numeric.Dimensions.Idx | |
BoundedDim d => Enum (Idx d) | |
Defined in Numeric.Dimensions.Idx | |
Enum (Idx (XN m)) | |
Defined in Numeric.Dimensions.Idx succ :: Idx (XN m) -> Idx (XN m) # pred :: Idx (XN m) -> Idx (XN m) # fromEnum :: Idx (XN m) -> Int # enumFrom :: Idx (XN m) -> [Idx (XN m)] # enumFromThen :: Idx (XN m) -> Idx (XN m) -> [Idx (XN m)] # enumFromTo :: Idx (XN m) -> Idx (XN m) -> [Idx (XN m)] # enumFromThenTo :: Idx (XN m) -> Idx (XN m) -> Idx (XN m) -> [Idx (XN m)] # | |
KnownDim n => Enum (Idx (N n)) | |
Defined in Numeric.Dimensions.Idx succ :: Idx (N n) -> Idx (N n) # pred :: Idx (N n) -> Idx (N n) # fromEnum :: Idx (N n) -> Int # enumFrom :: Idx (N n) -> [Idx (N n)] # enumFromThen :: Idx (N n) -> Idx (N n) -> [Idx (N n)] # enumFromTo :: Idx (N n) -> Idx (N n) -> [Idx (N n)] # enumFromThenTo :: Idx (N n) -> Idx (N n) -> Idx (N n) -> [Idx (N n)] # | |
Dimensions ds => Enum (Idxs ds) |
|
Eq (Idx d) | |
Eq (Idxs xs) | |
BoundedDim d => Integral (Idx d) | |
(Typeable d, Typeable k) => Data (Idx d) | |
Defined in Numeric.Dimensions.Idx gfoldl :: (forall d0 b. Data d0 => c (d0 -> b) -> d0 -> c b) -> (forall g. g -> c g) -> Idx d -> c (Idx d) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Idx d) # dataTypeOf :: Idx d -> DataType # dataCast1 :: Typeable t => (forall d0. Data d0 => c (t d0)) -> Maybe (c (Idx d)) # dataCast2 :: Typeable t => (forall d0 e. (Data d0, Data e) => c (t d0 e)) -> Maybe (c (Idx d)) # gmapT :: (forall b. Data b => b -> b) -> Idx d -> Idx d # gmapQl :: (r -> r' -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Idx d -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Idx d -> r # gmapQ :: (forall d0. Data d0 => d0 -> u) -> Idx d -> [u] # gmapQi :: Int -> (forall d0. Data d0 => d0 -> u) -> Idx d -> u # gmapM :: Monad m => (forall d0. Data d0 => d0 -> m d0) -> Idx d -> m (Idx d) # gmapMp :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Idx d -> m (Idx d) # gmapMo :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Idx d -> m (Idx d) # | |
KnownDim n => Num (Idx n) | |
BoundedDim d => Num (Idx d) | |
Num (Idx (XN m)) | |
Defined in Numeric.Dimensions.Idx | |
KnownDim n => Num (Idx (N n)) | |
Defined in Numeric.Dimensions.Idx | |
Ord (Idx d) | |
Ord (Idxs xs) | Compare indices by their importance in lexicorgaphic order from the first dimension to the last dimension (the first dimension is the most significant one). Literally, compare a b = compare (listIdxs a) (listIdxs b) This is the same sort == sortOn fromEnum |
BoundedDim d => Read (Idx d) | |
BoundedDims xs => Read (Idxs xs) | |
BoundedDim d => Real (Idx d) | |
Defined in Numeric.Dimensions.Idx toRational :: Idx d -> Rational # | |
Show (Idx d) | |
Show (Idxs xs) | |
Generic (Idx d) | |
Storable (Idx d) | |
PrimBytes (Idx x) Source # | |
Defined in Numeric.PrimBytes type PrimFields (Idx x) :: [Symbol] Source # getBytes :: Idx x -> ByteArray# Source # getBytesPinned :: Idx x -> ByteArray# Source # fromBytes :: Int# -> ByteArray# -> Idx x Source # readBytes :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Idx x #) Source # writeBytes :: MutableByteArray# s -> Int# -> Idx x -> State# s -> State# s Source # readAddr :: Addr# -> State# s -> (# State# s, Idx x #) Source # writeAddr :: Idx x -> Addr# -> State# s -> State# s Source # byteSize :: Idx x -> Int# Source # byteAlign :: Idx x -> Int# Source # byteOffset :: Idx x -> Int# Source # byteFieldOffset :: forall (name :: Symbol). (Elem name (PrimFields (Idx x)), KnownSymbol name) => Proxy# name -> Idx x -> Int# Source # indexArray :: ByteArray# -> Int# -> Idx x Source # readArray :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Idx x #) Source # writeArray :: MutableByteArray# s -> Int# -> Idx x -> State# s -> State# s Source # | |
RepresentableList xs => PrimBytes (Idxs xs) Source # | |
Defined in Numeric.PrimBytes type PrimFields (Idxs xs) :: [Symbol] Source # getBytes :: Idxs xs -> ByteArray# Source # getBytesPinned :: Idxs xs -> ByteArray# Source # fromBytes :: Int# -> ByteArray# -> Idxs xs Source # readBytes :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Idxs xs #) Source # writeBytes :: MutableByteArray# s -> Int# -> Idxs xs -> State# s -> State# s Source # readAddr :: Addr# -> State# s -> (# State# s, Idxs xs #) Source # writeAddr :: Idxs xs -> Addr# -> State# s -> State# s Source # byteSize :: Idxs xs -> Int# Source # byteAlign :: Idxs xs -> Int# Source # byteOffset :: Idxs xs -> Int# Source # byteFieldOffset :: forall (name :: Symbol). (Elem name (PrimFields (Idxs xs)), KnownSymbol name) => Proxy# name -> Idxs xs -> Int# Source # indexArray :: ByteArray# -> Int# -> Idxs xs Source # readArray :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Idxs xs #) Source # writeArray :: MutableByteArray# s -> Int# -> Idxs xs -> State# s -> State# s Source # | |
type Rep (Idx d) | |
Defined in Numeric.Dimensions.Idx | |
type PrimFields (Idx x) Source # | |
Defined in Numeric.PrimBytes | |
type PrimFields (Idxs xs) Source # | |
Defined in Numeric.PrimBytes |
(Kind) This is the kind of type-level natural numbers.
Instances
Either known or unknown at compile-time natural number
Instances
type Idxs = TypedList (Idx :: k -> Type) #
Type-level dimensional indexing with arbitrary Word values inside.
Most of the operations on it require Dimensions
or BoundedDims
constraint,
because the Idxs
itself does not store info about dimension bounds.
data TypedList (f :: k -> Type) (xs :: [k]) where #
Type-indexed list
pattern Empty :: () => xs ~ ('[] :: [k]) => TypedList f xs | Zero-length type list; synonym to |
pattern Reverse :: forall k f xs sx. () => ReverseList xs sx => TypedList f sx -> TypedList f xs | Reverse a typed list |
pattern Snoc :: forall k f xs sy (y :: k). () => SnocList sy y xs => TypedList f sy -> f y -> TypedList f xs | Constructing a type-indexed list from the other end |
pattern Cons :: forall k f xs (y :: k) ys. () => xs ~ (y ': ys) => f y -> TypedList f ys -> TypedList f xs | Constructing a type-indexed list in the canonical way |
pattern TypeList :: () => RepresentableList xs => TypeList xs | Pattern matching against this causes |
pattern (:*) :: forall k f xs (y :: k) ys. () => xs ~ (y ': ys) => f y -> TypedList f ys -> TypedList f xs infixr 5 | Constructing a type-indexed list |
pattern U :: () => xs ~ ('[] :: [k]) => TypedList f xs | Zero-length type list |
pattern Dims :: forall k ds (ns :: [Nat]). KnownDimKind (KindOfEl ds) => forall. (ds ~~ ns, Dimensions ns) => Dims ds |
|
pattern KnownDims :: () => (All (KnownDim :: Nat -> Constraint) ds, All (BoundedDim :: Nat -> Constraint) ds, RepresentableList ds, Dimensions ds) => Dims ds |
|
pattern XDims :: KnownDimKind (KindOfEl ds) => FixedDims ds ns => Dims ns -> Dims ds |
|
pattern XIdxs :: (FixedDims ds ns, Dimensions ns) => Idxs ns -> Idxs ds | Transform between Note, this pattern is not a |
Instances
class PrimTagged a => PrimBytes a Source #
Defines how to read and write your data to and from Haskell unboxed byte arrays and plain pointers.
Similarly to Storable
, this class provides functions to get
the size and alignment of a data via phantom arguments.
Thus, the size and alignment of the data must not depend on the data content
(they depend only on the type of the data).
In particular, this means that dynamically sized structures like Haskell lists
or maps are not allowed.
This module provides default implementations for all methods of this class via
Generic
. Hence, to make your data an instance of PrimBytes
,
it is sufficient to write the instance head:
data MyData a b = ... deriving Generic instance (PrimBytes a, PrimBytes b) => PrimBytes (MyData a b)
.. or use the DeriveAnyClass
extension to make it even shorter:
data MyData a b = ... deriving (Generic, PrimBytes)
The derived instance tries to pack the data as dense as possible, but sometimes
it is better to write the instance by hand.
If a derived type has more than one constructor, the derived instance puts
a Word32
tag at the beginning of the byte representation.
All fields of a constructor are packed in a C-like fashion next to each other,
while respecting their alignments.
Instances
bFieldOffsetOf :: forall (name :: Symbol) (a :: Type) (b :: Type). (PrimBytes a, Elem name (PrimFields a), KnownSymbol name, Num b) => a -> b Source #
A wrapper on byteFieldOffset
.
class PrimBytes t => PrimArray t a | a -> t Source #