-- 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. @package easytensor @version 1.0.0.1 -- | The very core of DataFrame: definition of the data family. module Numeric.DataFrame.Family -- | Keep data in a primitive data frame and maintain information about -- Dimensions in the type system -- | Internal primitive functions shared across modules module Numeric.DataFrame.Internal.Array.PrimOps inftyD :: Double inftyF :: Float minInt# :: Int# -> Int# -> Int# loop# :: Int# -> Int# -> Int# -> (Int# -> State# s -> State# s) -> State# s -> State# s -- | Loop with given increment, plus keep the step number in the first -- argument of the iterated function loopWithI# :: Int# -> Int# -> Int# -> (Int# -> Int# -> State# s -> State# s) -> State# s -> State# s -- | Do something in a loop for int i from 0 to (n-1) loop1# :: Int# -> (Int# -> State# s -> State# s) -> State# s -> State# s -- | Do something in a loop for int i from 0 to (n-1) loop1a# :: Int# -> (Int# -> a -> a) -> a -> a -- | Same as overDim#, but with no return value overDim_# :: Dims (ds :: [k]) -> (Idxs ds -> Int# -> State# s -> State# s) -> Int# -> Int# -> State# s -> State# s overDim_'# :: Dims (ds :: [k]) -> (Idxs ds -> Int# -> State# s -> (# State# s, Int# #)) -> Int# -> State# s -> (# State# s, Int# #) module Numeric.PrimBytes -- | Facilities to convert to and from raw byte array. class PrimTagged a => PrimBytes a -- | Store content of a data type in a primitive byte array Should be used -- together with byteOffset function. getBytes :: PrimBytes a => a -> ByteArray# -- | Load content of a data type from a primitive byte array fromBytes :: PrimBytes a => Int# -> ByteArray# -> a -- | Read data from a mutable byte array given an offset in bytes readBytes :: PrimBytes a => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) -- | Write data into a mutable byte array at a given position (offset in -- bytes) writeBytes :: PrimBytes a => MutableByteArray# s -> Int# -> a -> State# s -> State# s -- | Read data from a specified address readAddr :: PrimBytes a => Addr# -> State# s -> (# State# s, a #) -- | Write data to a specified address writeAddr :: PrimBytes a => a -> Addr# -> State# s -> State# s -- | Size of a data type in bytes byteSize :: PrimBytes a => a -> Int# -- | Alignment of a data type in bytes. byteOffset should be -- multiple of this value. byteAlign :: PrimBytes a => a -> Int# -- | Offset of the data in a byte array used to store the data, measured in -- bytes. Should be used together with getBytes function. Unless -- in case of special data types represented by ByteArrays, it is equal -- to zero. byteOffset :: PrimBytes a => a -> Int# -- | Index array given an element offset. -- --
-- indexArray arr i = fromBytes ( i *# byteSize t) arr --indexArray :: PrimBytes a => ByteArray# -> Int# -> a -- | Read a mutable array given an element offset. -- --
-- readArray arr i = readBytes arr ( i *# byteSize t) --readArray :: PrimBytes a => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) -- | Write a mutable array given an element offset. -- --
-- writeArray arr i = writeBytes arr ( i *# byteSize t) --writeArray :: PrimBytes a => MutableByteArray# s -> Int# -> a -> State# s -> State# s -- | Store content of a data type in a primitive byte array Should be used -- together with byteOffset function. getBytes :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => a -> ByteArray# -- | Load content of a data type from a primitive byte array fromBytes :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => Int# -> ByteArray# -> a -- | Read data from a mutable byte array given an offset in bytes readBytes :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) -- | Write data into a mutable byte array at a given position (offset in -- bytes) writeBytes :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => MutableByteArray# s -> Int# -> a -> State# s -> State# s -- | Read data from a specified address readAddr :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => Addr# -> State# s -> (# State# s, a #) -- | Write data to a specified address writeAddr :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => a -> Addr# -> State# s -> State# s -- | Size of a data type in bytes byteSize :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => a -> Int# -- | Alignment of a data type in bytes. byteOffset should be -- multiple of this value. byteAlign :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => a -> Int# -- | Offset of the data in a byte array used to store the data, measured in -- bytes. Should be used together with getBytes function. Unless -- in case of special data types represented by ByteArrays, it is equal -- to zero. byteOffset :: (PrimBytes a, Generic a, GPrimBytes (Rep a)) => a -> Int# data PrimTag a [PTagFloat] :: PrimTag Float [PTagDouble] :: PrimTag Double [PTagInt] :: PrimTag Int [PTagInt8] :: PrimTag Int8 [PTagInt16] :: PrimTag Int16 [PTagInt32] :: PrimTag Int32 [PTagInt64] :: PrimTag Int64 [PTagWord] :: PrimTag Word [PTagWord8] :: PrimTag Word8 [PTagWord16] :: PrimTag Word16 [PTagWord32] :: PrimTag Word32 [PTagWord64] :: PrimTag Word64 [PTagPtr] :: PrimTag (Ptr a) [PTagOther] :: PrimTag a -- | This function allows to find out a type by comparing its tag. This is -- needed for array overloading, to infer array instances. For non-basic -- types it defaults to PTagOther primTag :: PrimBytes a => a -> PrimTag a instance Numeric.PrimBytes.PrimBytes a => Numeric.PrimBytes.GPrimBytes (GHC.Generics.K1 i a) instance Numeric.PrimBytes.PrimBytes GHC.Types.Word instance Numeric.PrimBytes.PrimBytes GHC.Types.Int instance Numeric.PrimBytes.PrimBytes GHC.Types.Float instance Numeric.PrimBytes.PrimBytes GHC.Types.Double instance Numeric.PrimBytes.PrimBytes (GHC.Ptr.Ptr a) instance Numeric.PrimBytes.PrimBytes GHC.Int.Int8 instance Numeric.PrimBytes.PrimBytes GHC.Int.Int16 instance Numeric.PrimBytes.PrimBytes GHC.Int.Int32 instance Numeric.PrimBytes.PrimBytes GHC.Int.Int64 instance Numeric.PrimBytes.PrimBytes GHC.Word.Word8 instance Numeric.PrimBytes.PrimBytes GHC.Word.Word16 instance Numeric.PrimBytes.PrimBytes GHC.Word.Word32 instance Numeric.PrimBytes.PrimBytes GHC.Word.Word64 instance Numeric.PrimBytes.PrimBytes (Numeric.Dimensions.Idxs.Idx x) instance Numeric.TypedList.RepresentableList xs => Numeric.PrimBytes.PrimBytes (Numeric.Dimensions.Idxs.Idxs xs) instance (Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All Numeric.PrimBytes.PrimBytes xs) => Numeric.PrimBytes.PrimBytes (Numeric.Tuple.Lazy.Tuple xs) instance (Numeric.TypedList.RepresentableList xs, Numeric.Type.List.All Numeric.PrimBytes.PrimBytes xs) => Numeric.PrimBytes.PrimBytes (Numeric.Tuple.Strict.Tuple xs) instance Numeric.PrimBytes.PrimBytes a => Numeric.PrimBytes.PrimBytes (GHC.Base.Maybe a) instance (Numeric.PrimBytes.PrimBytes a, Numeric.PrimBytes.PrimBytes b) => Numeric.PrimBytes.PrimBytes (Data.Either.Either a b) instance Numeric.PrimBytes.PrimBytes a => Numeric.PrimBytes.PrimBytes [a] instance Numeric.PrimBytes.PrimTagged a instance Numeric.PrimBytes.PrimTagged GHC.Types.Float instance Numeric.PrimBytes.PrimTagged GHC.Types.Double instance Numeric.PrimBytes.PrimTagged GHC.Types.Int instance Numeric.PrimBytes.PrimTagged GHC.Int.Int8 instance Numeric.PrimBytes.PrimTagged GHC.Int.Int16 instance Numeric.PrimBytes.PrimTagged GHC.Int.Int32 instance Numeric.PrimBytes.PrimTagged GHC.Int.Int64 instance Numeric.PrimBytes.PrimTagged GHC.Types.Word instance Numeric.PrimBytes.PrimTagged GHC.Word.Word8 instance Numeric.PrimBytes.PrimTagged GHC.Word.Word16 instance Numeric.PrimBytes.PrimTagged GHC.Word.Word32 instance Numeric.PrimBytes.PrimTagged GHC.Word.Word64 instance Numeric.PrimBytes.PrimTagged (GHC.Ptr.Ptr a) instance Numeric.PrimBytes.GPrimBytes GHC.Generics.V1 instance Numeric.PrimBytes.GPrimBytes GHC.Generics.U1 instance Numeric.PrimBytes.GPrimBytes f => Numeric.PrimBytes.GPrimBytes (GHC.Generics.M1 i c f) instance (Numeric.PrimBytes.GPrimBytes f, Numeric.PrimBytes.GPrimBytes g) => Numeric.PrimBytes.GPrimBytes (f GHC.Generics.:*: g) instance (Numeric.PrimBytes.GPrimBytes f, Numeric.PrimBytes.GPrimBytes g) => Numeric.PrimBytes.GPrimBytes (f GHC.Generics.:+: g) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec GHC.Types.Word) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec GHC.Types.Int) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec GHC.Types.Float) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec GHC.Types.Double) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec GHC.Types.Char) instance Numeric.PrimBytes.GPrimBytes (GHC.Generics.URec (GHC.Ptr.Ptr ())) module Numeric.DataFrame.Internal.Array.Class class PrimBytes t => PrimArray t a | a -> t -- | Broadcast element into array broadcast :: PrimArray t a => t -> a -- | Index an array given an offset ix# :: PrimArray t a => Int# -> a -> t -- | Generate an array using an accumulator funtion gen# :: PrimArray t a => Int# -> (s -> (# s, t #)) -> s -> (# s, a #) -- | update a single element in an array given an offset upd# :: PrimArray t a => Int# -> Int# -> t -> a -> a -- | Offset of an array in number of elements elemOffset :: PrimArray t a => a -> Int# -- | Number of elements in an array. Returns zero if this information is -- not available at runtime. This is possible only if all elements are -- same in an array. elemSize0 :: PrimArray t a => a -> Int# -- | Get array by its offset and size in a ByteArray. Both offset and size -- are given in element number. fromElems :: PrimArray t a => Int# -> Int# -> ByteArray# -> a -- | Index array by an integer offset (starting from 0). ixOff :: PrimArray t a => Int -> a -> t -- | Construct an array from a flat list and length unsafeFromFlatList :: PrimArray t a => Int -> [t] -> a module Numeric.DataFrame.SubSpace -- | Operations on DataFrames -- -- as is an element dimensionality -- -- bs is an indexing dimensionality -- -- t is an underlying data type (i.e. Float, Int, Double) class (ConcatList as bs asbs, Dimensions as, Dimensions bs, Dimensions asbs, PrimArray t (DataFrame t asbs)) => SubSpace (t :: Type) (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) | asbs as -> bs, asbs bs -> as, as bs -> asbs -- | Unsafely get a sub-dataframe by its primitive element offset. The -- offset is not checked to be aligned to the space structure or for -- bounds. Arguments are zero-based primitive element offset and subset -- ("as" element) size (aka totalDim of sub dataframe) -- -- Normal indexing can be expressed in terms of indexOffset#: -- --
-- i !. x = case (# dimVal (dim @as), fromEnum i #) of (# I# n, I# j #) -> indexOffset# (n *# j) n x --indexOffset# :: SubSpace t as bs asbs => Int# -> Int# -> DataFrame t asbs -> DataFrame t as -- | Set a new value to an element update :: SubSpace t as bs asbs => Idxs bs -> DataFrame t as -> DataFrame t asbs -> DataFrame t asbs -- | Map a function over each element of DataFrame ewmap :: forall s (as' :: [Nat]) (asbs' :: [Nat]). (SubSpace t as bs asbs, SubSpace s as' bs asbs') => (DataFrame s as' -> DataFrame t as) -> DataFrame s asbs' -> DataFrame t asbs -- | Map a function over each element with its index of DataFrame iwmap :: forall s (as' :: [Nat]) (asbs' :: [Nat]). (SubSpace t as bs asbs, SubSpace s as' bs asbs') => (Idxs bs -> DataFrame s as' -> DataFrame t as) -> DataFrame s asbs' -> DataFrame t asbs -- | Generate a DataFrame by repeating an element ewgen :: SubSpace t as bs asbs => DataFrame t as -> DataFrame t asbs -- | Generate a DataFrame by iterating a function (index -> element) iwgen :: SubSpace t as bs asbs => (Idxs bs -> DataFrame t as) -> DataFrame t asbs -- | Left-associative fold of a DataFrame. The fold is strict, so -- accumulater is evaluated to WHNF; but you'd better make sure that the -- function is strict enough to not produce memory leaks deeply inside -- the result data type. ewfoldl :: SubSpace t as bs asbs => (b -> DataFrame t as -> b) -> b -> DataFrame t asbs -> b -- | Left-associative fold of a DataFrame with an index The fold is strict, -- so accumulater is evaluated to WHNF; but you'd better make sure that -- the function is strict enough to not produce memory leaks deeply -- inside the result data type. iwfoldl :: SubSpace t as bs asbs => (Idxs bs -> b -> DataFrame t as -> b) -> b -> DataFrame t asbs -> b -- | Right-associative fold of a DataFrame The fold is strict, so -- accumulater is evaluated to WHNF; but you'd better make sure that the -- function is strict enough to not produce memory leaks deeply inside -- the result data type. ewfoldr :: SubSpace t as bs asbs => (DataFrame t as -> b -> b) -> b -> DataFrame t asbs -> b -- | Right-associative fold of a DataFrame with an index The fold is -- strict, so accumulater is evaluated to WHNF; but you'd better make -- sure that the function is strict enough to not produce memory leaks -- deeply inside the result data type. iwfoldr :: SubSpace t as bs asbs => (Idxs bs -> DataFrame t as -> b -> b) -> b -> DataFrame t asbs -> b -- | Apply an applicative functor on each element (Lens-like traversal) elementWise :: forall s (as' :: [Nat]) (asbs' :: [Nat]) f. (SubSpace t as bs asbs, Applicative f, SubSpace s as' bs asbs') => (DataFrame s as' -> f (DataFrame t as)) -> DataFrame s asbs' -> f (DataFrame t asbs) -- | Apply an applicative functor on each element with its index (Lens-like -- indexed traversal) indexWise :: forall s (as' :: [Nat]) (asbs' :: [Nat]) f. (SubSpace t as bs asbs, Applicative f, SubSpace s as' bs asbs') => (Idxs bs -> DataFrame s as' -> f (DataFrame t as)) -> DataFrame s asbs' -> f (DataFrame t asbs) -- | Index an element (reverse of !.) (!) :: SubSpace t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) => DataFrame t asbs -> Idxs bs -> DataFrame t as infixl 4 ! -- | Get an element by its index in the dataframe (!.) :: forall t as bs asbs. SubSpace t as bs asbs => Idxs bs -> DataFrame t asbs -> DataFrame t as infixr 4 !. -- | Apply a functor over a single element (simple lens) element :: forall t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) f. (SubSpace t as bs asbs, Applicative f) => Idxs bs -> (DataFrame t as -> f (DataFrame t as)) -> DataFrame t asbs -> f (DataFrame t asbs) ewfoldMap :: forall t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) m. (Monoid m, SubSpace t as bs asbs) => (DataFrame t as -> m) -> DataFrame t asbs -> m iwfoldMap :: forall t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) m. (Monoid m, SubSpace t as bs asbs) => (Idxs bs -> DataFrame t as -> m) -> DataFrame t asbs -> m -- | Zip two spaces on a specified subspace element-wise (without index) ewzip :: forall t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) s (as' :: [Nat]) (asbs' :: [Nat]) r (as'' :: [Nat]) (asbs'' :: [Nat]). (SubSpace t as bs asbs, SubSpace s as' bs asbs', SubSpace r as'' bs asbs'') => (DataFrame t as -> DataFrame s as' -> DataFrame r as'') -> DataFrame t asbs -> DataFrame s asbs' -> DataFrame r asbs'' -- | Zip two spaces on a specified subspace index-wise (with index) iwzip :: forall t (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) s (as' :: [Nat]) (asbs' :: [Nat]) r (as'' :: [Nat]) (asbs'' :: [Nat]). (SubSpace t as bs asbs, SubSpace s as' bs asbs', SubSpace r as'' bs asbs'') => (Idxs bs -> DataFrame t as -> DataFrame s as' -> DataFrame r as'') -> DataFrame t asbs -> DataFrame s asbs' -> DataFrame r asbs'' -- | Apply an applicative functor on each element with its index (Lens-like -- indexed traversal) indexWise_ :: forall t as bs asbs f b. (SubSpace t as bs asbs, Applicative f) => (Idxs bs -> DataFrame t as -> f b) -> DataFrame t asbs -> f () -- | Apply an applicative functor on each element (Lens-like traversal) elementWise_ :: forall t as bs asbs f b. (SubSpace t as bs asbs, Applicative f) => (DataFrame t as -> f b) -> DataFrame t asbs -> f () instance (Numeric.Type.List.ConcatList as bs asbs, Numeric.Dimensions.Dims.Dimensions as, Numeric.Dimensions.Dims.Dimensions bs, Numeric.Dimensions.Dims.Dimensions asbs, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Family.DataFrame t as), Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Family.DataFrame t asbs), Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Family.DataFrame t as), Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Family.DataFrame t asbs)) => Numeric.DataFrame.SubSpace.SubSpace t as bs asbs module Numeric.DataFrame.Internal.Array.Family.ScalarBase -- | Specialize ScalarBase type without any arrays newtype ScalarBase t ScalarBase :: t -> ScalarBase t [_unScalarBase] :: ScalarBase t -> t instance Numeric.PrimBytes.PrimBytes t => Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Float.RealFloat t => GHC.Float.RealFloat (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Real.RealFrac t => GHC.Real.RealFrac (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Real.Real t => GHC.Real.Real (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Read.Read t => GHC.Read.Read (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Classes.Ord t => GHC.Classes.Ord (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Float.Floating t => GHC.Float.Floating (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Real.Fractional t => GHC.Real.Fractional (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Num.Num t => GHC.Num.Num (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Real.Integral t => GHC.Real.Integral (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Classes.Eq t => GHC.Classes.Eq (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Enum.Enum t => GHC.Enum.Enum (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Enum.Bounded t => GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Show.Show t => GHC.Show.Show (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase GHC.Types.Double) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase GHC.Types.Float) instance Numeric.PrimBytes.PrimBytes t => Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Internal.Array.Family.ScalarBase.ScalarBase t) module Numeric.DataFrame.Internal.Array.Family.FloatX4 data FloatX4 FloatX4# :: Float# -> Float# -> Float# -> Float# -> FloatX4 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Float Numeric.DataFrame.Internal.Array.Family.FloatX4.FloatX4 module Numeric.DataFrame.Internal.Array.Family.FloatX3 data FloatX3 FloatX3# :: Float# -> Float# -> Float# -> FloatX3 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Float Numeric.DataFrame.Internal.Array.Family.FloatX3.FloatX3 module Numeric.DataFrame.Internal.Array.Family.FloatX2 data FloatX2 FloatX2# :: Float# -> Float# -> FloatX2 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Float Numeric.DataFrame.Internal.Array.Family.FloatX2.FloatX2 module Numeric.DataFrame.Internal.Array.Family.DoubleX4 data DoubleX4 DoubleX4# :: Double# -> Double# -> Double# -> Double# -> DoubleX4 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Double Numeric.DataFrame.Internal.Array.Family.DoubleX4.DoubleX4 module Numeric.DataFrame.Internal.Array.Family.DoubleX3 data DoubleX3 DoubleX3# :: Double# -> Double# -> Double# -> DoubleX3 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Double Numeric.DataFrame.Internal.Array.Family.DoubleX3.DoubleX3 module Numeric.DataFrame.Internal.Array.Family.DoubleX2 data DoubleX2 DoubleX2# :: Double# -> Double# -> DoubleX2 instance GHC.Enum.Bounded Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Show.Show Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Classes.Eq Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Classes.Ord Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Num.Num Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Real.Fractional Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance GHC.Float.Floating Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance Numeric.PrimBytes.PrimBytes Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 instance Numeric.DataFrame.Internal.Array.Class.PrimArray GHC.Types.Double Numeric.DataFrame.Internal.Array.Family.DoubleX2.DoubleX2 module Numeric.DataFrame.Internal.Array.Family.ArrayBase -- | Generic Array implementation. This array can reside in plain -- ByteArray# and can share the ByteArray# with other -- arrays. However, byte offset in the ByteArray# must be -- multiple of the element size. data ArrayBase (t :: Type) (ds :: [Nat]) ArrayBase :: (# t | (# Int#, Int#, ByteArray# #) #) -> ArrayBase instance (Numeric.PrimBytes.PrimBytes t, Numeric.Dimensions.Dims.Dimensions ds) => Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (GHC.Classes.Eq t, Numeric.PrimBytes.PrimBytes t) => GHC.Classes.Eq (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (GHC.Classes.Ord t, Numeric.PrimBytes.PrimBytes t) => GHC.Classes.Ord (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (Numeric.Dimensions.Dims.Dimensions ds, Numeric.PrimBytes.PrimBytes t, GHC.Show.Show t) => GHC.Show.Show (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase GHC.Types.Double ds) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase GHC.Types.Float ds) instance GHC.Enum.Bounded t => GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (GHC.Num.Num t, Numeric.PrimBytes.PrimBytes t) => GHC.Num.Num (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (GHC.Real.Fractional t, Numeric.PrimBytes.PrimBytes t) => GHC.Real.Fractional (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance (GHC.Float.Floating t, Numeric.PrimBytes.PrimBytes t) => GHC.Float.Floating (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) instance Numeric.PrimBytes.PrimBytes t => Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds) module Numeric.DataFrame.Internal.Array.Family -- | This type family aggregates all types used for arrays with different -- dimensioinality. The family is injective; thus, it is possible to get -- type family instance given the data constructor (and vice versa). If -- GHC knows the dimensionality of an array at compile time, it chooses a -- more efficient specialized instance of Array, e.g. Scalar newtype -- wrapper. Otherwise, it falls back to the generic ArrayBase -- implementation. -- -- Data family would not work here, because it would give overlapping -- instances. -- | Specialize ScalarBase type without any arrays newtype ScalarBase t ScalarBase :: t -> ScalarBase t [_unScalarBase] :: ScalarBase t -> t -- | Generic Array implementation. This array can reside in plain -- ByteArray# and can share the ByteArray# with other -- arrays. However, byte offset in the ByteArray# must be -- multiple of the element size. data ArrayBase (t :: Type) (ds :: [Nat]) ArrayBase :: (# t | (# Int#, Int#, ByteArray# #) #) -> ArrayBase -- | A framework for using Array type family instances. class ArraySingleton (t :: Type) (ds :: [Nat]) -- | Get Array type family instance aSing :: ArraySingleton t ds => ArraySing t ds data ArraySing t (ds :: [Nat]) [AScalar] :: (Array t ds ~ ScalarBase t) => ArraySing t '[] [AF2] :: (Array t ds ~ FloatX2) => ArraySing Float '[2] [AF3] :: (Array t ds ~ FloatX3) => ArraySing Float '[3] [AF4] :: (Array t ds ~ FloatX4) => ArraySing Float '[4] [AD2] :: (Array t ds ~ DoubleX2) => ArraySing Double '[2] [AD3] :: (Array t ds ~ DoubleX3) => ArraySing Double '[3] [AD4] :: (Array t ds ~ DoubleX4) => ArraySing Double '[4] [ABase] :: (Array t ds ~ ArrayBase t ds, PrimBytes t) => ArraySing t ds -- | Use ArraySing GADT to construct an ArraySingleton -- dictionary. In other words, bring an evidence of ArraySingleton -- instance into a scope at runtime. aSingEv :: ArraySing t ds -> Evidence (ArraySingleton t ds) -- | Use ArraySing GADT to construct an ArraySingleton -- dictionary. The same as aSingEv, but relies on PrimBytes -- and Dimensions. inferASing :: forall t ds. (PrimBytes t, Dimensions ds) => Evidence (ArraySingleton t ds) -- | This is a special function, because Scalar does not require PrimBytes. -- That is why the dimension list in the argument is not empty. inferPrimElem :: forall t d ds. ArraySingleton t (d : ds) => Evidence (PrimBytes t) inferPrim :: forall t ds. (PrimBytes t, ArraySingleton t ds, Dimensions ds) => Evidence (PrimBytes (Array t ds), PrimArray t (Array t ds)) inferEq :: forall t ds. (Eq t, ArraySingleton t ds) => Evidence (Eq (Array t ds)) inferShow :: forall t ds. (Show t, Dimensions ds, ArraySingleton t ds) => Evidence (Show (Array t ds)) inferOrd :: forall t ds. (Ord t, ArraySingleton t ds) => Evidence (Ord (Array t ds)) inferNum :: forall t ds. (Num t, ArraySingleton t ds) => Evidence (Num (Array t ds)) inferFractional :: forall t ds. (Fractional t, ArraySingleton t ds) => Evidence (Fractional (Array t ds)) inferFloating :: forall t ds. (Floating t, ArraySingleton t ds) => Evidence (Floating (Array t ds)) instance GHC.Classes.Eq (Numeric.DataFrame.Internal.Array.Family.ArraySing t ds) instance GHC.Classes.Ord (Numeric.DataFrame.Internal.Array.Family.ArraySing t ds) instance GHC.Show.Show (Numeric.DataFrame.Internal.Array.Family.ArraySing t ds) instance (Numeric.DataFrame.Internal.Array.Family.Array t ds ~ Numeric.DataFrame.Internal.Array.Family.ArrayBase.ArrayBase t ds, Numeric.PrimBytes.PrimBytes t) => Numeric.DataFrame.Internal.Array.Family.ArraySingleton t ds instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton t '[] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Float '[2] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Float '[3] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Float '[4] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Double '[2] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Double '[3] instance Numeric.DataFrame.Internal.Array.Family.ArraySingleton GHC.Types.Double '[4] module Numeric.DataFrame.Type -- | Keep data in a primitive data frame and maintain information about -- Dimensions in the type system -- | 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) -- | Constructing a MultiFrame using DataFrame columns infixr 6 :*: -- | Empty MultiFrame class DataFrameInference (t :: l) -- | Bring an evidence of ArraySingleton instance into a scope at -- runtime. This is often used to let GHC infer other complex type class -- instances, such as SubSpace. inferASing :: (DataFrameInference t, AllTypes PrimBytes t, Dimensions ds) => DataFrame t ds -> Evidence (ArraySingletons t ds) inferEq :: (DataFrameInference t, AllTypes Eq t, ArraySingletons t ds) => DataFrame t ds -> Evidence (Eq (DataFrame t ds)) inferShow :: (DataFrameInference t, AllTypes Show t, ArraySingletons t ds, Dimensions ds) => DataFrame t ds -> Evidence (Show (DataFrame t ds)) inferPrim :: (DataFrameInference t, AllTypes PrimBytes t, ArraySingletons t ds, Dimensions ds) => DataFrame t ds -> Evidence (PrimFrames t ds) -- | This is a special function, because Scalar does not require PrimBytes. -- That is why the dimension list in the argument nust not be empty. inferPrimElem :: (DataFrameInference t, ArraySingletons t ds, ds ~ (Head ds : Tail ds)) => DataFrame t ds -> Evidence (AllTypes PrimBytes t) inferOrd :: forall t ds. (Ord t, ArraySingleton t ds) => DataFrame t ds -> Evidence (Ord (DataFrame t ds)) inferNum :: forall t ds. (Num t, ArraySingletons t ds) => DataFrame t ds -> Evidence (Num (DataFrame t ds)) inferFractional :: forall t ds. (Fractional t, ArraySingleton t ds) => DataFrame t ds -> Evidence (Fractional (DataFrame t ds)) inferFloating :: forall t ds. (Floating t, ArraySingleton t ds) => DataFrame t ds -> Evidence (Floating (DataFrame t ds)) inferOrd' :: forall t ds. (Ord t, ArraySingleton t ds) => Evidence (Ord (DataFrame t ds)) inferNum' :: forall t ds. (Num t, ArraySingletons t ds) => Evidence (Num (DataFrame t ds)) inferFractional' :: forall t ds. (Fractional t, ArraySingleton t ds) => Evidence (Fractional (DataFrame t ds)) inferFloating' :: forall t ds. (Floating t, ArraySingleton t ds) => Evidence (Floating (DataFrame t ds)) inferASing' :: forall t ds. (DataFrameInference t, AllTypes PrimBytes t, Dimensions ds) => Evidence (ArraySingletons t ds) inferEq' :: forall t ds. (DataFrameInference t, AllTypes Eq t, ArraySingletons t ds) => Evidence (Eq (DataFrame t ds)) inferShow' :: forall t ds. (DataFrameInference t, AllTypes Show t, ArraySingletons t ds, Dimensions ds) => Evidence (Show (DataFrame t ds)) inferPrim' :: forall t ds. (DataFrameInference t, AllTypes PrimBytes t, ArraySingletons t ds, Dimensions ds) => Evidence (PrimFrames t ds) inferPrimElem' :: forall t ds. (DataFrameInference t, ArraySingletons t ds, ds ~ (Head ds : Tail ds)) => Evidence (AllTypes PrimBytes t) -- | Index array by an integer offset (starting from 0). ixOff :: PrimArray t a => Int -> a -> t -- | Construct an array from a flat list and length unsafeFromFlatList :: PrimArray t a => Int -> [t] -> a class Dim1 (t :: [k] -> Type) (ds :: [k]) dim1 :: Dim1 t ds => t ds -> Dim (Head ds) class Dim2 (t :: [k] -> Type) (ds :: [k]) dim2 :: Dim2 t ds => t ds -> Dim (Head (Tail ds)) class Dim3 (t :: [k] -> Type) (ds :: [k]) dim3 :: Dim3 t ds => t ds -> Dim (Head (Tail (Tail ds))) -- | Number of elements along the 1st dimension. dimSize1 :: Dim1 t ds => t ds -> Word -- | Number of elements along the 2nd dimension. dimSize2 :: Dim2 t ds => t ds -> Word -- | Number of elements along the 3rd dimension. dimSize3 :: Dim3 t ds => t ds -> Word -- | A wrapper on byteSize bSizeOf :: PrimBytes a => a -> Int -- | A wrapper on byteAlign bAlignOf :: PrimBytes a => a -> Int -- | 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 -> * -- | This type is used to index a single dimension; the range of indices is -- from 1 to n. -- -- Note, this type has a weird Enum instance: -- --
-- >>> fromEnum (Idx 7) -- 6 ---- -- The logic behind this is that the Enum class is used to -- transform indices to offsets. That is, element of an array at index -- k :: Idx n is the element taken by an offset `k - 1 :: Int`. newtype Idx (n :: k) :: forall k. () => k -> * Idx :: Word -> Idx [unIdx] :: Idx -> Word -- | Either known or unknown at compile-time natural number data XNat XN :: Nat -> XNat N :: Nat -> XNat -- | Type-level dimensionality O(1). type Dims (xs :: [k]) = TypedList (Dim :: k -> *) xs -- | Type-level dimensional indexing with arbitrary Word values inside. -- Most of the operations on it require Dimensions constraint, -- because the Idxs itself does not store info about dimension -- bounds. -- -- Note, this type has a special Enum instance: fromEnum -- gives an offset of the index in a flat 1D array; this is in line with -- a weird Enum instance of Idx type. type Idxs (xs :: [k]) = TypedList (Idx :: k -> *) xs -- | Type-indexed list data TypedList (f :: k -> Type) (xs :: [k]) :: forall k. () => k -> Type -> [k] -> * instance GHC.Classes.Eq (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Classes.Eq (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Enum.Bounded (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Enum.Bounded (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Enum.Enum (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Enum.Enum (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Real.Integral (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Real.Integral (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Num.Num (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Num.Num (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Real.Fractional (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Real.Fractional (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Float.Floating (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Float.Floating (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Classes.Ord (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Classes.Ord (Numeric.DataFrame.Family.DataFrame t ds) instance (GHC.Read.Read (Numeric.DataFrame.Internal.Array.Family.Array t ds), Numeric.Dimensions.Dims.Dimensions ds) => GHC.Read.Read (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Real.Real (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Real.Real (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Real.RealFrac (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Real.RealFrac (Numeric.DataFrame.Family.DataFrame t ds) instance GHC.Float.RealFloat (Numeric.DataFrame.Internal.Array.Family.Array t ds) => GHC.Float.RealFloat (Numeric.DataFrame.Family.DataFrame t ds) instance (Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Internal.Array.Family.Array t ds), Numeric.PrimBytes.PrimBytes t) => Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.DataFrame.Family.DataFrame t ds) instance Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Internal.Array.Family.Array t ds) => Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Family.DataFrame t ds) instance forall k (d1 :: k) (d2 :: k) (d3 :: k) (ds :: [k]) (t :: [k] -> *). Numeric.Dimensions.Dims.Dimensions (d1 : d2 : d3 : ds) => Numeric.DataFrame.Type.Dim3 t (d1 : d2 : d3 : ds) instance forall k (d1 :: k) (d2 :: k) (d3 :: k) (ds :: [k]). Numeric.DataFrame.Type.Dim3 (Numeric.TypedList.TypedList Numeric.Dim.Dim) (d1 : d2 : d3 : ds) instance forall l1 (l2 :: l1) (d1 :: Numeric.Dim.XNat) (d2 :: Numeric.Dim.XNat) (d3 :: Numeric.Dim.XNat) (ds :: [Numeric.Dim.XNat]). Numeric.DataFrame.Type.Dim3 (Numeric.DataFrame.Family.DataFrame l2) (d1 : d2 : d3 : ds) instance forall k (d1 :: k) (d2 :: k) (ds :: [k]) (t :: [k] -> *). Numeric.Dimensions.Dims.Dimensions (d1 : d2 : ds) => Numeric.DataFrame.Type.Dim2 t (d1 : d2 : ds) instance forall k (d1 :: k) (d2 :: k) (ds :: [k]). Numeric.DataFrame.Type.Dim2 (Numeric.TypedList.TypedList Numeric.Dim.Dim) (d1 : d2 : ds) instance forall l1 (l2 :: l1) (d1 :: Numeric.Dim.XNat) (d2 :: Numeric.Dim.XNat) (ds :: [Numeric.Dim.XNat]). Numeric.DataFrame.Type.Dim2 (Numeric.DataFrame.Family.DataFrame l2) (d1 : d2 : ds) instance forall k (d :: k) (ds :: [k]) (t :: [k] -> *). Numeric.Dimensions.Dims.Dimensions (d : ds) => Numeric.DataFrame.Type.Dim1 t (d : ds) instance forall k (d :: k) (ds :: [k]). Numeric.DataFrame.Type.Dim1 (Numeric.TypedList.TypedList Numeric.Dim.Dim) (d : ds) instance forall l1 (l2 :: l1) (d :: Numeric.Dim.XNat) (ds :: [Numeric.Dim.XNat]). Numeric.DataFrame.Type.Dim1 (Numeric.DataFrame.Family.DataFrame l2) (d : ds) instance forall l (t :: l) (ds :: [Numeric.Dim.XNat]). (Numeric.DataFrame.Type.AllTypes GHC.Classes.Eq t, Numeric.DataFrame.Type.DataFrameInference t) => GHC.Classes.Eq (Numeric.DataFrame.Family.DataFrame t ds) instance forall l (t :: l). (Numeric.DataFrame.Type.AllTypes GHC.Classes.Eq t, Numeric.DataFrame.Type.DataFrameInference t) => GHC.Classes.Eq (Numeric.DataFrame.Type.SomeDataFrame t) instance forall l (t :: l) (xns :: [Numeric.Dim.XNat]). (Numeric.DataFrame.Type.AllTypes GHC.Show.Show t, Numeric.DataFrame.Type.DataFrameInference t) => GHC.Show.Show (Numeric.DataFrame.Family.DataFrame t xns) instance forall l (t :: l). (Numeric.DataFrame.Type.AllTypes GHC.Show.Show t, Numeric.DataFrame.Type.DataFrameInference t) => GHC.Show.Show (Numeric.DataFrame.Type.SomeDataFrame t) instance Numeric.DataFrame.Type.DataFrameInference t instance Numeric.TypedList.RepresentableList ts => Numeric.DataFrame.Type.DataFrameInference ts instance Numeric.DataFrame.Type.ImplAllows GHC.Classes.Eq ts ds => GHC.Classes.Eq (Numeric.DataFrame.Family.DataFrame ts ds) instance (Numeric.Dimensions.Dims.Dimensions ds, Numeric.DataFrame.Type.ImplAllows GHC.Show.Show ts ds) => GHC.Show.Show (Numeric.DataFrame.Family.DataFrame ts ds) instance (GHC.Show.Show (Numeric.DataFrame.Internal.Array.Family.Array t ds), Numeric.Dimensions.Dims.Dimensions ds) => GHC.Show.Show (Numeric.DataFrame.Family.DataFrame t ds) instance forall k l (t :: l) (ds :: [k]). Numeric.PrimBytes.PrimBytes (Numeric.DataFrame.Family.DataFrame t ds) => Foreign.Storable.Storable (Numeric.DataFrame.Family.DataFrame t ds) -- | Interfrace 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 :: [Nat]) -- | Create a new mutable DataFrame. newDataFrame# :: forall t (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => State# s -> (# State# s, MDataFrame s t ns #) -- | Create a new mutable DataFrame. newPinnedDataFrame# :: forall t (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => State# s -> (# State# s, MDataFrame s t ns #) -- | Copy one DataFrame into another mutable DataFrame at specified -- position. copyDataFrame# :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]) s. (PrimBytes t, PrimBytes (DataFrame t (as +: b')), ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => DataFrame t (as +: b') -> Idxs (b :+ bs) -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. copyMDataFrame# :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]) s. (PrimBytes t, ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => MDataFrame s t (as +: b') -> Idxs (b :+ bs) -> MDataFrame s t asbs -> State# s -> (# State# s, () #) -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame# :: forall (t :: Type) (ns :: [Nat]) 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) (ns :: [Nat]) 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) (ns :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => 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) (ns :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | UnsafeCoerces an underlying byte array. unsafeThawDataFrame# :: forall (t :: Type) (ns :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> State# s -> (# State# s, MDataFrame s t ns #) -- | Write a single element at the specified index writeDataFrame# :: forall (t :: Type) (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => MDataFrame s t ns -> Idxs ns -> t -> State# s -> (# State# s, () #) -- | Write a single element at the specified element offset writeDataFrameOff# :: forall (t :: Type) (ns :: [Nat]) s. PrimBytes t => MDataFrame s t ns -> Int# -> t -> State# s -> (# State# s, () #) -- | Read a single element at the specified index readDataFrame# :: forall (t :: Type) (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => MDataFrame s t ns -> Idxs ns -> State# s -> (# State# s, t #) -- | Read a single element at the specified element offset readDataFrameOff# :: forall (t :: Type) (ns :: [Nat]) s. PrimBytes t => MDataFrame s t ns -> Int# -> State# s -> (# State# s, t #) -- | 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) (ns :: [Nat]) (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) (ns :: [Nat]) s. MDataFrame s t ns -> Bool -- | Mutable DataFrames living in ST. module Numeric.DataFrame.ST -- | Mutable DataFrame that lives in ST. Internal representation is always -- a MutableByteArray. -- | Mutable DataFrame of unknown dimensionality data SomeSTDataFrame s (t :: Type) SomeSTDataFrame :: (STDataFrame s t ns) -> SomeSTDataFrame s -- | Create a new mutable DataFrame. newDataFrame :: forall t (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => ST s (STDataFrame s t ns) -- | Create a new mutable DataFrame. newPinnedDataFrame :: forall t (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => ST s (STDataFrame s t ns) -- | Copy one DataFrame into another mutable DataFrame at specified -- position. copyDataFrame :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]) s. (PrimBytes t, PrimBytes (DataFrame t (as +: b')), ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => DataFrame t (as +: b') -> Idxs (b :+ bs) -> STDataFrame s t asbs -> ST s () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. copyMutableDataFrame :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]) s. (PrimBytes t, ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => STDataFrame s t (as +: b') -> Idxs (b :+ bs) -> STDataFrame s t asbs -> ST s () -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame :: forall (t :: Type) (ns :: [Nat]) 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 :: [Nat]) 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 :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => 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 :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | UnsafeCoerces an underlying byte array. unsafeThawDataFrame :: forall (t :: Type) (ns :: [Nat]) s. (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | Write a single element at the specified index writeDataFrame :: forall t (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => STDataFrame s t ns -> Idxs ns -> DataFrame t ('[] :: [Nat]) -> ST s () -- | Write a single element at the specified element offset writeDataFrameOff :: forall (t :: Type) (ns :: [Nat]) s. PrimBytes t => STDataFrame s t ns -> Int -> DataFrame t ('[] :: [Nat]) -> ST s () -- | Read a single element at the specified index readDataFrame :: forall (t :: Type) (ns :: [Nat]) s. (PrimBytes t, Dimensions ns) => STDataFrame s t ns -> Idxs ns -> ST s (DataFrame t ('[] :: [Nat])) -- | Read a single element at the specified element offset readDataFrameOff :: forall (t :: Type) (ns :: [Nat]) s. PrimBytes t => STDataFrame s t ns -> Int -> ST s (DataFrame t ('[] :: [Nat])) -- | Check if the byte array wrapped by this DataFrame is pinned, which -- means cannot be relocated by GC. isDataFramePinned :: forall (t :: Type) (ns :: [k]) s. KnownDimKind k => STDataFrame s t ns -> Bool -- | Low-level implementations of data frames module Numeric.DataFrame.Internal.Array -- | This modules provides generalization of a matrix product: tensor-like -- contraction. For matrices and vectors this is a normal matrix*matrix -- or vector*matrix or matrix*vector product, for larger dimensions it -- calculates the scalar product of "adjacent" dimesnions of a tensor. module Numeric.DataFrame.Contraction class ConcatList as bs asbs => Contraction (t :: Type) (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) | asbs as -> bs, asbs bs -> as, as bs -> asbs -- | Generalization of a matrix product: take scalar product over one -- dimension and, thus, concatenate other dimesnions contract :: (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 -- | Tensor contraction. In particular: 1. matrix-matrix product 2. -- matrix-vector or vector-matrix product 3. dot product of two vectors. (%*) :: (ConcatList as bs (as ++ bs), Contraction t as bs asbs, KnownDim m, PrimArray t (DataFrame t (as +: m)), PrimArray t (DataFrame t (m :+ bs)), PrimArray t (DataFrame t (as ++ bs))) => DataFrame t (as +: m) -> DataFrame t (m :+ bs) -> DataFrame t (as ++ bs) infixl 7 %* instance (Numeric.Type.List.ConcatList as bs asbs, Numeric.Dimensions.Dims.Dimensions as, Numeric.Dimensions.Dims.Dimensions bs, GHC.Num.Num t) => Numeric.DataFrame.Contraction.Contraction t as bs asbs -- | Mutable DataFrames living in IO. module Numeric.DataFrame.IO -- | Mutable DataFrame that lives in IO. Internal representation is always -- a MutableByteArray. -- | Mutable DataFrame of unknown dimensionality data SomeIODataFrame (t :: Type) SomeIODataFrame :: (IODataFrame t ns) -> SomeIODataFrame -- | Create a new mutable DataFrame. newDataFrame :: forall t (ns :: [Nat]). (PrimBytes t, Dimensions ns) => IO (IODataFrame t ns) -- | Create a new mutable DataFrame. newPinnedDataFrame :: forall t (ns :: [Nat]). (PrimBytes t, Dimensions ns) => IO (IODataFrame t ns) -- | Copy one DataFrame into another mutable DataFrame at specified -- position. copyDataFrame :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]). (PrimBytes t, PrimBytes (DataFrame t (as +: b')), ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => DataFrame t (as +: b') -> Idxs (b :+ bs) -> IODataFrame t asbs -> IO () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. copyMutableDataFrame :: forall (t :: Type) (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]). (PrimBytes t, ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => IODataFrame t (as +: b') -> Idxs (b :+ bs) -> IODataFrame t asbs -> IO () -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame :: forall (t :: Type) (ns :: [Nat]). PrimArray t (DataFrame t ns) => IODataFrame t ns -> IO (DataFrame t ns) -- | Make a mutable DataFrame immutable, without copying. unsafeFreezeDataFrame :: forall (t :: Type) (ns :: [Nat]). PrimArray t (DataFrame t ns) => IODataFrame t ns -> IO (DataFrame t ns) -- | Create a new mutable DataFrame and copy content of immutable one in -- there. thawDataFrame :: forall (t :: Type) (ns :: [Nat]). (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> IO (IODataFrame 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 :: [Nat]). (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> IO (IODataFrame t ns) -- | UnsafeCoerces an underlying byte array. unsafeThawDataFrame :: forall (t :: Type) (ns :: [Nat]). (PrimBytes (DataFrame t ns), PrimBytes t) => DataFrame t ns -> IO (IODataFrame t ns) -- | Write a single element at the specified index writeDataFrame :: forall t (ns :: [Nat]). (PrimBytes t, Dimensions ns) => IODataFrame t ns -> Idxs ns -> DataFrame t ('[] :: [Nat]) -> IO () -- | Write a single element at the specified element offset writeDataFrameOff :: forall (t :: Type) (ns :: [Nat]). PrimBytes t => IODataFrame t ns -> Int -> DataFrame t ('[] :: [Nat]) -> IO () -- | Read a single element at the specified index readDataFrame :: forall (t :: Type) (ns :: [Nat]). (PrimBytes t, Dimensions ns) => IODataFrame t ns -> Idxs ns -> IO (DataFrame t ('[] :: [Nat])) -- | Read a single element at the specified element offset readDataFrameOff :: forall (t :: Type) (ns :: [Nat]). PrimBytes t => IODataFrame t ns -> Int -> IO (DataFrame t ('[] :: [Nat])) -- | Allow arbitrary IO operations on a pointer to the beginning of the -- data keeping the data from garbage collecting until the arg function -- returns. -- -- Warning: do not let Ptr t leave the scope of the arg -- function, the data may be garbage-collected by then. -- -- Warning: use this function on a pinned DataFrame only; otherwise, the -- data may be relocated before the arg fun finishes. withDataFramePtr :: forall (t :: Type) (ns :: [k]) (r :: Type). (PrimBytes t, KnownDimKind k) => IODataFrame t ns -> (Ptr t -> IO r) -> IO r -- | Check if the byte array wrapped by this DataFrame is pinned, which -- means cannot be relocated by GC. isDataFramePinned :: forall (t :: Type) (ns :: [k]). KnownDimKind k => IODataFrame t ns -> Bool -- | Scalar is an alias to zero-dimensional DataFrame module Numeric.Scalar -- | Alias for zero-dimensional DataFrame type Scalar t = DataFrame t ('[] :: [Nat]) -- | Convert scalar back to ordinary type unScalar :: Scalar t -> t -- | Convert any type to scalar wrapper scalar :: t -> Scalar t -- | Broadcast scalar value onto a whole data frame fromScalar :: SubSpace t '[] ds ds => Scalar t -> DataFrame t ds type Scf = Scalar Float type Scd = Scalar Double type Sci = Scalar Int type Scw = Scalar Word -- | Re-export most of Data.Semigroup with a few changes and new -- definitions. -- -- The main initiative behind this module is to provide more strict -- alternatives to widely used semigroups. For example, Option has -- lazy (<>) implementation, which causes memory leaks in -- large foldMaps. module Numeric.Semigroup -- | The class of semigroups (types with an associative binary operation). -- -- Instances should satisfy the associativity law: -- -- class Semigroup a -- | An associative operation. (<>) :: Semigroup a => a -> a -> a -- | Reduce a non-empty list with <> -- -- The default definition should be sufficient, but this can be -- overridden for efficiency. sconcat :: Semigroup a => NonEmpty a -> a -- | Repeat a value n times. -- -- Given that this works on a Semigroup it is allowed to fail if -- you request 0 or fewer repetitions, and the default definition will do -- so. -- -- By making this a member of the class, idempotent semigroups and -- monoids can upgrade this to execute in O(1) by picking -- stimes = stimesIdempotent or stimes = -- stimesIdempotentMonoid respectively. stimes :: (Semigroup a, Integral b) => b -> a -> a -- | This is a valid definition of stimes for a Monoid. -- -- Unlike the default definition of stimes, it is defined for 0 -- and so it should be preferred where possible. stimesMonoid :: (Integral b, Monoid a) => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Semigroup. -- -- When x <> x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n). stimesIdempotent :: Integral b => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Monoid. -- -- When mappend x x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n) stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a -- | Repeat a value n times. -- --
-- mtimesDefault n a = a <> a <> ... <> a -- using <> (n-1) times ---- -- Implemented using stimes and mempty. -- -- This is a suitable definition for an mtimes member of -- Monoid. mtimesDefault :: (Integral b, Monoid a) => b -> a -> a -- | Map each element of the structure to a monoid, and combine the -- results. -- -- This function differs from Data.Foldable.foldMap in that uses -- foldl' instead of foldr inside. This makes this -- function suitable for Monoids with strict mappend operation. -- For example, -- --
-- foldMap' Sum $ take 1000000000 ([1..] :: [Int]) ---- -- runs in constant memory, whereas normal foldMap would cause a -- memory leak there. foldMap' :: (Foldable t, Monoid m) => (a -> m) -> t a -> m newtype Min a Min :: a -> Min a [getMin] :: Min a -> a newtype Max a Max :: a -> Max a [getMax] :: Max a -> a -- | Use Option (First a) to get the behavior of -- First from Data.Monoid. newtype First a First :: a -> First a [getFirst] :: First a -> a -- | Use Option (Last a) to get the behavior of -- Last from Data.Monoid newtype Last a Last :: a -> Last a [getLast] :: Last a -> a -- | Provide a Semigroup for an arbitrary Monoid. -- -- NOTE: This is not needed anymore since Semigroup became -- a superclass of Monoid in base-4.11 and this newtype be -- deprecated at some point in the future. newtype WrappedMonoid m WrapMonoid :: m -> WrappedMonoid m [unwrapMonoid] :: WrappedMonoid m -> m -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- --
x <> mempty = x
mempty <> x = x
mconcat = foldr '(<>)' -- mempty
-- >>> getDual (mappend (Dual "Hello") (Dual "World")) -- "WorldHello" --newtype Dual a Dual :: a -> Dual a [getDual] :: Dual a -> a -- | The monoid of endomorphisms under composition. -- --
-- >>> let computation = Endo ("Hello, " ++) <> Endo (++ "!")
--
-- >>> appEndo computation "Haskell"
-- "Hello, Haskell!"
--
newtype Endo a
Endo :: a -> a -> Endo a
[appEndo] :: Endo a -> a -> a
-- | Boolean monoid under conjunction (&&).
--
-- -- >>> getAll (All True <> mempty <> All False) -- False ---- --
-- >>> getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8])) -- False --newtype All All :: Bool -> All [getAll] :: All -> Bool -- | Boolean monoid under disjunction (||). -- --
-- >>> getAny (Any True <> mempty <> Any False) -- True ---- --
-- >>> getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8])) -- True --newtype Any Any :: Bool -> Any [getAny] :: Any -> Bool -- | Monoid under addition. -- --
-- >>> getSum (Sum 1 <> Sum 2 <> mempty) -- 3 --newtype Sum a Sum :: a -> Sum a [getSum] :: Sum a -> a -- | Monoid under multiplication. -- --
-- >>> getProduct (Product 3 <> Product 4 <> mempty) -- 12 --newtype Product a Product :: a -> Product a [getProduct] :: Product a -> a -- | Option is effectively Maybe with a better instance of -- Monoid, built off of an underlying Semigroup instead of -- an underlying Monoid. -- -- This version of Option data type is more strict than the one -- from Data.Semigroup. newtype Option a Option :: Maybe a -> Option a [getOption] :: Option a -> Maybe a -- | Fold an Option case-wise, just like maybe. Eagerly -- evaluates the value before returning! option :: b -> (a -> b) -> Option a -> b -- | Get value from Option with default value. Eagerly evaluates the -- value before returning! fromOption :: a -> Option a -> a -- | Wrap a value into Option container. Eagerly evaluates the value -- before wrapping! toOption :: a -> Option a -- | This lets you use a difference list of a Semigroup as a -- Monoid. diff :: Semigroup m => m -> Endo m -- | A generalization of cycle to an arbitrary Semigroup. May -- fail to terminate for some values in some semigroups. cycle1 :: Semigroup m => m -> m -- | Arg isn't itself a Semigroup in its own right, but it -- can be placed inside Min and Max to compute an arg min -- or arg max. data Arg a b Arg :: a -> b -> Arg a b type ArgMin a b = Min Arg a b type ArgMax a b = Max Arg a b -- | Evaluate minimum and maximum at the same time. Arithmetics and -- semigroup operations are eager, functorial operations are lazy. -- -- This data type is especially useful for calculating bounds of foldable -- containers with numeric data using foldMap minMax. data MinMax a MinMax :: a -> a -> MinMax a minMax :: a -> MinMax a mmDiff :: Num a => MinMax a -> a mmAvg :: Fractional a => MinMax a -> a instance GHC.Generics.Generic1 Numeric.Semigroup.MinMax instance GHC.Generics.Generic (Numeric.Semigroup.MinMax a) instance Data.Data.Data a => Data.Data.Data (Numeric.Semigroup.MinMax a) instance GHC.Show.Show a => GHC.Show.Show (Numeric.Semigroup.MinMax a) instance GHC.Read.Read a => GHC.Read.Read (Numeric.Semigroup.MinMax a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.Semigroup.MinMax a) instance Control.Monad.Fix.MonadFix Numeric.Semigroup.Option instance GHC.Base.Monad Numeric.Semigroup.Option instance GHC.Base.Applicative Numeric.Semigroup.Option instance GHC.Base.Alternative Numeric.Semigroup.Option instance GHC.Base.Functor Numeric.Semigroup.Option instance GHC.Generics.Generic1 Numeric.Semigroup.Option instance GHC.Generics.Generic (Numeric.Semigroup.Option a) instance Data.Data.Data a => Data.Data.Data (Numeric.Semigroup.Option a) instance GHC.Read.Read a => GHC.Read.Read (Numeric.Semigroup.Option a) instance GHC.Show.Show a => GHC.Show.Show (Numeric.Semigroup.Option a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Numeric.Semigroup.Option a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.Semigroup.Option a) instance GHC.Classes.Ord a => GHC.Base.Semigroup (Numeric.Semigroup.MinMax a) instance (GHC.Classes.Ord a, GHC.Enum.Bounded a) => GHC.Base.Monoid (Numeric.Semigroup.MinMax a) instance GHC.Base.Functor Numeric.Semigroup.MinMax instance GHC.Base.Applicative Numeric.Semigroup.MinMax instance GHC.Base.Monad Numeric.Semigroup.MinMax instance Control.Monad.Fix.MonadFix Numeric.Semigroup.MinMax instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Numeric.Semigroup.MinMax a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Numeric.Semigroup.MinMax a) instance (GHC.Num.Num a, GHC.Classes.Ord a) => GHC.Num.Num (Numeric.Semigroup.MinMax a) instance Data.Foldable.Foldable Numeric.Semigroup.Option instance Data.Traversable.Traversable Numeric.Semigroup.Option instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.Semigroup.Option a) instance GHC.Base.Semigroup a => GHC.Base.Monoid (Numeric.Semigroup.Option a) -- | Vector is an alias to a DataFrame with order 1. module Numeric.Vector type Vector (t :: l) (n :: k) = DataFrame t '[n] type Vec2f = Vector Float 2 type Vec3f = Vector Float 3 type Vec4f = Vector Float 4 type Vec2d = Vector Double 2 type Vec3d = Vector Double 3 type Vec4d = Vector Double 4 type Vec2i = Vector Int 2 type Vec3i = Vector Int 3 type Vec4i = Vector Int 4 type Vec2w = Vector Word 2 type Vec3w = Vector Word 3 type Vec4w = Vector Word 4 -- | Scalar product -- sum of Vecs' components products, propagated into -- whole Vec (.*.) :: (Num t, Num (Vector t n), SubSpace t '[] '[n] '[n]) => Vector t n -> Vector t n -> Vector t n infixl 7 .*. -- | Scalar product -- sum of Vecs' components products -- a scalar dot :: (Num t, Num (Vector t n), SubSpace t '[] '[n] '[n]) => Vector t n -> Vector t n -> Scalar t -- | Dot product of two vectors (·) :: (Num t, Num (Vector t n), SubSpace t '[] '[n] '[n]) => Vector t n -> Vector t n -> Scalar t infixl 7 · -- | Sum of absolute values normL1 :: (Num t, SubSpace t '[] '[n] '[n]) => Vector t n -> Scalar t -- | hypot function (square root of squares) normL2 :: (Floating t, SubSpace t '[] '[n] '[n]) => Vector t n -> Scalar t -- | Maximum of absolute values normLPInf :: (Ord t, Num t, SubSpace t '[] '[n] '[n]) => Vector t n -> Scalar t -- | Minimum of absolute values normLNInf :: (Ord t, Num t, SubSpace t '[] '[n] '[n]) => Vector t n -> Scalar t -- | Norm in Lp space normLP :: (Floating t, SubSpace t '[] '[n] '[n]) => Int -> Vector t n -> Scalar t -- | Normalize vector w.r.t. Euclidean metric (L2). normalized :: (Floating t, Fractional (Vector t n), SubSpace t '[] '[n] '[n]) => Vector t n -> Vector t n -- | Compose a 2D vector vec2 :: SubSpace t '[] '[2] '[2] => t -> t -> Vector t 2 -- | Compose a 3D vector vec3 :: SubSpace t '[] '[3] '[3] => t -> t -> t -> Vector t 3 -- | Compose a 4D vector vec4 :: SubSpace t '[] '[4] '[4] => t -> t -> t -> t -> Vector t 4 -- | Take a determinant of a matrix composed from two 2D vectors. Like a -- cross product in 2D. det2 :: (Num t, SubSpace t '[] '[2] '[2]) => Vector t 2 -> Vector t 2 -> Scalar t -- | Cross product cross :: (Num t, SubSpace t '[] '[3] '[3]) => Vector t 3 -> Vector t 3 -> Vector t 3 -- | Cross product for two vectors in 3D (×) :: (Num t, SubSpace t '[] '[3] '[3]) => Vector t 3 -> Vector t 3 -> Vector t 3 infixl 7 × unpackV2 :: SubSpace t '[] '[2] '[2] => Vector t 2 -> (t, t) unpackV3 :: SubSpace t '[] '[3] '[3] => Vector t 3 -> (t, t, t) unpackV4 :: SubSpace t '[] '[4] '[4] => Vector t 4 -> (t, t, t, t) module Numeric.Matrix.Class 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 class MatrixLU t (n :: Nat) -- | Compute LU factorization with Partial Pivoting lu :: MatrixLU t n => Matrix t n n -> LUFact t n -- | Result of LU factorization with Partial Pivoting PA = LU . data LUFact t n LUFact :: Matrix t n n -> Matrix t n n -> Matrix t n n -> Scalar t -> LUFact t n -- | Lower triangular matrix L. All elements on the diagonal of -- L equal 1. [luLower] :: LUFact t n -> Matrix t n n -- | Upper triangular matrix U [luUpper] :: LUFact t n -> Matrix t n n -- | Row permutation matrix P [luPerm] :: LUFact t n -> Matrix t n n -- | Sign of permutation luPermSign == det . luPerm [luPermSign] :: LUFact t n -> Scalar t -- | 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. class HomTransform4 t -- | Create a translation matrix from a vector translate4 :: HomTransform4 t => Vector t 4 -> Matrix t 4 4 -- | Create a translation matrix from a vector translate3 :: HomTransform4 t => Vector t 3 -> Matrix t 4 4 -- | Rotation matrix for a rotation around the X axis, angle is given in -- radians. rotateX :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around the Y axis, angle is given in -- radians. rotateY :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around the Z axis, angle is given in -- radians. rotateZ :: HomTransform4 t => t -> Matrix t 4 4 -- | Rotation matrix for a rotation around an arbitrary normalized vector rotate :: HomTransform4 t => Vector t 3 -> t -> Matrix t 4 4 -- | Rotation matrix from the Euler angles yaw pitch and roll 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 instance forall k t (n :: k). (GHC.Show.Show (Numeric.Matrix.Class.Matrix t n n), GHC.Show.Show t) => GHC.Show.Show (Numeric.Matrix.Class.LUFact t n) instance forall k t (n :: k). (GHC.Classes.Eq (Numeric.Matrix.Class.Matrix t n n), GHC.Classes.Eq t) => GHC.Classes.Eq (Numeric.Matrix.Class.LUFact t n) -- | Construct new DataFrames from pieces. module Numeric.DataFrame.Shape -- | Append one DataFrame to another, sum up last dimension (<:>) :: forall (n :: Nat) (m :: Nat) (npm :: Nat) (ds :: [Nat]) (t :: Type). (PrimBytes (DataFrame t (ds +: n)), PrimBytes (DataFrame t (ds +: m)), PrimBytes (DataFrame t (ds +: npm)), npm ~ (n + m), n ~ (npm - m), m ~ (npm - n)) => DataFrame t (ds +: n) -> DataFrame t (ds +: m) -> DataFrame t (ds +: npm) infixl 5 <:> -- | Append one DataFrame to another, add another Dim = 2 to their -- dimension list. (<::>) :: forall (ds :: [Nat]) (t :: Type). (PrimBytes (DataFrame t ds), PrimBytes (DataFrame t ds), PrimBytes (DataFrame t (ds +: 2 :: [Nat]))) => DataFrame t ds -> DataFrame t ds -> DataFrame t (ds +: 2 :: [Nat]) infixl 5 <::> -- | Grow the first DataFrame by adding the second one to it incrementing -- the last Dim in the list. (<+:>) :: forall (ds :: [Nat]) (n :: Nat) (m :: Nat) (t :: Type). (PrimBytes (DataFrame t (ds +: n)), PrimBytes (DataFrame t ds), PrimBytes (DataFrame t (ds +: m)), m ~ (n + 1)) => DataFrame t (ds +: n) -> DataFrame t ds -> DataFrame t (ds +: m) infixl 5 <+:> -- | Broadcast scalar value onto a whole data frame fromScalar :: SubSpace t '[] ds ds => Scalar t -> DataFrame t ds -- | Implement function toList. We need to create a dedicated type -- class for this to make it polymorphic over kind k (Nat - XNat). class DataFrameToList (t :: Type) (ds :: [k]) (z :: k) -- | Unwrap the last dimension of a DataFrame into a list of smaller frames toList :: DataFrameToList t ds z => DataFrame t (ds +: z) -> [DataFrame t ds] -- | Concatenate a list of DataFrames. Returns Nothing if -- the list does not have enough elements or if provided length is -- invalid. fromListN :: forall (m :: Nat) (ns :: [Nat]) (t :: Type). (Dimensions ns, PrimBytes t) => Dim m -> Int -> [DataFrame t ns] -> Maybe (DataFrame t (AsXDims ns +: XN m)) -- | Concatenate a list of DataFrames. Returns Nothing if -- the list does not have enough elements. -- -- Input must be parametrized by [Nat] to make sure every -- element in the input list has the same dimensionality. Output is in -- [XNat], because the last dimension is unknown at compile -- time. fromList :: forall m ns t. (Dimensions ns, PrimBytes t) => Dim m -> [DataFrame t ns] -> Maybe (DataFrame t (AsXDims ns +: XN m)) instance (Numeric.Dimensions.Dims.Dimensions (ns Numeric.Type.List.+: z), Numeric.PrimBytes.PrimBytes t) => Numeric.DataFrame.Shape.DataFrameToList t ns z instance Numeric.DataFrame.Shape.DataFrameToList t xns xz 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 class MatrixLU t (n :: Nat) -- | Compute LU factorization with Partial Pivoting lu :: MatrixLU t n => Matrix t n n -> LUFact t n -- | Result of LU factorization with Partial Pivoting PA = LU . data LUFact t n LUFact :: Matrix t n n -> Matrix t n n -> Matrix t n n -> Scalar t -> LUFact t n -- | Lower triangular matrix L. All elements on the diagonal of -- L equal 1. [luLower] :: LUFact t n -> Matrix t n n -- | Upper triangular matrix U [luUpper] :: LUFact t n -> Matrix t n n -- | Row permutation matrix P [luPerm] :: LUFact t n -> Matrix t n n -- | Sign of permutation luPermSign == det . luPerm [luPermSign] :: LUFact t n -> Scalar t -- | Alias for DataFrames of rank 2 type Matrix (t :: l) (n :: k) (m :: k) = DataFrame t '[n, m] 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 (Vector (t :: Type) 2), PrimBytes (Matrix t 2 2)) => Vector t 2 -> Vector t 2 -> Matrix t 2 2 -- | Compose a 3x3D matrix mat33 :: (PrimBytes (t :: Type), PrimBytes (Vector t 3), PrimBytes (Matrix t 3 3)) => Vector t 3 -> Vector t 3 -> Vector t 3 -> Matrix t 3 3 -- | Compose a 4x4D matrix mat44 :: forall (t :: Type). (PrimBytes t, PrimBytes (Vector t (4 :: Nat)), PrimBytes (Matrix t (4 :: Nat) (4 :: Nat))) => Vector t (4 :: Nat) -> Vector t (4 :: Nat) -> Vector t (4 :: Nat) -> Vector t (4 :: Nat) -> Matrix t (4 :: Nat) (4 :: Nat) -- | Tensor contraction. In particular: 1. matrix-matrix product 2. -- matrix-vector or vector-matrix product 3. dot product of two vectors. (%*) :: (ConcatList as bs (as ++ bs), Contraction t as bs asbs, KnownDim m, PrimArray t (DataFrame t (as +: m)), PrimArray t (DataFrame t (m :+ bs)), PrimArray t (DataFrame t (as ++ bs))) => DataFrame t (as +: m) -> DataFrame t (m :+ bs) -> DataFrame t (as ++ bs) infixl 7 %* -- | Permute rows that the largest magnitude elements in columns are on -- diagonals. -- -- Invariants of result matrix: * forall j >= i: |M[i,i]| >= M[j,i] -- * if M[i,i] == 0 then forall j >= i: |M[i+1,i+1]| >= M[j,i+1] pivotMat :: forall (t :: Type) (n :: k). (KnownDim n, PrimArray t (Matrix t n n), Ord t, Num t) => Matrix t n n -> (Matrix t n n, Matrix t n n, Scalar t) -- | Solve Ax = b problem given LU decomposition of A. luSolve :: forall (t :: Type) (n :: Nat). (KnownDim n, Ord t, Fractional t, PrimBytes t, PrimArray t (Matrix t n n), PrimArray t (Vector t n)) => LUFact t n -> Vector t n -> Vector t n instance (Numeric.Dim.KnownDim n, Numeric.Dim.KnownDim m, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t n m), Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t m n)) => Numeric.Matrix.Class.MatrixTranspose t n m instance Numeric.Matrix.Class.MatrixTranspose t xn xm instance (Numeric.Dim.KnownDim n, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t n n), GHC.Num.Num t) => Numeric.Matrix.Class.SquareMatrix t n instance (Numeric.Dim.KnownDim n, GHC.Classes.Ord t, GHC.Real.Fractional t, Numeric.PrimBytes.PrimBytes t, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t n n), Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Vector.Vector t n), Numeric.PrimBytes.PrimBytes (Numeric.Vector.Vector t n), Numeric.PrimBytes.PrimBytes (Numeric.Matrix.Class.Matrix t n n)) => Numeric.Matrix.Class.MatrixInverse t n instance (Numeric.Dim.KnownDim n, GHC.Classes.Ord t, GHC.Real.Fractional t, Numeric.PrimBytes.PrimBytes t, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t n n)) => Numeric.Matrix.Class.MatrixDeterminant t n instance (Numeric.Dim.KnownDim n, GHC.Classes.Ord t, GHC.Real.Fractional t, Numeric.PrimBytes.PrimBytes t, Numeric.DataFrame.Internal.Array.Class.PrimArray t (Numeric.Matrix.Class.Matrix t n n)) => Numeric.Matrix.Class.MatrixLU t n -- | Quaternion operations implemented for Floats and Doubles. -- -- The types QDouble and QFloat have the same -- representation as corresponding `Vector t 4`. This means, you can do a -- cheap conversion between the types. -- -- However, arithmetic instances, such as Num and Floating are -- implemented in substentially different ways. For example, fromInteger -- fills a vector fully but sets only real part to a quaternion: -- --
-- >>> 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. Some of the -- operations (such as trigonometric operations) are ambiguous for -- quaternions; the general rules I follow: -- --
-- > realToFrac (square q) == q * conjugate q --square :: Quaternion t => Quater t -> t -- | Imagine part of quaternion (orientation vector) im :: Quaternion t => Quater t -> Quater t -- | Real part of the quaternion re :: Quaternion t => Quater t -> Quater t -- | Get imagenery 3D vector of the quaternion imVec :: Quaternion t => Quater t -> Vector t 3 -- | Real part of the quaternion into number 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 q = (cos -- (a/2), sin (a/2) * v); then the rotation angle is a, and -- the axis of rotation is v. Scaling is proportional to -- |v|^2. -- --
-- >>> 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. 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 -- --
-- >>> 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 -- q and `-q` are equivalent, there result of this function may -- be ambiguious. I decided to force its real part be positive: -- --
-- >>> taker (fromMatrix33 m) >= 0 --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 -- q and `-q` are equivalent, there result of this function may -- be ambiguious. I decided to force its real part be positive: -- --
-- >>> taker (fromMatrix44 m) >= 0 --fromMatrix44 :: Quaternion t => Matrix t 4 4 -> Quater t -- | Create a rotation matrix from a quaternion. Note, that rotations of -- q and `-q` 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 -- q and `-q` 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.DataFrame