-- 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 0.3.2.0 -- | 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). class Semigroup a -- | An associative operation. -- --
--   (a <> b) <> c = a <> (b <> c)
--   
-- -- If a is also a Monoid we further require -- --
--   (<>) = mappend
--   
(<>) :: 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. 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: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. class Monoid a -- | Identity of mappend mempty :: Monoid a => a -- | An associative operation mappend :: Monoid a => a -> a -> a -- | Fold a list using the monoid. For most types, the default definition -- for mconcat will be used, but the function is included in the -- class definition so that an optimized version can be provided for -- specific types. mconcat :: Monoid a => [a] -> a -- | The dual of a Monoid, obtained by swapping the arguments of -- mappend. newtype Dual a :: * -> * Dual :: a -> Dual a [getDual] :: Dual a -> a -- | The monoid of endomorphisms under composition. newtype Endo a :: * -> * Endo :: (a -> a) -> Endo a [appEndo] :: Endo a -> a -> a -- | Boolean monoid under conjunction (&&). newtype All :: * All :: Bool -> All [getAll] :: All -> Bool -- | Boolean monoid under disjunction (||). newtype Any :: * Any :: Bool -> Any [getAny] :: Any -> Bool -- | Monoid under addition. newtype Sum a :: * -> * Sum :: a -> Sum a [getSum] :: Sum a -> a -- | Monoid under multiplication. 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 Data.Foldable.Foldable Numeric.Semigroup.Option instance Data.Traversable.Traversable Numeric.Semigroup.Option instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Numeric.Semigroup.Option a) instance Data.Semigroup.Semigroup a => GHC.Base.Monoid (Numeric.Semigroup.Option a) instance GHC.Classes.Ord a => Data.Semigroup.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) -- | This module defines a set of tuple data types to substitute normal -- lazy tuples. The reason is that Monoid instances of normal -- tuples are lazy, which makes folds with arithmetic operations leak -- memory. Semigroup and Monoid instances of these -- tuples are strict in all their arguments. -- -- Using tuple types defined here together with -- Numeric.Semigroup.foldMap', one can combine multiple monoidal -- fold structures in a single pass over foldable container: -- --
--   > foldMap' (T3 <$> Max <*> Sum <*> minMax) $ take 100000000 ([1..] :: [Int])
--   
-- -- The example above runs in constant space, which would not happen with -- normal GHC tuples due to strictness properties of their mappend -- implementations (tuple arguments are not enforced). module Numeric.Semigroup.StrictTuple data T0 T0 :: T0 newtype T1 a T1 :: a -> T1 a data T2 a b T2 :: a -> b -> T2 a b data T3 a b c T3 :: a -> b -> c -> T3 a b c data T4 a b c d T4 :: a -> b -> c -> d -> T4 a b c d data T5 a b c d e T5 :: a -> b -> c -> d -> e -> T5 a b c d e data T6 a b c d e f T6 :: a -> b -> c -> d -> e -> f -> T6 a b c d e f data T7 a b c d e f g T7 :: a -> b -> c -> d -> e -> f -> g -> T7 a b c d e f g data T8 a b c d e f g h T8 :: a -> b -> c -> d -> e -> f -> g -> h -> T8 a b c d e f g h data T9 a b c d e f g h i T9 :: a -> b -> c -> d -> e -> f -> g -> h -> i -> T9 a b c d e f g h i class StrictTuple a b | a -> b, b -> a toStrictTuple :: StrictTuple a b => a -> b fromStrictTuple :: StrictTuple a b => b -> a strictT0 :: T0 strictT1 :: a -> T1 a strictT2 :: a -> b -> T2 a b strictT3 :: a -> b -> c -> T3 a b c strictT4 :: a -> b -> c -> d -> T4 a b c d strictT5 :: a -> b -> c -> d -> e -> T5 a b c d e strictT6 :: a -> b -> c -> d -> e -> f -> T6 a b c d e f strictT7 :: a -> b -> c -> d -> e -> f -> g -> T7 a b c d e f g strictT8 :: a -> b -> c -> d -> e -> f -> g -> h -> T8 a b c d e f g h strictT9 :: a -> b -> c -> d -> e -> f -> g -> h -> i -> T9 a b c d e f g h i instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance (Data.Data.Data i, Data.Data.Data h, Data.Data.Data g, Data.Data.Data f, Data.Data.Data e, Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance (GHC.Classes.Ord i, GHC.Classes.Ord h, GHC.Classes.Ord g, GHC.Classes.Ord f, GHC.Classes.Ord e, GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance (GHC.Read.Read i, GHC.Read.Read h, GHC.Read.Read g, GHC.Read.Read f, GHC.Read.Read e, GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance (GHC.Show.Show i, GHC.Show.Show h, GHC.Show.Show g, GHC.Show.Show f, GHC.Show.Show e, GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance (GHC.Classes.Eq i, GHC.Classes.Eq h, GHC.Classes.Eq g, GHC.Classes.Eq f, GHC.Classes.Eq e, GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (Data.Data.Data h, Data.Data.Data g, Data.Data.Data f, Data.Data.Data e, Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Classes.Ord h, GHC.Classes.Ord g, GHC.Classes.Ord f, GHC.Classes.Ord e, GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Read.Read h, GHC.Read.Read g, GHC.Read.Read f, GHC.Read.Read e, GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Show.Show h, GHC.Show.Show g, GHC.Show.Show f, GHC.Show.Show e, GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Classes.Eq h, GHC.Classes.Eq g, GHC.Classes.Eq f, GHC.Classes.Eq e, GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (Data.Data.Data g, Data.Data.Data f, Data.Data.Data e, Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Classes.Ord g, GHC.Classes.Ord f, GHC.Classes.Ord e, GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Read.Read g, GHC.Read.Read f, GHC.Read.Read e, GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Show.Show g, GHC.Show.Show f, GHC.Show.Show e, GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Classes.Eq g, GHC.Classes.Eq f, GHC.Classes.Eq e, GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (Data.Data.Data f, Data.Data.Data e, Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Classes.Ord f, GHC.Classes.Ord e, GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Read.Read f, GHC.Read.Read e, GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Show.Show f, GHC.Show.Show e, GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Classes.Eq f, GHC.Classes.Eq e, GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T5 a b c d) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (Data.Data.Data e, Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Classes.Ord e, GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Read.Read e, GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Show.Show e, GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Classes.Eq e, GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T4 a b c) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (Data.Data.Data d, Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Classes.Ord d, GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Read.Read d, GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Show.Show d, GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Classes.Eq d, GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T4 a b c d) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T3 a b) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T3 a b c) instance (Data.Data.Data c, Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Classes.Ord c, GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Read.Read c, GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Show.Show c, GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Classes.Eq c, GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T3 a b c) instance GHC.Generics.Generic1 (Numeric.Semigroup.StrictTuple.T2 a) instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T2 a b) instance (Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T2 a b) instance GHC.Generics.Generic1 Numeric.Semigroup.StrictTuple.T1 instance GHC.Generics.Generic (Numeric.Semigroup.StrictTuple.T1 a) instance Data.Data.Data a => Data.Data.Data (Numeric.Semigroup.StrictTuple.T1 a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Numeric.Semigroup.StrictTuple.T1 a) instance GHC.Read.Read a => GHC.Read.Read (Numeric.Semigroup.StrictTuple.T1 a) instance GHC.Show.Show a => GHC.Show.Show (Numeric.Semigroup.StrictTuple.T1 a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Numeric.Semigroup.StrictTuple.T1 a) instance GHC.Generics.Generic Numeric.Semigroup.StrictTuple.T0 instance Data.Data.Data Numeric.Semigroup.StrictTuple.T0 instance GHC.Classes.Ord Numeric.Semigroup.StrictTuple.T0 instance GHC.Read.Read Numeric.Semigroup.StrictTuple.T0 instance GHC.Show.Show Numeric.Semigroup.StrictTuple.T0 instance GHC.Classes.Eq Numeric.Semigroup.StrictTuple.T0 instance Data.Semigroup.Semigroup Numeric.Semigroup.StrictTuple.T0 instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T1 a) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T2 a b) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T3 a b c) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d, Data.Semigroup.Semigroup e) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d, Data.Semigroup.Semigroup e, Data.Semigroup.Semigroup f) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d, Data.Semigroup.Semigroup e, Data.Semigroup.Semigroup f, Data.Semigroup.Semigroup g) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d, Data.Semigroup.Semigroup e, Data.Semigroup.Semigroup f, Data.Semigroup.Semigroup g, Data.Semigroup.Semigroup h) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (Data.Semigroup.Semigroup a, Data.Semigroup.Semigroup b, Data.Semigroup.Semigroup c, Data.Semigroup.Semigroup d, Data.Semigroup.Semigroup e, Data.Semigroup.Semigroup f, Data.Semigroup.Semigroup g, Data.Semigroup.Semigroup h, Data.Semigroup.Semigroup i) => Data.Semigroup.Semigroup (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance GHC.Base.Monoid Numeric.Semigroup.StrictTuple.T0 instance GHC.Base.Monoid a => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T1 a) instance (GHC.Base.Monoid a, GHC.Base.Monoid b) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g, GHC.Base.Monoid h) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g, GHC.Base.Monoid h, GHC.Base.Monoid i) => GHC.Base.Monoid (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance GHC.Base.Functor Numeric.Semigroup.StrictTuple.T1 instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T2 a) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T3 a b) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T4 a b c) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T5 a b c d) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance GHC.Base.Functor (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance GHC.Base.Applicative Numeric.Semigroup.StrictTuple.T1 instance GHC.Base.Monoid a => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T2 a) instance (GHC.Base.Monoid a, GHC.Base.Monoid b) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T3 a b) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T4 a b c) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T5 a b c d) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g, GHC.Base.Monoid h) => GHC.Base.Applicative (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance GHC.Base.Monad Numeric.Semigroup.StrictTuple.T1 instance GHC.Base.Monoid a => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T2 a) instance (GHC.Base.Monoid a, GHC.Base.Monoid b) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T3 a b) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T4 a b c) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T5 a b c d) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance (GHC.Base.Monoid a, GHC.Base.Monoid b, GHC.Base.Monoid c, GHC.Base.Monoid d, GHC.Base.Monoid e, GHC.Base.Monoid f, GHC.Base.Monoid g, GHC.Base.Monoid h) => GHC.Base.Monad (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance GHC.Enum.Bounded Numeric.Semigroup.StrictTuple.T0 instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T1 a) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T2 a b) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T3 a b c) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T4 a b c d) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d, GHC.Enum.Bounded e) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d, GHC.Enum.Bounded e, GHC.Enum.Bounded f) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d, GHC.Enum.Bounded e, GHC.Enum.Bounded f, GHC.Enum.Bounded g) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d, GHC.Enum.Bounded e, GHC.Enum.Bounded f, GHC.Enum.Bounded g, GHC.Enum.Bounded h) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b, GHC.Enum.Bounded c, GHC.Enum.Bounded d, GHC.Enum.Bounded e, GHC.Enum.Bounded f, GHC.Enum.Bounded g, GHC.Enum.Bounded h, GHC.Enum.Bounded i) => GHC.Enum.Bounded (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) instance Data.Foldable.Foldable Numeric.Semigroup.StrictTuple.T1 instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T2 a) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T3 a b) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T4 a b c) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T5 a b c e) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance Data.Foldable.Foldable (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance Data.Traversable.Traversable Numeric.Semigroup.StrictTuple.T1 instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T2 a) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T3 a b) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T4 a b c) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T5 a b c d) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T6 a b c d e) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T7 a b c d e f) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T8 a b c d e f g) instance Data.Traversable.Traversable (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h) instance Data.Bifunctor.Bifunctor Numeric.Semigroup.StrictTuple.T2 instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T3 a) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T4 a b) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T5 a b c) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T6 a b c d) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T7 a b c d e) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T8 a b c d e f) instance Data.Bifunctor.Bifunctor (Numeric.Semigroup.StrictTuple.T9 a b c d e f g) instance Numeric.Semigroup.StrictTuple.StrictTuple () Numeric.Semigroup.StrictTuple.T0 instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b) (Numeric.Semigroup.StrictTuple.T2 a b) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c) (Numeric.Semigroup.StrictTuple.T3 a b c) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d) (Numeric.Semigroup.StrictTuple.T4 a b c d) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d, e) (Numeric.Semigroup.StrictTuple.T5 a b c d e) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d, e, f) (Numeric.Semigroup.StrictTuple.T6 a b c d e f) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d, e, f, g) (Numeric.Semigroup.StrictTuple.T7 a b c d e f g) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d, e, f, g, h) (Numeric.Semigroup.StrictTuple.T8 a b c d e f g h) instance Numeric.Semigroup.StrictTuple.StrictTuple (a, b, c, d, e, f, g, h, i) (Numeric.Semigroup.StrictTuple.T9 a b c d e f g h i) module Numeric.Commons -- | Facilities to convert to and from raw byte array. Warning! offsets and -- sizes are in elements, not in bytes! Therefore one must be really -- carefull if having a crazy idea of converting between types of -- different element sizes. class PrimBytes (a :: Type) -- | Store content of a data type in a primitive byte array (ElementOffset, -- NumberOfElements, ByteArrayContent ) toBytes :: PrimBytes a => a -> (# Int#, Int#, ByteArray# #) -- | Load content of a data type from a primitive byte array -- (ElementOffset, NumberOfElements, ByteArrayContent ) fromBytes :: PrimBytes a => (# Int#, Int#, ByteArray# #) -> a -- | Size of a data type in bytes byteSize :: PrimBytes a => a -> Int# -- | Alignment of a data type in bytes byteAlign :: PrimBytes a => a -> Int# -- | Size of a conainer type elements in bytes elementByteSize :: PrimBytes a => a -> Int# -- | Primitive indexing ix :: PrimBytes a => Int# -> a -> (ElemPrim a :: TYPE (ElemRep a)) instance Numeric.Commons.PrimBytes GHC.Types.Float instance Numeric.Commons.PrimBytes GHC.Types.Double instance Numeric.Commons.PrimBytes GHC.Types.Int instance Numeric.Commons.PrimBytes GHC.Int.Int8 instance Numeric.Commons.PrimBytes GHC.Int.Int16 instance Numeric.Commons.PrimBytes GHC.Int.Int32 instance Numeric.Commons.PrimBytes GHC.Int.Int64 instance Numeric.Commons.PrimBytes GHC.Types.Word instance Numeric.Commons.PrimBytes GHC.Word.Word8 instance Numeric.Commons.PrimBytes GHC.Word.Word16 instance Numeric.Commons.PrimBytes GHC.Word.Word32 instance Numeric.Commons.PrimBytes GHC.Word.Word64 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 type Scf = Scalar Float type Scd = Scalar Double module Numeric.DataFrame.IO class MutableFrame t (ns :: [Nat]) -- | Mutable DataFrame that lives in IO. Internal representation is always -- a ByteArray. data IODataFrame t (ns :: [Nat]) -- | Mutable DataFrame of unknown dimensionality data SomeIODataFrame t (xns :: [XNat]) SomeIODataFrame :: (IODataFrame t ns) -> SomeIODataFrame t -- | Create a new mutable DataFrame. newDataFrame :: 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 (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]). (ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs), PrimBytes (DataFrame t (as +: b'))) => DataFrame t (as +: b') -> Idx (b :+ bs) -> IODataFrame t asbs -> IO () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. copyMutableDataFrame :: forall t (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]). (PrimBytes t, ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs)) => IODataFrame t (as +: b') -> Idx (b :+ bs) -> IODataFrame t asbs -> IO () -- | Make a mutable DataFrame immutable, without copying. unsafeFreezeDataFrame :: forall t (ns :: [Nat]). PrimBytes (DataFrame t ns) => IODataFrame t ns -> IO (DataFrame t ns) -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame :: forall t (ns :: [Nat]). PrimBytes (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 (ns :: [Nat]). PrimBytes (DataFrame t ns) => DataFrame t ns -> IO (IODataFrame t ns) -- | Write a single element at the specified index writeDataFrame :: forall t (ns :: [Nat]). (MutableFrame t ns, Dimensions ns) => IODataFrame t ns -> Idx ns -> Scalar t -> IO () -- | Read a single element at the specified index readDataFrame :: forall t (ns :: [Nat]). (MutableFrame t ns, Dimensions ns) => IODataFrame t ns -> Idx ns -> IO (Scalar t) -- | Write a single element at the specified element offset writeDataFrameOff :: forall t (ns :: [Nat]). (MutableFrame t ns, Dimensions ns) => IODataFrame t ns -> Int -> Scalar t -> IO () -- | Read a single element at the specified element offset readDataFrameOff :: forall t (ns :: [Nat]). (MutableFrame t ns, Dimensions ns) => IODataFrame t ns -> Int -> IO (Scalar t) -- | Mutable DataFrames living in ST. module Numeric.DataFrame.ST class MutableFrame t (ns :: [Nat]) -- | Mutable DataFrame that lives in ST. Internal representation is always -- a ByteArray. data STDataFrame s t (ns :: [Nat]) -- | Mutable DataFrame of unknown dimensionality data SomeSTDataFrame s t (xns :: [XNat]) SomeSTDataFrame :: (STDataFrame s t ns) -> SomeSTDataFrame s t -- | Create a new mutable DataFrame. newDataFrame :: 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 (as :: [Nat]) (b' :: Nat) (b :: Nat) (bs :: [Nat]) (asbs :: [Nat]) s. (ConcatList as (b :+ bs) asbs, Dimensions (b :+ bs), PrimBytes (DataFrame t (as +: b'))) => DataFrame t (as +: b') -> Idx (b :+ bs) -> STDataFrame s t asbs -> ST s () -- | Copy one mutable DataFrame into another mutable DataFrame at specified -- position. copyMutableDataFrame :: forall t (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') -> Idx (b :+ bs) -> STDataFrame s t asbs -> ST s () -- | Make a mutable DataFrame immutable, without copying. unsafeFreezeDataFrame :: forall t (ns :: [Nat]) s. PrimBytes (DataFrame t ns) => STDataFrame s t ns -> ST s (DataFrame t ns) -- | Copy content of a mutable DataFrame into a new immutable DataFrame. freezeDataFrame :: forall t (ns :: [Nat]) s. PrimBytes (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 (ns :: [Nat]) s. PrimBytes (DataFrame t ns) => DataFrame t ns -> ST s (STDataFrame s t ns) -- | Write a single element at the specified index writeDataFrame :: forall t (ns :: [Nat]) s. (MutableFrame t ns, Dimensions ns) => STDataFrame s t ns -> Idx ns -> Scalar t -> ST s () -- | Read a single element at the specified index readDataFrame :: forall t (ns :: [Nat]) s. (MutableFrame t ns, Dimensions ns) => STDataFrame s t ns -> Idx ns -> ST s (Scalar t) -- | Write a single element at the specified element offset writeDataFrameOff :: forall t (ns :: [Nat]) s. (MutableFrame t ns, Dimensions ns) => STDataFrame s t ns -> Int -> Scalar t -> ST s () -- | Read a single element at the specified element offset readDataFrameOff :: forall t (ns :: [Nat]) s. (MutableFrame t ns, Dimensions ns) => STDataFrame s t ns -> Int -> ST s (Scalar t) module Numeric.Vector type Vector t (n :: Nat) = 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 -- | Scalar product -- sum of Vecs' components products, propagated into -- whole Vec (.*.) :: (Num t, Num (Vector t n), ElementWise (Idx '[n]) t (Vector t 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), ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Vector t n -> Scalar t -- | Dot product of two vectors (·) :: (Num t, Num (Vector t n), ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Vector t n -> Scalar t infixl 7 `·` -- | Sum of absolute values normL1 :: (Num t, ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Scalar t -- | hypot function (square root of squares) normL2 :: (Floating t, ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Scalar t -- | Maximum of absolute values normLPInf :: (Ord t, Num t, ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Scalar t -- | Minimum of absolute values normLNInf :: (Ord t, Num t, ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Scalar t -- | Norm in Lp space normLP :: (Floating t, ElementWise (Idx '[n]) t (Vector t n)) => Int -> Vector t n -> Scalar t -- | Normalize vector w.r.t. Euclidean metric (L2). normalized :: (Floating t, Fractional (Vector t n), ElementWise (Idx '[n]) t (Vector t n)) => Vector t n -> Vector t n -- | Compose a 2D vector vec2 :: ElementWise (Idx '[2]) t (Vector t 2) => t -> t -> Vector t 2 -- | Compose a 3D vector vec3 :: ElementWise (Idx '[3]) t (Vector t 3) => t -> t -> t -> Vector t 3 -- | Compose a 3D vector vec4 :: ElementWise (Idx '[4]) t (Vector t 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 :: (ElementWise (Idx '[2]) t (Vector t 2), Num t) => Vector t 2 -> Vector t 2 -> Scalar t -- | Cross product cross :: (ElementWise (Idx '[3]) t (Vector t 3), Num t) => Vector t 3 -> Vector t 3 -> Vector t 3 -- | Cross product for two vectors in 3D (×) :: (ElementWise (Idx '[3]) t (Vector t 3), Num t) => Vector t 3 -> Vector t 3 -> Vector t 3 infixl 7 × unpackV2 :: ElementWise (Idx '[2]) t (Vector t 2) => Vector t 2 -> (t, t) unpackV3 :: ElementWise (Idx '[3]) t (Vector t 3) => Vector t 3 -> (t, t, t) unpackV4 :: ElementWise (Idx '[4]) t (Vector t 4) => Vector t 4 -> (t, t, t, t) module Numeric.Matrix class MatrixCalculus t (n :: Nat) (m :: Nat) -- | Transpose Mat transpose :: (MatrixCalculus t n m, MatrixCalculus t m n, PrimBytes (Matrix t m n)) => Matrix t n m -> Matrix t m n class SquareMatrixCalculus t (n :: Nat) -- | Mat with 1 on diagonal and 0 elsewhere eye :: SquareMatrixCalculus t n => Matrix t n n -- | Put the same value on the Mat diagonal, 0 otherwise diag :: SquareMatrixCalculus t n => Scalar t -> Matrix t n n -- | Determinant of Mat det :: SquareMatrixCalculus t n => Matrix t n n -> Scalar t -- | Sum of diagonal elements trace :: SquareMatrixCalculus t n => Matrix t n n -> Scalar t class MatrixInverse t (n :: Nat) -- | Matrix inverse inverse :: MatrixInverse t n => DataFrame t '[n, n] -> DataFrame t '[n, n] -- | 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 -- | Alias for DataFrames of rank 2 type Matrix t (n :: Nat) (m :: Nat) = 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 2), PrimBytes (Matrix t 2 2)) => Vector t 2 -> Vector t 2 -> Matrix t 2 2 -- | Compose a 3x3D matrix mat33 :: (PrimBytes t, 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, PrimBytes (DataFrame t (as +: m)), PrimBytes (DataFrame t (m :+ bs)), PrimBytes (DataFrame t (as ++ bs))) => DataFrame t (as +: m) -> DataFrame t (m :+ bs) -> DataFrame t (as ++ bs) infixl 7 %* module Numeric.DataFrame -- | Keep data in a primitive data frame and maintain information about -- Dimensions in the type-system -- | Allow all numeric operations depending on element type type NumericFrame t ds = (CommonOpFrame t ds, NumericVariantFrame t ds) -- | Allow floating-point operations on data frames type FPFRame t ds = (Fractional (DataFrame t ds), Floating (DataFrame t ds)) -- | Allow some integer-like operations on data frames type IntegralFrame t (ds :: [Nat]) = Bounded (DataFrame t ds) -- | Allow all common operations on data frames type CommonOpFrame t ds = (Show (DataFrame t ds), Eq (DataFrame t ds), Ord (DataFrame t ds), Num (DataFrame t ds), ElementWise (Idx ds) t (DataFrame t ds), PrimBytes (DataFrame t ds), ArrayInstanceInference t ds, KnownDims ds, FiniteList ds, Dimensions ds) -- | 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) => SubSpace (t :: Type) (as :: [Nat]) (bs :: [Nat]) (asbs :: [Nat]) | asbs as -> bs, asbs bs -> as, as bs -> asbs where (!.) i = case (# dimVal (dim @as), fromEnum i #) of { (# I# n, I# j #) -> indexOffset# (n *# j) n } -- | Unsafely get a sub-dataframe by its primitive element subset. 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 -- | Get an element by its index in the dataframe (!.) :: SubSpace t as bs asbs => Idx bs -> DataFrame t asbs -> DataFrame t as -- | Set a new value to an element update :: SubSpace t as bs asbs => Idx 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') => (Idx 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 => (Idx 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 => (Idx 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 => (Idx 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') => (Idx 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 -> Idx bs -> DataFrame t as infixl 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) => Idx 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) => (Idx 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'') => (Idx 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) => (Idx 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 () 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, PrimBytes (DataFrame t (as +: m)), PrimBytes (DataFrame t (m :+ bs)), PrimBytes (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, PrimBytes (DataFrame t (as +: m)), PrimBytes (DataFrame t (m :+ bs)), PrimBytes (DataFrame t (as ++ bs))) => DataFrame t (as +: m) -> DataFrame t (m :+ bs) -> DataFrame t (as ++ bs) infixl 7 %* -- | Evidence for PrimBytes class type PrimBytesEvidence t (ds :: [Nat]) = Evidence (PrimBytes (DataFrame t ds)) inferPrimBytes :: forall t (ds :: [Nat]). (ArrayInstanceInference t ds, Dimensions ds) => PrimBytesEvidence t ds -- | Evidence for ElementWise class type ElementWiseEvidence t (ds :: [Nat]) = Evidence (ElementWise (Idx ds) t (DataFrame t ds)) inferElementWise :: forall t (ds :: [Nat]). (ArrayInstanceInference t ds, Dimensions ds) => ElementWiseEvidence t ds -- | Allow all common operations on available data frames type NumericFrameEvidence t (ds :: [Nat]) = Evidence (NumericFrame t ds) inferNumericFrame :: forall t (ds :: [Nat]). (ArrayInstanceInference t ds, Dimensions ds) => NumericFrameEvidence t ds -- | Append one DataFrame to another, adding up their last dimensionality (<:>) :: 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, adding up their last dimensionality (<::>) :: 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 <::> -- | Append one DataFrame to another, adding up their last dimensionality (<+:>) :: 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 <+:> -- | 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 ns t xns xnsm. (ns ~ AsDims xns, xnsm ~ (xns +: XN 2), PrimBytes (DataFrame t ns), Dimensions ns, ArrayInstanceInference t ns) => [DataFrame t ns] -> DataFrame t (xns +: XN 2) -- | 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 z (ds :: [k]) -- | Unwrap the last dimension of a DataFrame into a list of smaller frames toList :: DataFrameToList t z ds => DataFrame t (ds +: z) -> [DataFrame t ds] -- | Broadcast scalar value onto a whole data frame fromScalar :: ElementWise (Idx ds) t (DataFrame t ds) => Scalar t -> DataFrame t ds -- | Access elements. i is an index type x is an element t is a container -- type class ElementWise i x t | t -> x i -- | A singleton type used to prove that the given Array family instance -- has a known instance type ArrayInstanceEvidence t (ds :: [Nat]) = Evidence (ArrayInstanceInference t ds) -- | Keep information about the instance behind Array family -- -- Warning! This part of the code is platform and flag dependent. data ArrayInstance t (ds :: [Nat]) AIScalar :: ArrayInstance t AIArrayF :: ArrayInstance t AIArrayD :: ArrayInstance t AIArrayI :: ArrayInstance t AIArrayI8 :: ArrayInstance t AIArrayI16 :: ArrayInstance t AIArrayI32 :: ArrayInstance t AIArrayI64 :: ArrayInstance t AIArrayW :: ArrayInstance t AIArrayW8 :: ArrayInstance t AIArrayW16 :: ArrayInstance t AIArrayW32 :: ArrayInstance t AIArrayW64 :: ArrayInstance t AIFloatX2 :: ArrayInstance t AIFloatX3 :: ArrayInstance t AIFloatX4 :: ArrayInstance t AIDoubleX2 :: ArrayInstance t AIDoubleX3 :: ArrayInstance t AIDoubleX4 :: ArrayInstance t getArrayInstance :: forall t (ds :: [Nat]). ArrayInstanceInference t ds => ArrayInstance t ds -- | Given element type instance and proper dimension list, infer a -- corresponding array instance inferArrayInstance :: forall t ds. (FiniteList ds, KnownDims ds, ElemTypeInference t) => ArrayInstanceEvidence t ds class ArraySizeInference ds -- | Pattern match agains result to get actual array dimensionality arraySizeInstance :: ArraySizeInference ds => ArraySize ds inferSnocArrayInstance :: (ArraySizeInference ds, ElemTypeInference t, KnownDim z) => p t ds -> q z -> ArrayInstanceEvidence t (ds +: z) inferConsArrayInstance :: (ArraySizeInference ds, ElemTypeInference t, KnownDim z) => q z -> p t ds -> ArrayInstanceEvidence t (z :+ ds) inferInitArrayInstance :: (ArraySizeInference ds, ElemTypeInference t) => p t ds -> ArrayInstanceEvidence t (Init ds) -- | Keep information about the array dimensionality -- -- Warning! This part of the code is platform and flag dependent. data ArraySize (ds :: [Nat]) ASScalar :: ArraySize ASX2 :: ArraySize ASX3 :: ArraySize ASX4 :: ArraySize ASXN :: ArraySize ASArray :: ArraySize class ElemTypeInference t -- | Pattern match against result to get specific element type elemTypeInstance :: ElemTypeInference t => ElemType t -- | Keep information about the element type instance. -- -- Warning! This part of the code is platform and flag dependent. data ElemType t ETFloat :: ElemType t ETDouble :: ElemType t ETInt :: ElemType t ETInt8 :: ElemType t ETInt16 :: ElemType t ETInt32 :: ElemType t ETInt64 :: ElemType t ETWord :: ElemType t ETWord8 :: ElemType t ETWord16 :: ElemType t ETWord32 :: ElemType t ETWord64 :: ElemType t -- | 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: -- --
    --
  1. Preserve imaginary vector axis same if possible;
  2. --
  3. If both +q and -q are possible, prefer real -- value positive (re q >= 0).
  4. --
module Numeric.Quaternion -- | Quaternion operations class Quaternion t where data Quater t where { 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 -- | 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