-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Pure, type-indexed haskell vector, matrix, and tensor library. -- -- Pure, type-indexed haskell vector, matrix, and tensor library. -- Features dimensionality type-checking for all operations. Generic -- n-dimensional versions are implemented using low-level prim ops. -- Allows ad-hoc replacement with fixed low-dimensionality vectors and -- matrices without changing user interface. Please see the README on -- GitHub at https://github.com/achirkin/easytensor#readme @package easytensor @version 2.1.0.0 -- | Facilities for converting Haskell data to and from raw bytes. -- -- The main purpose of this module is to support the implementation of -- the DataFrame Backend. However, it also comes very -- useful for writing FFI. To that end, the PrimBytes class is -- similar to the Storable class: it provides means to write your -- data to and read from a raw memory area. Though, it is more flexible -- in that it can work with both, foreign pointers and primitive byte -- arrays, and it provides means to get data field offsets by their -- selector names. On top of that, a PrimBytes instance can be -- derived via the Generic machinery. -- -- A derived PrimBytes instance tries to pack the data as dense as -- possible, while respecting the alignment requirements. In all cases -- known to me, the resulting data layout coincides with a corresponding -- C struct, allowing to marshal the data without any boilerplate. -- However, this is not guaranteed, but you can write a PrimBytes -- instance manually if necessary (and report an issue plz). -- -- Note about alignment, size, and padding of the data. There are -- two basic sanity assumptions about these, which are not checked in -- this module at all: -- --
-- 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. class PrimTagged a => PrimBytes a where { -- | List of field names. -- -- It is used to get field offsets using byteFieldOffset function. -- -- A Generic-derived instance has this list non-empty only if two obvious -- conditions are met: -- --
-- import qualified Numeric.ProductOrd.NonTransitive as NonTransitive --module Numeric.ProductOrd.NonTransitive -- | Redefine Ord instance for a type which is a cartesian product -- -- as a partial product order. -- -- Since vanilla Haskell Ord class is always about total order, -- ProductOrd instance is not particularly correct. However, it -- turns out to be very useful for comparing vector or tuple-like types. -- -- The implementation of ProductOrd in this module workarounds -- this by using a non-transitive Eq instance: <math> -- -- Another inconsistency with the Haskell Report is the min and -- max functions; these are simply element-wise minimum and -- maximum here. Thus, these instances preserve important properties like -- min a b <= a && min a b <= b, but do not -- preserve a property that min a b == a || min a b == b. -- -- All of this is really useful in geometry applications and for -- calculating things like Pareto dominance, but should be used -- with care. Remember about this if you want to put a -- ProductOrd into a Set or a Map! newtype ProductOrd a ProductOrd :: a -> ProductOrd a [getProductOrd] :: ProductOrd a -> a -- | Treat Incomparable as EQ (non-transitive equality). toOrdering :: PartialOrdering -> Ordering instance Data.Traversable.Traversable Numeric.ProductOrd.NonTransitive.ProductOrd instance Foreign.Storable.Storable a => Foreign.Storable.Storable (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Base.Monoid a => GHC.Base.Monoid (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Real.Fractional a => GHC.Real.Fractional (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Float.Floating a => GHC.Float.Floating (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Enum.Enum a => GHC.Enum.Enum (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Num.Num a => GHC.Num.Num (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Generics.Generic1 Numeric.ProductOrd.NonTransitive.ProductOrd instance GHC.Generics.Generic (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance Data.Data.Data a => Data.Data.Data (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Read.Read a => GHC.Read.Read (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance GHC.Show.Show a => GHC.Show.Show (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), GHC.Real.Integral a) => GHC.Real.Integral (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), Data.Bits.Bits a) => Data.Bits.Bits (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), Data.Bits.FiniteBits a) => Data.Bits.FiniteBits (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), GHC.Real.Real a) => GHC.Real.Real (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), GHC.Real.RealFrac a) => GHC.Real.RealFrac (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a), GHC.Float.RealFloat a) => GHC.Float.RealFloat (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance Data.Foldable.Foldable Numeric.ProductOrd.NonTransitive.ProductOrd instance GHC.Base.Functor Numeric.ProductOrd.NonTransitive.ProductOrd instance GHC.Base.Applicative Numeric.ProductOrd.NonTransitive.ProductOrd instance GHC.Base.Monad Numeric.ProductOrd.NonTransitive.ProductOrd instance Control.Monad.Fix.MonadFix Numeric.ProductOrd.NonTransitive.ProductOrd instance Control.Monad.Zip.MonadZip Numeric.ProductOrd.NonTransitive.ProductOrd instance GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd a) => GHC.Classes.Eq (Numeric.ProductOrd.NonTransitive.ProductOrd a) instance forall k (f :: k -> *) (xs :: [k]). Data.Type.List.All GHC.Classes.Ord (Data.Type.List.Map f xs) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (Numeric.TypedList.TypedList f xs)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4, a5)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4, a5, a6)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4, a5, a6, a7)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7, GHC.Classes.Ord a8) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4, a5, a6, a7, a8)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7, GHC.Classes.Ord a8, GHC.Classes.Ord a9) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (a1, a2, a3, a4, a5, a6, a7, a8, a9)) -- | Compare product types using partial Ord instances: -- --
-- import qualified Numeric.ProductOrd.Partial as Partial --module Numeric.ProductOrd.Partial -- | Redefine Ord instance for a type which is a cartesian product -- -- as a partial product order. -- -- Since vanilla Haskell Ord class is always about total order, -- ProductOrd instance is not particularly correct. However, it -- turns out to be very useful for comparing vector or tuple-like types. -- -- The implementation of ProductOrd in this module workarounds -- this by using a partial compare function in an Eq -- instance: <math> -- -- Another inconsistency with the Haskell Report is the min and -- max functions; these are simply element-wise minimum and -- maximum here. Thus, these instances preserve important properties like -- min a b <= a && min a b <= b, but do not -- preserve a property that min a b == a || min a b == b. -- -- All of this is really useful in geometry applications and for -- calculating things like Pareto dominance, but should be used -- with care. In particular, never use ProductOrd as a key to a -- Set or a Map! newtype ProductOrd a ProductOrd :: a -> ProductOrd a [getProductOrd] :: ProductOrd a -> a -- | Treat Incomparable as error (partial function). toOrdering :: PartialOrdering -> Ordering instance Data.Bits.FiniteBits a => Data.Bits.FiniteBits (Numeric.ProductOrd.Partial.ProductOrd a) instance Data.Bits.Bits a => Data.Bits.Bits (Numeric.ProductOrd.Partial.ProductOrd a) instance Data.Traversable.Traversable Numeric.ProductOrd.Partial.ProductOrd instance Foreign.Storable.Storable a => Foreign.Storable.Storable (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Base.Monoid a => GHC.Base.Monoid (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Real.Fractional a => GHC.Real.Fractional (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Float.Floating a => GHC.Float.Floating (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Enum.Enum a => GHC.Enum.Enum (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Num.Num a => GHC.Num.Num (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Generics.Generic1 Numeric.ProductOrd.Partial.ProductOrd instance GHC.Generics.Generic (Numeric.ProductOrd.Partial.ProductOrd a) instance Data.Data.Data a => Data.Data.Data (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Read.Read a => GHC.Read.Read (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Show.Show a => GHC.Show.Show (Numeric.ProductOrd.Partial.ProductOrd a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.ProductOrd.Partial.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd a), GHC.Real.Integral a) => GHC.Real.Integral (Numeric.ProductOrd.Partial.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd a), GHC.Real.Real a) => GHC.Real.Real (Numeric.ProductOrd.Partial.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd a), GHC.Real.RealFrac a) => GHC.Real.RealFrac (Numeric.ProductOrd.Partial.ProductOrd a) instance (GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd a), GHC.Float.RealFloat a) => GHC.Float.RealFloat (Numeric.ProductOrd.Partial.ProductOrd a) instance Data.Foldable.Foldable Numeric.ProductOrd.Partial.ProductOrd instance GHC.Base.Functor Numeric.ProductOrd.Partial.ProductOrd instance GHC.Base.Applicative Numeric.ProductOrd.Partial.ProductOrd instance GHC.Base.Monad Numeric.ProductOrd.Partial.ProductOrd instance Control.Monad.Fix.MonadFix Numeric.ProductOrd.Partial.ProductOrd instance Control.Monad.Zip.MonadZip Numeric.ProductOrd.Partial.ProductOrd instance forall k (f :: k -> *) (xs :: [k]). Data.Type.List.All GHC.Classes.Ord (Data.Type.List.Map f xs) => GHC.Classes.Eq (Numeric.ProductOrd.Partial.ProductOrd (Numeric.TypedList.TypedList f xs)) instance forall k (f :: k -> *) (xs :: [k]). Data.Type.List.All GHC.Classes.Ord (Data.Type.List.Map f xs) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (Numeric.TypedList.TypedList f xs)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4, a5)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4, a5, a6)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4, a5, a6, a7)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7, GHC.Classes.Ord a8) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4, a5, a6, a7, a8)) instance (GHC.Classes.Ord a1, GHC.Classes.Ord a2, GHC.Classes.Ord a3, GHC.Classes.Ord a4, GHC.Classes.Ord a5, GHC.Classes.Ord a6, GHC.Classes.Ord a7, GHC.Classes.Ord a8, GHC.Classes.Ord a9) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (a1, a2, a3, a4, a5, a6, a7, a8, a9)) -- | The core easytensor types. module Numeric.DataFrame.Type -- | Data frame that has an unknown dimensionality at compile time. -- Pattern-match against its constructor to get a Nat-indexed data frame data SomeDataFrame (t :: l) SomeDataFrame :: DataFrame t ns -> SomeDataFrame -- | DataFrame with its type arguments swapped. data DataFrame' (xs :: [k]) (t :: l) -- | Keep data in a primitive data frame and maintain information about -- Dimensions in the type system data family DataFrame (t :: l) (xs :: [k]) -- | Empty MultiFrame pattern Z :: forall (xs :: [Type]) (ns :: [Nat]). () => xs ~ '[] => DataFrame xs ns -- | Constructing a MultiFrame using DataFrame columns 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 :*: -- | A scalar DataFrame is just a newtype wrapper on a value. 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) -- | Convert any type to a scalar wrapper scalar :: t -> DataFrame t ('[] :: [Nat]) -- | Convert a scalar back to an ordinary type unScalar :: DataFrame t ('[] :: [Nat]) -> t -- | Index one dimension deep into a DataFrame. class IndexFrame t d ds -- | 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). (!) :: IndexFrame t d ds => DataFrame t (d : ds) -> Word -> DataFrame t ds -- | This type family describes two strategies for dealing with dimensions -- when slicing a DataFrame. -- -- If the original space dimension (d) is fixed at compile time -- (d :: Nat or d ~ N n), then we enforce the safety of -- a slicing operation with types: the index space is bounded by the size -- of the original space minus the subframe size. -- -- If the original space dimension (d) is not fixed (d ~ XN -- m), then we give up. Just let the user do the slicing as easy as -- possible, and throw an OutOfDimBounds exception at runtime if -- the index plus the sliced size is greater than the original size of -- the DataFrame. type family SubFrameIndexCtx (d :: k) (idxN :: k) (subN :: k) :: Constraint -- | Represent smart constructor functions packDF and -- unpackDF. type family PackDF (t :: Type) (ds :: [Nat]) (d :: Nat) (r :: Type) :: Type -- | Takes d arguments of type DataFrame t ds and produce -- a DataFrame t (d ': ds). -- -- NB: always use TypeApplications extension with this function -- to apply all type arguments! Otherwise, a very dumb type family -- PackDF will not infer the types for you. -- -- The following example creates a Matrix Double 12 3 filled -- with twelve 3D vectors (using fromInteger of Vector -- Double 3): -- --
-- >>> packDF @Double @12 @'[3] 1 2 3 4 5 6 7 8 9 10 11 12 ---- -- packDF and unpackDF together serve as a generic -- constructor for a DataFrame of an arbitrary (statically known) size. packDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d : ds)) => PackDF t ds d (DataFrame t (d : ds)) -- | Takes a function (e.g. a constructor) with d+1 argument (df1, -- df2, .. dfd, Dict) and a DataFrame t (d ': ds). Feeds the -- dataframe elements into that function. For example, you can pass a -- tuple to this function, and get all dataframe elements (and some -- dictionaries -- useful evidence to work with element frames) -- -- NB: always use TypeApplications extension with this function -- to apply all type arguments! Otherwise, a very dumb type family -- PackDF will not infer the types for you. -- -- The following example unpacks a 3D vector (created using -- fromInteger of Vector Double 3) into a 4-tuple with -- three scalars and one Dict: -- --
-- >>> unpackDF @Double @3 @'[] (,,,) 2 ---- -- packDF and unpackDF together serve as a generic -- constructor for a DataFrame of an arbitrary (statically known) size. unpackDF :: forall (t :: Type) (d :: Nat) (ds :: [Nat]) (rep :: RuntimeRep) (r :: TYPE rep). (PrimBytes t, Dimensions (d : ds)) => PackDF t ds d (Dict (Dimensions ds, KnownBackend t ds) -> r) -> DataFrame t (d : ds) -> r -- | Append one DataFrame to another, sum up the first dimension. -- -- If you want to deconstruct a DataFrame, use index or -- slice instead. appendDF :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n, KnownDim m) => DataFrame t (n :+ ds) -> DataFrame t (m :+ ds) -> DataFrame t ((n + m) :+ ds) -- | Append a small DataFrame to a big DataFrame on the left. -- -- If you want to deconstruct a DataFrame, use index or -- slice instead. consDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t ds -> DataFrame t (n :+ ds) -> DataFrame t ((n + 1) :+ ds) -- | Append a small DataFrame to a big DataFrame on the right. -- -- If you want to deconstruct a DataFrame, use index or -- slice instead. snocDF :: forall (n :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes t, Dimensions ds, KnownDim n) => DataFrame t (n :+ ds) -> DataFrame t ds -> DataFrame t ((n + 1) :+ ds) -- | Construct a DataFrame from a flat list. -- -- The values are filled according to the DataFrame layout: row-by-row -- and further from the last dimension (least significant) to the first -- dimension (most significant). -- -- If the argument list is shorter than totalDim, then the rest -- of the frame is padded with a default value (second argument). -- -- If the argument list is longer than totalDim, then unused -- values are dropped. If you want, you can pass an infinite list as an -- argument, i.e. the following is a valid use: -- --
-- >>> fromFlatList (dims :: Dims '[2,5]) 0 [6,8..] --fromFlatList :: forall (t :: Type) (ds :: [Nat]). PrimArray t (DataFrame t ds) => Dims ds -> t -> [t] -> DataFrame t ds -- | Construct a DataFrame from a list of smaller DataFrames. -- -- If the argument list is shorter than d, then the rest of the -- frame is padded with a default value (first argument). -- -- If the argument list is longer than d, then unused values are -- dropped. If you want, you can pass an infinite list as an argument. fromListWithDefault :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). (PrimBytes t, Dimensions (d : ds)) => DataFrame t ds -> [DataFrame t ds] -> DataFrame t (d : ds) -- | Construct a dynamic DataFrame from a list of smaller DataFrames. -- Pattern-match against the resulting XFrame to find out its -- dimensionality. -- -- You must not provide an infinite list as an argument. fromList :: forall (t :: Type) (ds :: [Nat]) (xds :: [XNat]). (PrimBytes t, Dimensions ds, xds ~ Map N ds, ds ~ UnMap N xds) => [DataFrame t ds] -> DataFrame t (XN 0 : xds) -- | Try to convert between XNat-indexed DataFrames. -- -- This is useful for imposing restrictions on unknown DataFrames, e.g. -- increasing the minimum number of elements. constrainDF :: forall (ds :: [XNat]) (ys :: [XNat]) t. (BoundedDims ds, All KnownDimType ds) => DataFrame t ys -> Maybe (DataFrame t ds) -- | Place elements of a vector on the main diagonal of a matrix; fill the -- rest of the matrix with zeroes. -- -- Note, this function is naturally generalized onto higher dimensions -- (which can be seen from the type signature). -- -- Note, the argument of this function does not fully determine its -- result type. This may cause some obscure type errors. Specify type -- parameters n and m explicitly or make sure the -- result type is fixed. asDiag :: forall (n :: Nat) (m :: Nat) (ds :: [Nat]) (t :: Type). (Dimensions ds, KnownDim n, KnownDim m, KnownBackend t (Min n m :+ ds), KnownBackend t (n :+ (m :+ ds)), PrimBytes t) => DataFrame t (Min n m :+ ds) -> DataFrame t (n :+ (m :+ ds)) class KnownBackend t ds BackendFamily t ds => KnownBackend t (ds :: [Nat]) -- | Implementation behind the DataFrame type DFBackend (t :: Type) (ds :: [Nat]) = Backend I t ds (BackendFamily t ds) -- | I use this kind-polymorphic constraint to generalize XFrame -- and SomeDataFrame over SingleFrame and -- MultiFrame. type family KnownBackends (ts :: l) (ns :: [Nat]) :: Constraint -- | Allow inferring KnownBackends if you know the dimensions and -- the element types. class InferKnownBackend t (ds :: [Nat]) -- | Infer KnownBackends if you know the dimensions and the -- element types. inferKnownBackend :: InferKnownBackend t ds => Dict (KnownBackends t ds) -- | Evidence that the elements of the DataFrame are PrimBytes. inferPrimElem :: forall (t :: Type) (d :: Nat) (ds :: [Nat]). KnownBackend t (d : ds) => DataFrame t (d : ds) -> Dict (PrimBytes t) -- | 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 XNats to represent them. data Dim (x :: k) :: forall k. () => k -> Type -- | Match against this pattern to bring KnownDim instance into -- scope. pattern D :: forall k (d :: k). KnownDimType d => (KindOf d ~ Nat, KnownDim d) => Dim d -- | Match Dim n against a concrete Nat pattern D1 :: forall (n :: Nat). () => n ~ 1 => Dim n -- | Match Dim n against a concrete Nat pattern D25 :: forall (n :: Nat). () => n ~ 25 => Dim n -- | Match Dim n against a concrete Nat pattern D24 :: forall (n :: Nat). () => n ~ 24 => Dim n -- | Match Dim n against a concrete Nat pattern D23 :: forall (n :: Nat). () => n ~ 23 => Dim n -- | Match Dim n against a concrete Nat pattern D22 :: forall (n :: Nat). () => n ~ 22 => Dim n -- | Match Dim n against a concrete Nat pattern D21 :: forall (n :: Nat). () => n ~ 21 => Dim n -- | Match Dim n against a concrete Nat pattern D20 :: forall (n :: Nat). () => n ~ 20 => Dim n -- | Match Dim n against a concrete Nat pattern D19 :: forall (n :: Nat). () => n ~ 19 => Dim n -- | Match Dim n against a concrete Nat pattern D18 :: forall (n :: Nat). () => n ~ 18 => Dim n -- | Match Dim n against a concrete Nat pattern D17 :: forall (n :: Nat). () => n ~ 17 => Dim n -- | Match Dim n against a concrete Nat pattern D16 :: forall (n :: Nat). () => n ~ 16 => Dim n -- | Match Dim n against a concrete Nat pattern D15 :: forall (n :: Nat). () => n ~ 15 => Dim n -- | Match Dim n against a concrete Nat pattern D14 :: forall (n :: Nat). () => n ~ 14 => Dim n -- | Match Dim n against a concrete Nat pattern D13 :: forall (n :: Nat). () => n ~ 13 => Dim n -- | Match Dim n against a concrete Nat pattern D12 :: forall (n :: Nat). () => n ~ 12 => Dim n -- | Match Dim n against a concrete Nat pattern D11 :: forall (n :: Nat). () => n ~ 11 => Dim n -- | Match Dim n against a concrete Nat pattern D10 :: forall (n :: Nat). () => n ~ 10 => Dim n -- | Match Dim n against a concrete Nat pattern D9 :: forall (n :: Nat). () => n ~ 9 => Dim n -- | Match Dim n against a concrete Nat pattern D8 :: forall (n :: Nat). () => n ~ 8 => Dim n -- | Match Dim n against a concrete Nat pattern D7 :: forall (n :: Nat). () => n ~ 7 => Dim n -- | Match Dim n against a concrete Nat pattern D6 :: forall (n :: Nat). () => n ~ 6 => Dim n -- | Match Dim n against a concrete Nat pattern D5 :: forall (n :: Nat). () => n ~ 5 => Dim n -- | Match Dim n against a concrete Nat pattern D4 :: forall (n :: Nat). () => n ~ 4 => Dim n -- | Match Dim n against a concrete Nat pattern D3 :: forall (n :: Nat). () => n ~ 3 => Dim n -- | Match Dim n against a concrete Nat pattern D2 :: forall (n :: Nat). () => n ~ 2 => Dim n -- | Match Dim n against a concrete Nat pattern D0 :: forall (n :: Nat). () => n ~ 0 => Dim n -- | XNat that is unknown at compile time. Same as SomeNat, -- but for a dimension: Hide dimension size inside, but allow specifying -- its minimum possible value. pattern Dx :: forall (d :: XNat). KnownDimType d => forall (m :: Nat) (n :: Nat). (KindOf d ~ XNat, d ~ XN m, m <= n) => Dim n -> Dim d -- | Statically known XNat pattern Dn :: forall (d :: XNat). KnownDimType d => forall (n :: Nat). (KindOf d ~ XNat, d ~ N n) => Dim n -> Dim d -- | This type is used to index a single dimension. -- --
-- 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. class PrimTagged a => PrimBytes a -- | A wrapper on byteSize bSizeOf :: (PrimBytes a, Num b) => a -> b -- | A wrapper on byteAlign bAlignOf :: (PrimBytes a, Num b) => a -> b -- | A wrapper on byteFieldOffset. 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 -- | Index array by an integer offset (starting from 0). ixOff :: PrimArray t a => Int -> a -> t instance forall k l (t :: l) (xs :: [k]). (Data.Data.Data (Numeric.DataFrame.Type.DataFrame t xs), Data.Typeable.Internal.Typeable t, Data.Typeable.Internal.Typeable xs, Data.Typeable.Internal.Typeable k, Data.Typeable.Internal.Typeable l) => Data.Data.Data (Numeric.DataFrame.Type.DataFrame' xs t) instance GHC.Classes.Eq (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Classes.Ord (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Classes.Ord (Numeric.DataFrame.Type.DataFrame t ds) instance Numeric.ProductOrd.ProductOrder (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => Numeric.ProductOrd.ProductOrder (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Enum.Bounded (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Enum.Enum (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Enum.Enum (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Real.Integral (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Real.Integral (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Num.Num (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Num.Num (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Real.Fractional (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Real.Fractional (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Float.Floating (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Float.Floating (Numeric.DataFrame.Type.DataFrame t ds) instance Numeric.Basics.Epsilon (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => Numeric.Basics.Epsilon (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Real.Real (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Real.Real (Numeric.DataFrame.Type.DataFrame t ds) instance Numeric.Basics.RealExtras (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => Numeric.Basics.RealExtras (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Real.RealFrac (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Real.RealFrac (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Float.RealFloat (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => GHC.Float.RealFloat (Numeric.DataFrame.Type.DataFrame t ds) instance Numeric.Basics.RealFloatExtras (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => Numeric.Basics.RealFloatExtras (Numeric.DataFrame.Type.DataFrame t ds) instance Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Internal.BackendI.DFBackend t ds) => Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Type.DataFrame t ds) instance (Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Internal.BackendI.DFBackend t ds), Numeric.PrimBytes.PrimBytes t) => Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Generics.Generic (Numeric.DataFrame.Type.DataFrame ts ds) instance (Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.Dimensions ds) => GHC.Generics.Generic (Numeric.DataFrame.Type.DataFrame t ds) instance (Data.Data.Data t, Numeric.PrimBytes.PrimBytes t, Data.Typeable.Internal.Typeable ds) => Data.Data.Data (Numeric.DataFrame.Type.DataFrame t ds) instance (Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Type.DataFrame t '[d]), Numeric.Dimensions.Dim.KnownDim d) => Numeric.DataFrame.Type.IndexFrame t d '[] instance (Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Type.DataFrame t (d : ds)), Numeric.Dimensions.Dim.KnownDim d, Numeric.DataFrame.Internal.Backend.KnownBackend t ds) => Numeric.DataFrame.Type.IndexFrame t d ds instance Numeric.DataFrame.Type.IndexFrame '[] d ds instance (Numeric.DataFrame.Type.IndexFrame t d ds, Numeric.DataFrame.Type.IndexFrame ts d ds) => Numeric.DataFrame.Type.IndexFrame (t : ts) d ds instance Numeric.PrimBytes.PrimBytes t => Numeric.DataFrame.Type.IndexFrame t xd xds instance (Numeric.TypedList.RepresentableList ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts) => Numeric.DataFrame.Type.IndexFrame ts xd xds instance Numeric.DataFrame.Type.AllFrames GHC.Classes.Eq ts ds => GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts ds) instance (Numeric.DataFrame.Type.AllFrames Data.Data.Data ts ds, Data.Typeable.Internal.Typeable ts, Data.Typeable.Internal.Typeable ds) => Data.Data.Data (Numeric.DataFrame.Type.DataFrame ts ds) instance (Numeric.DataFrame.Type.AllFrames GHC.Classes.Eq ts ds, Numeric.DataFrame.Type.AllFrames GHC.Classes.Ord ts ds) => GHC.Classes.Ord (Numeric.DataFrame.Type.DataFrame ts ds) instance (Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.Dimensions ds) => Numeric.DataFrame.Type.InferKnownBackend t ds instance (Numeric.TypedList.RepresentableList ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts, Numeric.Dimensions.Dim.Dimensions ds) => Numeric.DataFrame.Type.InferKnownBackend ts ds instance GHC.Classes.Eq t => GHC.Classes.Eq (Numeric.DataFrame.Type.SomeDataFrame t) instance Data.Type.List.All GHC.Classes.Eq ts => GHC.Classes.Eq (Numeric.DataFrame.Type.SomeDataFrame ts) instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t) => GHC.Show.Show (Numeric.DataFrame.Type.SomeDataFrame t) instance (Data.Type.List.All GHC.Show.Show ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts) => GHC.Show.Show (Numeric.DataFrame.Type.SomeDataFrame ts) instance (GHC.Read.Read t, Numeric.PrimBytes.PrimBytes t) => GHC.Read.Read (Numeric.DataFrame.Type.SomeDataFrame t) instance (Data.Type.List.All GHC.Read.Read ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts, Numeric.TypedList.RepresentableList ts) => GHC.Read.Read (Numeric.DataFrame.Type.SomeDataFrame ts) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Type.KnownBackends ts (Numeric.Dimensions.Dim.DimsBound xns), GHC.Num.Num (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => GHC.Num.Num (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Type.KnownBackends ts (Numeric.Dimensions.Dim.DimsBound xns), GHC.Real.Fractional (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => GHC.Real.Fractional (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Type.KnownBackends ts (Numeric.Dimensions.Dim.DimsBound xns), GHC.Float.Floating (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => GHC.Float.Floating (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Type.KnownBackends ts (Numeric.Dimensions.Dim.DimsBound xns), GHC.Enum.Bounded (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => GHC.Enum.Bounded (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Type.KnownBackends ts (Numeric.Dimensions.Dim.DimsBound xns), Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (ts :: l). (GHC.Enum.Enum (Numeric.DataFrame.Type.DataFrame ts '[]), Numeric.DataFrame.Type.KnownBackends ts '[]) => GHC.Enum.Enum (Numeric.DataFrame.Type.DataFrame ts '[]) instance forall l (ts :: l). (Numeric.Basics.Epsilon (Numeric.DataFrame.Type.DataFrame ts '[]), Numeric.DataFrame.Type.KnownBackends ts '[], GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts '[])) => Numeric.Basics.Epsilon (Numeric.DataFrame.Type.DataFrame ts '[]) instance forall l (ts :: l). (GHC.Real.Real (Numeric.DataFrame.Type.DataFrame ts '[]), Numeric.DataFrame.Type.KnownBackends ts '[], GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts '[])) => GHC.Real.Real (Numeric.DataFrame.Type.DataFrame ts '[]) instance forall l (ts :: l). (GHC.Real.Integral (Numeric.DataFrame.Type.DataFrame ts '[]), Numeric.DataFrame.Type.KnownBackends ts '[], GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts '[])) => GHC.Real.Integral (Numeric.DataFrame.Type.DataFrame ts '[]) instance GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (Numeric.DataFrame.Internal.BackendI.DFBackend t ds)) => GHC.Classes.Ord (Numeric.ProductOrd.NonTransitive.ProductOrd (Numeric.DataFrame.Type.DataFrame t ds)) instance (GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (Numeric.DataFrame.Internal.BackendI.DFBackend t ds)), GHC.Classes.Eq (Numeric.DataFrame.Internal.BackendI.DFBackend t ds)) => GHC.Classes.Ord (Numeric.ProductOrd.Partial.ProductOrd (Numeric.DataFrame.Type.DataFrame t ds)) instance forall k l (t :: l) (ds :: [k]). Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Type.DataFrame t ds) => Foreign.Storable.Storable (Numeric.DataFrame.Type.DataFrame t ds) instance GHC.Classes.Eq t => GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame t ds) instance Data.Type.List.All GHC.Classes.Eq ts => GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts ds) instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.Dimensions ds) => GHC.Show.Show (Numeric.DataFrame.Type.DataFrame t ds) instance (Data.Type.List.All GHC.Show.Show ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts, Numeric.Dimensions.Dim.Dimensions ds) => GHC.Show.Show (Numeric.DataFrame.Type.DataFrame ts ds) instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t) => GHC.Show.Show (Numeric.DataFrame.Type.DataFrame t xns) instance (Data.Type.List.All GHC.Show.Show ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts) => GHC.Show.Show (Numeric.DataFrame.Type.DataFrame ts xns) instance (GHC.Read.Read t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.Dimensions ds) => GHC.Read.Read (Numeric.DataFrame.Type.DataFrame t ds) instance (Data.Type.List.All GHC.Read.Read ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts, Numeric.TypedList.RepresentableList ts, Numeric.Dimensions.Dim.Dimensions ds) => GHC.Read.Read (Numeric.DataFrame.Type.DataFrame ts ds) instance (GHC.Read.Read t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.BoundedDims ds, Data.Type.List.All Numeric.Dimensions.Dim.KnownDimType ds) => GHC.Read.Read (Numeric.DataFrame.Type.DataFrame t ds) instance (Data.Type.List.All GHC.Read.Read ts, Data.Type.List.All Numeric.PrimBytes.PrimBytes ts, Numeric.TypedList.RepresentableList ts, Numeric.Dimensions.Dim.BoundedDims ds, Data.Type.List.All Numeric.Dimensions.Dim.KnownDimType ds) => GHC.Read.Read (Numeric.DataFrame.Type.DataFrame ts ds) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (xns Data.Type.Equality.~ Data.Type.List.Map 'Numeric.Dimensions.Dim.N (Numeric.Dimensions.Dim.DimsBound xns), GHC.Classes.Eq (Numeric.DataFrame.Type.DataFrame ts xns), GHC.Classes.Ord (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => GHC.Classes.Ord (Numeric.DataFrame.Type.DataFrame ts xns) instance forall l (xns :: [Numeric.Dimensions.Dim.XNat]) (ts :: l). (xns Data.Type.Equality.~ Data.Type.List.Map 'Numeric.Dimensions.Dim.N (Numeric.Dimensions.Dim.DimsBound xns), Numeric.ProductOrd.ProductOrder (Numeric.DataFrame.Type.DataFrame ts (Numeric.Dimensions.Dim.DimsBound xns))) => Numeric.ProductOrd.ProductOrder (Numeric.DataFrame.Type.DataFrame ts xns) instance (Numeric.Dimensions.Dim.Dimensions xns, Numeric.DataFrame.Internal.Backend.KnownBackend t (Numeric.Dimensions.Dim.DimsBound xns), Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Type.DataFrame t (Numeric.Dimensions.Dim.DimsBound xns)), Numeric.PrimBytes.PrimBytes t) => Numeric.DataFrame.Internal.PrimArray.PrimArray t (Numeric.DataFrame.Type.DataFrame t xns) instance (Numeric.Basics.RealExtras (Numeric.DataFrame.Type.DataFrame t '[]), Numeric.DataFrame.Internal.Backend.KnownBackend t '[], GHC.Classes.Eq t) => Numeric.Basics.RealExtras (Numeric.DataFrame.Type.DataFrame t '[]) instance (GHC.Real.RealFrac (Numeric.DataFrame.Type.DataFrame t '[]), Numeric.DataFrame.Internal.Backend.KnownBackend t '[], GHC.Classes.Eq t) => GHC.Real.RealFrac (Numeric.DataFrame.Type.DataFrame t '[]) instance (GHC.Float.RealFloat (Numeric.DataFrame.Type.DataFrame t '[]), Numeric.DataFrame.Internal.Backend.KnownBackend t '[], GHC.Classes.Eq t) => GHC.Float.RealFloat (Numeric.DataFrame.Type.DataFrame t '[]) instance (Numeric.Basics.RealFloatExtras (Numeric.DataFrame.Type.DataFrame t '[]), Numeric.DataFrame.Internal.Backend.KnownBackend t '[], GHC.Classes.Eq t) => Numeric.Basics.RealFloatExtras (Numeric.DataFrame.Type.DataFrame t '[]) -- | Interface to perform primitive stateful operations on mutable frames. module Numeric.DataFrame.Internal.Mutable -- | Mutable DataFrame type. Keeps element offset, number of elements, and -- a mutable byte storage data MDataFrame s t (ns :: [k]) -- | Allow coercing between XNat-indexed and Nat-indexed -- Mutable DataFrames. castDataFrame# :: forall (t :: Type) (xns :: [XNat]) (ns :: [Nat]) s. FixedDims xns ns => MDataFrame s t ns -> MDataFrame s t xns -- | Create a new mutable DataFrame. newDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. (PrimBytes t, Dimensions ns) => State# s -> (# State# s, MDataFrame s t ns #) -- | Create a new mutable DataFrame. newPinnedDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. (PrimBytes t, Dimensions ns) => State# s -> (# State# s, MDataFrame s t ns #) -- | Create a new mutable DataFrame of the same size. oneMoreDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. MDataFrame s t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | View a part of a DataFrame. -- -- This function does not perform a copy. All changes to a new DataFrame -- will be reflected in the original DataFrame as well. -- -- 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. subDataFrameView# :: forall (t :: Type) (k :: Type) (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (SubFrameIndexCtx b bi bd, KnownDim bd, ConcatList as (b :+ bs) asbs) => Idxs (as +: bi) -> MDataFrame s t asbs -> MDataFrame s t (bd :+ bs) -- | View a part of a DataFrame. -- -- This function does not perform a copy. All changes to a new DataFrame -- will be reflected in the original DataFrame as well. -- -- This is a simpler version of subDataFrameView that allows to -- view over one index at a time. -- -- 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. subDataFrameView'# :: forall (t :: Type) (k :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. ConcatList as bs asbs => Idxs as -> MDataFrame s t asbs -> MDataFrame s t bs -- | Copy one DataFrame into another mutable DataFrame at specified -- position. -- -- In contrast to copyDataFrame', this function allows to copy -- over a range of contiguous indices over a single dimension. For -- example, you can write a 3x4 matrix into a 7x4 matrix, starting at -- indices 0..3. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. If (b ~ XN m) and (Idx bi + Dim bd -- > Dim b), this function copies only as many elements as fits -- into the dataframe along this dimension (possibly none). copyDataFrame# :: forall (t :: Type) (k :: Type) (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) -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. -- -- In contrast to copyMutableDataFrame', this function allows to -- copy over a range of contiguous indices over a single dimension. For -- example, you can write a 3x4 matrix into a 7x4 matrix, starting at -- indices 0..3. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. If (b ~ XN m) and (Idx bi + Dim bd -- > Dim b), this function copies only as many elements as fits -- into the dataframe along this dimension (possibly none). copyMDataFrame# :: forall (t :: Type) (k :: Type) (b :: k) (bi :: k) (bd :: k) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (SubFrameIndexCtx b bi bd, ExactDims bs, PrimBytes t, ConcatList as (b :+ bs) asbs) => Idxs (as +: bi) -> MDataFrame s t (bd :+ bs) -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one DataFrame into another mutable DataFrame at specified -- position. -- -- This is a simpler version of copyDataFrame that allows to -- copy over one index at a time. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. copyDataFrame'# :: forall (t :: Type) (k :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (ExactDims bs, PrimArray t (DataFrame t bs), ConcatList as bs asbs) => Idxs as -> DataFrame t bs -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. -- -- This is a simpler version of copyMutableDataFrame that allows -- to copy over one index at a time. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. copyMDataFrame'# :: forall (t :: Type) (k :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (ExactDims bs, PrimBytes t, ConcatList as bs asbs) => Idxs as -> MDataFrame s t bs -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one DataFrame into another mutable DataFrame by offset in -- primitive elements. -- -- This is a low-level copy function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds. copyDataFrameOff# :: forall (t :: Type) (k :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (Dimensions bs, PrimArray t (DataFrame t bs), ConcatList as bs asbs) => Int -> DataFrame t bs -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one mutable DataFrame into another mutable DataFrame by offset in -- primitive elements. -- -- This is a low-level copy function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds. copyMDataFrameOff# :: forall (t :: Type) (k :: Type) (as :: [k]) (bs :: [k]) (asbs :: [k]) s. (ExactDims bs, PrimBytes t, ConcatList as bs asbs) => Int -> MDataFrame s t bs -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimArray t (DataFrame t ns) => MDataFrame s t ns -> State# s -> (# State# s, DataFrame t ns #) -- | Make a mutable DataFrame immutable, without copying. unsafeFreezeDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimArray t (DataFrame t ns) => MDataFrame s t ns -> State# s -> (# State# s, DataFrame t ns #) -- | Create a new mutable DataFrame and copy content of immutable one in -- there. thawDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | Create a new mutable DataFrame and copy content of immutable one in -- there. The result array is pinned and aligned. thawPinDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | UnsafeCoerces an underlying byte array. unsafeThawDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | Given two continuations f and g. If the input -- DataFrame is a single broadcast value, use it in f. -- Otherwise, create a new mutable DataFrame and copy content of -- immutable one in there; then use it in g. -- -- This function is useful when thawDataFrame cannot be used due -- to Dimensions ns constraint being not available. withThawDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) (r :: Type) s. PrimArray t (DataFrame t ns) => (t -> State# s -> (# State# s, r #)) -> (MDataFrame s t ns -> State# s -> (# State# s, r #)) -> DataFrame t ns -> State# s -> (# State# s, r #) -- | Write a single element at the specified index. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in ns is unknown (n ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. writeDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimBytes (DataFrame t ('[] :: [k])) => MDataFrame s t ns -> Idxs ns -> DataFrame t ('[] :: [k]) -> State# s -> (# State# s, () #) -- | Write a single element at the specified element offset. -- -- This is a low-level write function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds. writeDataFrameOff# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimBytes (DataFrame t ('[] :: [k])) => MDataFrame s t ns -> Int -> DataFrame t ('[] :: [k]) -> State# s -> (# State# s, () #) -- | Read a single element at the specified index. -- -- If any of the dims in ns is unknown (n ~ XN m), then -- this function is unsafe and can throw an OutOfDimBounds -- exception. Otherwise, its safety is guaranteed by the type system. readDataFrame# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimBytes (DataFrame t ('[] :: [k])) => MDataFrame s t ns -> Idxs ns -> State# s -> (# State# s, DataFrame t ('[] :: [k]) #) -- | Read a single element at the specified element offset. -- -- This is a low-level read function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you read beyond the DataFrame -- bounds. readDataFrameOff# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. PrimBytes (DataFrame t ('[] :: [k])) => MDataFrame s t ns -> Int -> State# s -> (# State# s, DataFrame t ('[] :: [k]) #) -- | Allow arbitrary operations on a pointer to the beginning of the data. -- Only possible with RealWord state (thus, in IO) due -- to semantics of touch# operation that keeps the data from -- being garbage collected. withDataFramePtr# :: forall (t :: Type) (k :: Type) (ns :: [k]) (r :: Type). PrimBytes t => MDataFrame RealWorld t ns -> (Addr# -> State# RealWorld -> (# State# RealWorld, r #)) -> State# RealWorld -> (# State# RealWorld, r #) -- | Check if the byte array wrapped by this DataFrame is pinned, which -- means cannot be relocated by GC. isDataFramePinned# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. MDataFrame s t ns -> Bool -- | Get cumulative dimensions ns of a MDataFrame s t ns getDataFrameSteps# :: forall (t :: Type) (k :: Type) (ns :: [k]) s. MDataFrame s t ns -> CumulDims -- | Mutable DataFrames living in ST. module Numeric.DataFrame.ST -- | Mutable DataFrame that lives in ST. Internal representation is always -- a MutableByteArray. data STDataFrame s (t :: Type) (ns :: [k]) -- | Data frame with some dimensions missing at compile time. Pattern-match -- against its constructor to get a Nat-indexed mutable data frame. pattern XSTFrame :: forall s (t :: Type) (xns :: [XNat]). () => forall (ns :: [Nat]). (FixedDims xns ns, Dimensions ns) => STDataFrame s t ns -> STDataFrame s t xns -- | Mutable DataFrame of unknown dimensionality data SomeSTDataFrame s (t :: Type) SomeSTDataFrame :: STDataFrame s t ns -> SomeSTDataFrame s -- | Allow coercing between XNat-indexed and Nat-indexed -- Mutable DataFrames. castDataFrame :: forall (t :: Type) (xns :: [XNat]) (ns :: [Nat]) s. FixedDims xns ns => STDataFrame s t ns -> STDataFrame s t xns -- | Create a new mutable DataFrame. newDataFrame :: forall (t :: Type) ns s. (PrimBytes t, Dimensions ns) => ST s (STDataFrame s t ns) -- | Create a new mutable DataFrame. newPinnedDataFrame :: forall (t :: Type) ns s. (PrimBytes t, Dimensions ns) => ST s (STDataFrame s t ns) -- | Create a new mutable DataFrame of the same size. oneMoreDataFrame :: forall (t :: Type) ns s. STDataFrame s t ns -> ST s (STDataFrame s t ns) -- | View a part of a DataFrame. -- -- This function does not perform a copy. All changes to a new DataFrame -- will be reflected in the original DataFrame as well. -- -- 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. subDataFrameView :: forall (t :: Type) b bi bd as bs asbs s. (SubFrameIndexCtx b bi bd, KnownDim bd, ConcatList as (b :+ bs) asbs) => Idxs (as +: bi) -> STDataFrame s t asbs -> STDataFrame s t (bd :+ bs) -- | View a part of a DataFrame. -- -- This function does not perform a copy. All changes to a new DataFrame -- will be reflected in the original DataFrame as well. -- -- This is a simpler version of subDataFrameView that allows to -- view over one index at a time. -- -- 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. subDataFrameView' :: forall (t :: Type) as bs asbs s. ConcatList as bs asbs => Idxs as -> STDataFrame s t asbs -> STDataFrame s t bs -- | Copy one DataFrame into another mutable DataFrame at specified -- position. -- -- In contrast to copyDataFrame', this function allows to copy -- over a range of contiguous indices over a single dimension. For -- example, you can write a 3x4 matrix into a 7x4 matrix, starting at -- indices 0..3. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. If (b ~ XN m) and (Idx bi + Dim bd -- > Dim b), this function copies only as many elements as fits -- into the dataframe along this dimension (possibly none). copyDataFrame :: forall (t :: Type) b bi bd as bs asbs 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 () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. -- -- In contrast to copyMutableDataFrame', this function allows to -- copy over a range of contiguous indices over a single dimension. For -- example, you can write a 3x4 matrix into a 7x4 matrix, starting at -- indices 0..3. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. If (b ~ XN m) and (Idx bi + Dim bd -- > Dim b), this function copies only as many elements as fits -- into the dataframe along this dimension (possibly none). copyMutableDataFrame :: forall (t :: Type) b bi bd as bs asbs s. (SubFrameIndexCtx b bi bd, ExactDims bs, PrimBytes t, ConcatList as (b :+ bs) asbs) => Idxs (as +: bi) -> STDataFrame s t (bd :+ bs) -> STDataFrame s t asbs -> ST s () -- | Copy one DataFrame into another mutable DataFrame at specified -- position. -- -- This is a simpler version of copyDataFrame that allows to -- copy over one index at a time. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. copyDataFrame' :: forall (t :: Type) as bs asbs s. (ExactDims bs, PrimArray t (DataFrame t bs), ConcatList as bs asbs) => Idxs as -> DataFrame t bs -> STDataFrame s t asbs -> ST s () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. -- -- This is a simpler version of copyMutableDataFrame that allows -- to copy over one index at a time. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in as is unknown (a ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. copyMutableDataFrame' :: forall (t :: Type) as bs asbs s. (ExactDims bs, PrimBytes t, ConcatList as bs asbs) => Idxs as -> STDataFrame s t bs -> STDataFrame s t asbs -> ST s () -- | Copy one DataFrame into another mutable DataFrame by offset in -- primitive elements. -- -- This is a low-level copy function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds. copyDataFrameOff :: forall (t :: Type) as bs asbs s. (Dimensions bs, PrimArray t (DataFrame t bs), ConcatList as bs asbs) => Int -> DataFrame t bs -> STDataFrame s t asbs -> ST s () -- | Copy one mutable DataFrame into another mutable DataFrame by offset in -- primitive elements. -- -- This is a low-level copy function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds copyMutableDataFrameOff :: forall (t :: Type) as bs asbs s. (ExactDims bs, PrimBytes t, ConcatList as bs asbs) => Int -> STDataFrame s t bs -> STDataFrame s t asbs -> ST s () -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame :: forall (t :: Type) ns s. PrimArray t (DataFrame t ns) => STDataFrame s t ns -> ST s (DataFrame t ns) -- | Make a mutable DataFrame immutable, without copying. unsafeFreezeDataFrame :: forall (t :: Type) ns s. PrimArray t (DataFrame t ns) => STDataFrame s t ns -> ST s (DataFrame t ns) -- | Create a new mutable DataFrame and copy content of immutable one in -- there. thawDataFrame :: forall (t :: Type) ns s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | Create a new mutable DataFrame and copy content of immutable one in -- there. The result array is pinned and aligned. thawPinDataFrame :: forall (t :: Type) ns s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | UnsafeCoerces an underlying byte array. unsafeThawDataFrame :: forall (t :: Type) ns s. (Dimensions ns, PrimArray t (DataFrame t ns)) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | Given two continuations f and g. If the input -- DataFrame is a single broadcast value, use it in f. -- Otherwise, create a new mutable DataFrame and copy content of -- immutable one in there; then use it in g. -- -- This function is useful when thawDataFrame cannot be used due -- to Dimensions ns constraint being not available. withThawDataFrame :: forall (t :: Type) ns r s. PrimArray t (DataFrame t ns) => (t -> ST s r) -> (STDataFrame s t ns -> ST s r) -> DataFrame t ns -> ST s r -- | Write a single element at the specified index. -- -- This function is safe (no OutOfDimBounds exception possible). -- If any of the dims in ns is unknown (n ~ XN m), you -- may happen to write data beyond dataframe bounds. In this case, this -- function does nothing. writeDataFrame :: forall (t :: Type) ns s. PrimBytes (DataFrame t ('[] :: KindOf ns)) => STDataFrame s t ns -> Idxs ns -> DataFrame t ('[] :: KindOf ns) -> ST s () -- | Write a single element at the specified element offset. -- -- This is a low-level write function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you write beyond the DataFrame -- bounds. writeDataFrameOff :: forall (t :: Type) ns s. PrimBytes (DataFrame t ('[] :: KindOf ns)) => STDataFrame s t ns -> Int -> DataFrame t ('[] :: KindOf ns) -> ST s () -- | Read a single element at the specified index. -- -- If any of the dims in ns is unknown (n ~ XN m), then -- this function is unsafe and can throw an OutOfDimBounds -- exception. Otherwise, its safety is guaranteed by the type system. readDataFrame :: forall (t :: Type) ns s. PrimBytes (DataFrame t ('[] :: KindOf ns)) => STDataFrame s t ns -> Idxs ns -> ST s (DataFrame t ('[] :: KindOf ns)) -- | Read a single element at the specified element offset. -- -- This is a low-level read function; you have to keep in mind the -- row-major layout of Mutable DataFrames. Offset bounds are not checked. -- You will get an undefined behavior if you read beyond the DataFrame -- bounds. readDataFrameOff :: forall (t :: Type) ns s. PrimBytes (DataFrame t ('[] :: KindOf ns)) => STDataFrame s t ns -> Int -> ST s (DataFrame t ('[] :: KindOf ns)) -- | Check if the byte array wrapped by this DataFrame is pinned, which -- means cannot be relocated by GC. isDataFramePinned :: forall (t :: Type) ns s. STDataFrame s t ns -> Bool -- | Get cumulative dimensions ns of a STDataFrame s t ns getDataFrameSteps :: forall (t :: Type) ns s. STDataFrame s t ns -> CumulDims -- | This module provides a flexible interface to manipulate parts of a -- DataFrame. -- --
-- >>> 1 = vec4 1 1 1 1 -- -- >>> 1 = packQ 0 0 0 1 ---- -- All other numeric operations for vectors are element-wise, but for -- quaternions I have implemented the actual quaternion math. In most of -- the cases, you can think of these as being operations on complex -- numbers, where the role of imaginary i is played by a 3D -- vector. Some of the operations are ambiguous for quaternions; for -- example <math>, but also <math>, and <math>, and any -- other unit quaterion with zero real part. In cases like this, I stick -- to the i-th axis: <math> module Numeric.Quaternion -- | Quaternion operations class (Floating (Quater t), Floating t, Ord t, PrimBytes t, KnownBackend t '[3], KnownBackend t '[4], KnownBackend t '[3, 3], KnownBackend t '[4, 4]) => Quaternion t where { -- | Quaternion data type. The ordering of coordinates is -- (x,y,z,w), where w is the argument, and x y -- z are the components of a 3D vector data family Quater t; } -- | Set the quaternion in format (x,y,z,w) packQ :: Quaternion t => t -> t -> t -> t -> Quater t -- | Get the values of the quaternion in format (x,y,z,w) unpackQ# :: Quaternion t => Quater t -> (# t, t, t, t #) -- | Set the quaternion from 3D axis vector and argument fromVecNum :: Quaternion t => Vector t 3 -> t -> Quater t -- | Set the quaternion from 4D vector in format (x,y,z,w) fromVec4 :: Quaternion t => Vector t 4 -> Quater t -- | Transform the quaternion to 4D vector in format (x,y,z,w) toVec4 :: Quaternion t => Quater t -> Vector t 4 -- | Get scalar square of the quaternion. -- --
-- >>> realToFrac (square q) == q * conjugate q --square :: Quaternion t => Quater t -> t -- | Imaginary part of the quaternion (orientation vector) im :: Quaternion t => Quater t -> Quater t -- | Real part of the quaternion re :: Quaternion t => Quater t -> Quater t -- | Imaginary part of the quaternion as a 3D vector imVec :: Quaternion t => Quater t -> Vector t 3 -- | Real part of the quaternion as a scalar taker :: Quaternion t => Quater t -> t -- | i-th component takei :: Quaternion t => Quater t -> t -- | j-th component takej :: Quaternion t => Quater t -> t -- | k-th component takek :: Quaternion t => Quater t -> t -- | Conjugate quaternion (negate imaginary part) conjugate :: Quaternion t => Quater t -> Quater t -- | Rotates and scales vector in 3D using quaternion. Let <math> , -- <math>, <math>; then the rotation angle is <math>, -- and the axis of rotation is <math>. Scaling is proportional to -- <math>. -- --
-- >>> rotScale q x == q * x * (conjugate q) --rotScale :: Quaternion t => Quater t -> Vector t 3 -> Vector t 3 -- | Creates a quaternion q from two vectors a and -- b, such that rotScale q a == b. getRotScale :: Quaternion t => Vector t 3 -> Vector t 3 -> Quater t -- | Creates a rotation versor from an axis vector and an angle in radians. -- Result is always a unit quaternion (versor). If the argument vector is -- zero, then result is a real unit quaternion. axisRotation :: Quaternion t => Vector t 3 -> t -> Quater t -- | Quaternion rotation angle <math> (where <math> , -- <math>, <math>). -- --
-- >>> q /= 0 ==> axisRotation (imVec q) (qArg q) == signum q --qArg :: Quaternion t => Quater t -> t -- | Create a quaternion from a rotation matrix. Note, that rotations of -- <math> and <math> are equivalent, there result of this -- function may be ambiguious. Assume the sign of the result to be chosen -- arbitrarily. fromMatrix33 :: Quaternion t => Matrix t 3 3 -> Quater t -- | Create a quaternion from a homogenious coordinates trasform matrix. -- Ignores matrix translation transform. Note, that rotations of -- <math> and <math> are equivalent, there result of this -- function may be ambiguious. Assume the sign of the result to be chosen -- arbitrarily. fromMatrix44 :: Quaternion t => Matrix t 4 4 -> Quater t -- | Create a rotation matrix from a quaternion. Note, that rotations of -- <math> and <math> are equivalent, so the following -- property holds: -- --
-- >>> toMatrix33 q == toMatrix33 (-q) --toMatrix33 :: Quaternion t => Quater t -> Matrix t 3 3 -- | Create a homogenious coordinates trasform matrix from a quaternion. -- Translation of the output matrix is zero. Note, that rotations of -- <math> and <math> are equivalent, so the following -- property holds: -- --
-- >>> toMatrix44 q == toMatrix44 (-q) --toMatrix44 :: Quaternion t => Quater t -> Matrix t 4 4 type QDouble = Quater Double type QFloat = Quater Float module Numeric.Matrix.QR -- | Result of QR factorization <math>. data QR (t :: Type) (n :: Nat) (m :: Nat) QR :: Matrix t n n -> Scalar t -> Matrix t n m -> QR -- | Orthogonal matrix <math> [qrQ] :: QR -> Matrix t n n -- | A shortcut for evaluating a determinant of <math> [qrQDet] :: QR -> Scalar t -- | Upper-triangular matrix <math> [qrR] :: QR -> Matrix t n m -- | Result of LQ factorization <math>. data LQ (t :: Type) (n :: Nat) (m :: Nat) LQ :: Matrix t n m -> Matrix t m m -> Scalar t -> LQ -- | Lower-triangular matrix <math> [lqL] :: LQ -> Matrix t n m -- | Orthogonal matrix <math> [lqQ] :: LQ -> Matrix t m m -- | A shortcut for evaluating a determinant of <math> [lqQDet] :: LQ -> Scalar t class (PrimBytes t, Ord t, Epsilon t, KnownDim n, KnownDim m) => MatrixQR t (n :: Nat) (m :: Nat) -- | Compute QR factorization qr :: MatrixQR t n m => Matrix t n m -> QR t n m -- | Compute LQ factorization lq :: MatrixQR t n m => Matrix t n m -> LQ t n m -- | Calculate determinant of a matrix via QR decomposition detViaQR :: forall t n. MatrixQR t n n => Matrix t n n -> Scalar t -- | Calculate inverse of a matrix via QR decomposition inverseViaQR :: forall t n. MatrixQR t n n => Matrix t n n -> Matrix t n n -- | Compute a QR or LQ decomposition of matrix <math>, and solve a -- system of linear equations <math>. -- -- If <math> QR decomposition is used; if <math> this -- function solves linear least squares problem. If <math> -- (underdetermined system) LQ decomposition is used to yield a minimum -- norm solution. qrSolveR :: forall t (n :: Nat) (m :: Nat) (ds :: [Nat]). (MatrixQR t n m, Dimensions ds) => Matrix t n m -> DataFrame t (n :+ ds) -> DataFrame t (m :+ ds) -- | Compute a QR or LQ decomposition of matrix <math>, and solve a -- system of linear equations <math>. -- -- If <math> LQ decomposition is used; if <math> this -- function solves linear least squares problem. If <math> -- (underdetermined system) QR decomposition is used to yield a minimum -- norm solution. qrSolveL :: forall t (n :: Nat) (m :: Nat) (ds :: [Nat]). (MatrixQR t n m, Dimensions ds) => Matrix t n m -> DataFrame t (ds +: m) -> DataFrame t (ds +: n) instance (GHC.Classes.Eq t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m) => GHC.Classes.Eq (Numeric.Matrix.QR.QR t n m) instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m) => GHC.Show.Show (Numeric.Matrix.QR.QR t n m) instance (GHC.Classes.Eq t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m) => GHC.Classes.Eq (Numeric.Matrix.QR.LQ t n m) instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m) => GHC.Show.Show (Numeric.Matrix.QR.LQ t n m) instance (Numeric.PrimBytes.PrimBytes t, GHC.Classes.Ord t, Numeric.Basics.Epsilon t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m) => Numeric.Matrix.QR.MatrixQR t n m module Numeric.Matrix.LU class (KnownDim n, Ord t, Fractional t, PrimBytes t, KnownBackend t '[n, n]) => MatrixLU t (n :: Nat) -- | Compute LU factorization with Partial Pivoting lu :: MatrixLU t n => Matrix t n n -> LU t n -- | Result of LU factorization with Partial Pivoting <math>. data LU (t :: Type) (n :: Nat) LU :: Matrix t n n -> Matrix t n n -> Matrix t n n -> Scalar t -> LU -- | Unit lower triangular matrix <math>. All elements on the -- diagonal of L equal 1. The rest of the elements -- satisfy <math>. [luLower] :: LU -> Matrix t n n -- | Upper triangular matrix <math> [luUpper] :: LU -> Matrix t n n -- | Row permutation matrix <math> [luPerm] :: LU -> Matrix t n n -- | Sign of permutation luPermDet == det . luPerm; <math>. [luPermDet] :: LU -> Scalar t -- | Solve Ax = b problem given LU decomposition of A. luSolveR :: forall t (n :: Nat) (ds :: [Nat]). (MatrixLU t n, Dimensions ds) => LU t n -> DataFrame t (n :+ ds) -> DataFrame t (n :+ ds) -- | Solve xA = b problem given LU decomposition of A. luSolveL :: forall t (n :: Nat) (ds :: [Nat]). (MatrixLU t n, Dimensions ds) => LU t n -> DataFrame t (ds +: n) -> DataFrame t (ds +: n) -- | Calculate determinant of a matrix via LU decomposition detViaLU :: forall (t :: Type) (n :: Nat). MatrixLU t n => Matrix t n n -> Scalar t -- | Calculate inverse of a matrix via LU decomposition inverseViaLU :: forall (t :: Type) (n :: Nat). MatrixLU t n => Matrix t n n -> Matrix t n n instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n) => GHC.Show.Show (Numeric.Matrix.LU.LU t n) instance (GHC.Classes.Eq (Numeric.Matrix.Internal.Matrix t n n), GHC.Classes.Eq t) => GHC.Classes.Eq (Numeric.Matrix.LU.LU t n) instance (Numeric.Dimensions.Dim.KnownDim n, GHC.Classes.Ord t, GHC.Real.Fractional t, Numeric.PrimBytes.PrimBytes t, Numeric.DataFrame.Internal.Backend.KnownBackend t '[n, n]) => Numeric.Matrix.LU.MatrixLU t n module Numeric.Matrix class MatrixTranspose t (n :: k) (m :: k) -- | Transpose Mat transpose :: MatrixTranspose t n m => Matrix t n m -> Matrix t m n class SquareMatrix t (n :: Nat) -- | Mat with 1 on diagonal and 0 elsewhere eye :: SquareMatrix t n => Matrix t n n -- | Put the same value on the Mat diagonal, 0 otherwise diag :: SquareMatrix t n => Scalar t -> Matrix t n n -- | Sum of diagonal elements trace :: SquareMatrix t n => Matrix t n n -> Scalar t class MatrixDeterminant t (n :: Nat) -- | Determinant of Mat det :: MatrixDeterminant t n => Matrix t n n -> Scalar t class MatrixInverse t (n :: Nat) -- | Matrix inverse inverse :: MatrixInverse t n => Matrix t n n -> Matrix t n n -- | Alias for DataFrames of rank 2 type Matrix (t :: l) (n :: k) (m :: k) = DataFrame t '[n, m] -- | Operations on 4x4 transformation matrices and vectors in homogeneous -- coordinates. All angles are specified in radians. -- -- Note: since version 2 of easytensor, DataFrames and matrices -- are row-major. A good SIMD implementation may drastically improve -- performance of 4D vector-matrix products of the form v %* m, -- but not so much for products of the form m %* v (due to -- memory layout). Thus, all operations here assume the former form to -- benefit more from SIMD in future. class HomTransform4 t -- | Create a translation matrix from a vector. The 4th coordinate is -- ignored. -- -- If p ! 3 == 1 and v ! 3 == 0, then -- --
-- p %* translate4 v == p + v --translate4 :: HomTransform4 t => Vector t 4 -> Matrix t 4 4 -- | Create a translation matrix from a vector. -- -- If p ! 3 == 1, then -- --
-- p %* translate3 v == p + toHomVector v --translate3 :: HomTransform4 t => Vector t 3 -> Matrix t 4 4 -- | Rotation matrix for a rotation around the X axis, angle is given in -- radians. e.g. p %* rotateX (pi/2) rotates point p -- around Ox by 90 degrees. rotateX :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around the Y axis, angle is given in -- radians. e.g. p %* rotateY (pi/2) rotates point p -- around Oy by 90 degrees. rotateY :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around the Z axis, angle is given in -- radians. e.g. p %* rotateZ (pi/2) rotates point p -- around Oz by 90 degrees. rotateZ :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around an arbitrary normalized vector -- e.g. p %* rotate (pi/2) v rotates point p around -- v by 90 degrees. rotate :: HomTransform4 t => Vector t 3 -> t -> Matrix t 4 4 -- | Rotation matrix from the Euler angles roll (axis Z), yaw -- (axis Y'), and pitch (axis X''). This order is known -- as Tait-Bryan angles (Z-Y'-X'' intrinsic rotations), or -- nautical angles, or Cardan angles. -- --
-- rotateEuler pitch yaw roll == rotateZ roll %* rotateY yaw %* rotateX pitch ---- -- https://en.wikipedia.org/wiki/Euler_angles#Conventions_2 rotateEuler :: HomTransform4 t => t -> t -> t -> Matrix t 4 4 -- | Create a transform matrix using up direction, camera position and a -- point to look at. Just the same as GluLookAt. lookAt :: HomTransform4 t => Vector t 3 -> Vector t 3 -> Vector t 3 -> Matrix t 4 4 -- | A perspective symmetric projection matrix. Right-handed coordinate -- system. (x - right, y - top) -- http://en.wikibooks.org/wiki/GLSL_Programming/Vertex_Transformations perspective :: HomTransform4 t => t -> t -> t -> t -> Matrix t 4 4 -- | An orthogonal symmetric projection matrix. Right-handed coordinate -- system. (x - right, y - top) -- http://en.wikibooks.org/wiki/GLSL_Programming/Vertex_Transformations orthogonal :: HomTransform4 t => t -> t -> t -> t -> Matrix t 4 4 -- | Add one more dimension and set it to 1. toHomPoint :: HomTransform4 t => Vector t 3 -> Vector t 4 -- | Add one more dimension and set it to 0. toHomVector :: HomTransform4 t => Vector t 3 -> Vector t 4 -- | Transform a homogenous vector or point into a normal 3D vector. If the -- last coordinate is not zero, divide the rest by it. fromHom :: HomTransform4 t => Vector t 4 -> Vector t 3 type Mat22f = Matrix Float 2 2 type Mat23f = Matrix Float 2 3 type Mat24f = Matrix Float 2 4 type Mat32f = Matrix Float 3 2 type Mat33f = Matrix Float 3 3 type Mat34f = Matrix Float 3 4 type Mat42f = Matrix Float 4 2 type Mat43f = Matrix Float 4 3 type Mat44f = Matrix Float 4 4 type Mat22d = Matrix Double 2 2 type Mat23d = Matrix Double 2 3 type Mat24d = Matrix Double 2 4 type Mat32d = Matrix Double 3 2 type Mat33d = Matrix Double 3 3 type Mat34d = Matrix Double 3 4 type Mat42d = Matrix Double 4 2 type Mat43d = Matrix Double 4 3 type Mat44d = Matrix Double 4 4 -- | Compose a 2x2D matrix mat22 :: PrimBytes (t :: Type) => Vector t 2 -> Vector t 2 -> Matrix t 2 2 -- | Compose a 3x3D matrix mat33 :: PrimBytes (t :: Type) => Vector t 3 -> Vector t 3 -> Vector t 3 -> Matrix t 3 3 -- | Compose a 4x4D matrix mat44 :: PrimBytes (t :: Type) => Vector t 4 -> Vector t 4 -> Vector t 4 -> Vector t 4 -> Matrix t 4 4 -- | Tensor contraction. In particular: 1. matrix-matrix product 2. -- matrix-vector or vector-matrix product 3. dot product of two vectors. (%*) :: (Contraction t as bs asbs, KnownDim m, PrimArray t (DataFrame t (as +: m)), PrimArray t (DataFrame t (m :+ bs)), PrimArray t (DataFrame t asbs)) => DataFrame t (as +: m) -> DataFrame t (m :+ bs) -> DataFrame t asbs infixl 7 %* module Numeric.DataFrame -- | Sort a DataFrame along the first dimension. -- -- Note: the elements (which are of type DataFrame t ns) are -- compared lexicographically. sort :: forall (t :: Type) n ns. (SortableDataFrame t (n : ns), Ord t, SortBy n) => DataFrame t (n : ns) -> DataFrame t (n : ns) -- | Sort a DataFrame along the first dimension using given -- comparison function. sortBy :: forall (t :: Type) n ns. (SortableDataFrame t (n : ns), SortBy n) => (DataFrame t ns -> DataFrame t ns -> Ordering) -> DataFrame t (n : ns) -> DataFrame t (n : ns) module Numeric.Matrix.Bidiagonal -- | Decomposition of a matrix <math> such that <math> and -- <math> are orthogonal and <math> is bidiagonal. data BiDiag (t :: Type) (n :: Nat) (m :: Nat) BiDiag :: Matrix t n n -> Scalar t -> Vector t (Min n m) -> Vector t (Min n m) -> Matrix t m m -> Scalar t -> BiDiag -- | <math> left orthogonal matrix [bdU] :: BiDiag -> Matrix t n n -- | A shortcut for evaluating a determinant of <math> [bdUDet] :: BiDiag -> Scalar t -- | Main diagonal of <math> [bdAlpha] :: BiDiag -> Vector t (Min n m) -- | First upper diagonal of <math>; its last element equals zero if -- <math> [bdBeta] :: BiDiag -> Vector t (Min n m) -- | <math> left orthogonal matrix [bdV] :: BiDiag -> Matrix t m m -- | A shortcut for evaluating a determinant of <math> [bdVDet] :: BiDiag -> Scalar t -- | Put two vectors on the main and first upper diagonal. biDiag :: forall (t :: Type) (n :: Nat) (m :: Nat). (PrimBytes t, Num t) => Dims '[n, m] -> Vector t (Min n m) -> Vector t (Min n m) -> Matrix t n m -- | Decompose a matrix <math> such that ( U ) and <math> are -- orthogonal and <math> is bidiagonal. -- -- The first returned number bidiagonalHouseholder :: forall (t :: Type) (n :: Nat) (m :: Nat). (PrimBytes t, Ord t, Epsilon t, KnownDim n, KnownDim m) => Matrix t n m -> BiDiag t n m instance (GHC.Show.Show t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m, Numeric.Dimensions.Dim.KnownDim (Data.Type.Lits.Min n m)) => GHC.Show.Show (Numeric.Matrix.Bidiagonal.BiDiag t n m) instance (GHC.Classes.Eq t, Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dim.KnownDim n, Numeric.Dimensions.Dim.KnownDim m, Numeric.Dimensions.Dim.KnownDim (Data.Type.Lits.Min n m), Numeric.DataFrame.Internal.Backend.KnownBackend t '[Data.Type.Lits.Min n m]) => GHC.Classes.Eq (Numeric.Matrix.Bidiagonal.BiDiag t n m) module Numeric.Matrix.SVD class RealFloatExtras t => MatrixSVD (t :: Type) (n :: Nat) (m :: Nat) -- | Compute SVD factorization of a matrix svd :: (MatrixSVD t n m, IterativeMethod) => Matrix t n m -> SVD t n m -- | Result of SVD factorization M = svdU %* asDiag svdS %* transpose -- svdV . -- -- Invariants: -- --