-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Tensors of statically known size -- -- This library provides a toolkit for working with tensors of statically -- known size and element's type. See README.md @package static-tensor @version 0.2.0.0 module Data.Function.NAry -- | N-ary function from n arguments of type t to value -- of type r. -- | Apply list of params to N-ary function. class ApplyNAry (n :: Nat) (t :: Type) (r :: Type) applyNAry :: ApplyNAry n t r => NAry n t r -> [t] -> r instance Data.Function.NAry.ApplyNAry 0 t r instance (Data.Function.NAry.ApplyNAry (n GHC.TypeNats.- 1) t r, Data.Function.NAry.NAry n t r ~ (t -> Data.Function.NAry.NAry (n GHC.TypeNats.- 1) t r), GHC.TypeNats.KnownNat n) => Data.Function.NAry.ApplyNAry n t r -- | This module provides unrollable versions of functions on lists. -- -- Classes in this module are assumed to be closed. You should not -- create new instances for them. module Data.List.Unrolled -- | Append two lists. Type param l is the length of the left -- list. class Append (n :: Nat) append :: Append n => [a] -> [a] -> [a] -- | Drop n elements from a list. class Drop (n :: Nat) drop :: Drop n => [a] -> [a] -- | Take n elements from a list class Take (n :: Nat) take :: Take n => [a] -> [a] -- | Split list at n-th element. splitAt :: forall (n :: Nat) a. (Take n, Drop n) => [a] -> ([a], [a]) -- | Split list into chunks of the given length c. n is -- length of the list. class ChunksOf (n :: Nat) (c :: Nat) chunksOf :: ChunksOf n c => [a] -> [[a]] -- | Number of resulting chunks when list of length len split by -- chunks of length clen. -- | Zip 2 lists together. Type param n is the length of the first -- list. class Zip (n :: Nat) zip :: Zip n => [a] -> [b] -> [(a, b)] -- | Zip 3 lists together. Type param n is the length of the first -- list. class Zip3 (n :: Nat) zip3 :: Zip3 n => [a] -> [b] -> [c] -> [(a, b, c)] -- | Zip 2 lists together using given function. Type param n is -- the length of the first list. class ZipWith (n :: Nat) zipWith :: ZipWith n => (a -> b -> c) -> [a] -> [b] -> [c] -- | Unzip a list. Type param n is the length of the list. class Unzip (n :: Nat) unzip :: Unzip n => [(a, b)] -> ([a], [b]) -- | Filter list with given predicate. Type param n is the length -- of the list. class Filter (n :: Nat) filter :: Filter n => (a -> Bool) -> [a] -> [a] -- | Apply function to all elements of a list. Type param n is the -- length of the list. class Map (n :: Nat) map :: Map n => (a -> b) -> [a] -> [b] -- | Check if all elements of the list satisfy the predicate. Type param -- n is the length of the list. class All (n :: Nat) all :: All n => (a -> Bool) -> [a] -> Bool -- | Right fold of a list of length n. class Foldr (n :: Nat) foldr :: Foldr n => (a -> b -> b) -> b -> [a] -> b -- | Right fold of a list of length n with no base element. class Foldr1 (n :: Nat) foldr1 :: Foldr1 n => (a -> a -> a) -> [a] -> a -- | Left fold of a list of length n. class Foldl (n :: Nat) foldl :: Foldl n => (b -> a -> b) -> b -> [a] -> b -- | Right fold of a list of length n with no base element. class Foldl1 (n :: Nat) foldl1 :: Foldl1 n => (a -> a -> a) -> [a] -> a -- | Map each element of the list of length n to a monoid, and -- combine the results. foldMap :: forall (n :: Nat) m a. (FoldMap n m) => (a -> m) -> [a] -> m -- | Constraint of the foldMap function. type FoldMap (n :: Nat) m = (Monoid m, Foldr n) -- | Sum of the elements of the list of length n. sum :: forall (n :: Nat) a. (Sum n a) => [a] -> a -- | Constraint of the sum function. type Sum (n :: Nat) a = (Foldr n, Num a) -- | Fill the list of length n with the same values. class Replicate (n :: Nat) replicate :: Replicate n => a -> [a] -- | Enumeration of length n starting from given value. class EnumFromN (n :: Nat) enumFromN :: (EnumFromN n, (Num a)) => a -> [a] -- | Enumeration of length n starting from given value with given -- step. class EnumFromStepN (n :: Nat) enumFromStepN :: (EnumFromStepN n, (Num a)) => a -> a -> [a] instance Data.List.Unrolled.EnumFromStepN 0 instance Data.List.Unrolled.EnumFromStepN (n GHC.TypeNats.- 1) => Data.List.Unrolled.EnumFromStepN n instance Data.List.Unrolled.EnumFromN 0 instance Data.List.Unrolled.EnumFromN (n GHC.TypeNats.- 1) => Data.List.Unrolled.EnumFromN n instance Data.List.Unrolled.Replicate 0 instance Data.List.Unrolled.Replicate (n GHC.TypeNats.- 1) => Data.List.Unrolled.Replicate n instance Data.List.Unrolled.Foldl1 1 instance Data.List.Unrolled.Foldl1 (n GHC.TypeNats.- 1) => Data.List.Unrolled.Foldl1 n instance Data.List.Unrolled.Foldl 0 instance Data.List.Unrolled.Foldl (n GHC.TypeNats.- 1) => Data.List.Unrolled.Foldl n instance Data.List.Unrolled.Foldr1 1 instance Data.List.Unrolled.Foldr1 (n GHC.TypeNats.- 1) => Data.List.Unrolled.Foldr1 n instance Data.List.Unrolled.Foldr 0 instance Data.List.Unrolled.Foldr (n GHC.TypeNats.- 1) => Data.List.Unrolled.Foldr n instance Data.List.Unrolled.All 0 instance Data.List.Unrolled.All (n GHC.TypeNats.- 1) => Data.List.Unrolled.All n instance Data.List.Unrolled.Map 0 instance Data.List.Unrolled.Map (n GHC.TypeNats.- 1) => Data.List.Unrolled.Map n instance Data.List.Unrolled.Filter 0 instance Data.List.Unrolled.Filter (n GHC.TypeNats.- 1) => Data.List.Unrolled.Filter n instance Data.List.Unrolled.ZipWith 0 instance Data.List.Unrolled.ZipWith (n GHC.TypeNats.- 1) => Data.List.Unrolled.ZipWith n instance Data.List.Unrolled.Unzip 0 instance Data.List.Unrolled.Unzip (n GHC.TypeNats.- 1) => Data.List.Unrolled.Unzip n instance Data.List.Unrolled.Zip3 0 instance Data.List.Unrolled.Zip3 (n GHC.TypeNats.- 1) => Data.List.Unrolled.Zip3 n instance Data.List.Unrolled.Zip 0 instance Data.List.Unrolled.Zip (n GHC.TypeNats.- 1) => Data.List.Unrolled.Zip n instance Data.List.Unrolled.ChunksOf 0 0 instance Data.List.Unrolled.ChunksOf 0 c instance Data.List.Unrolled.ChunksOf n 0 instance (Data.List.Unrolled.Take c, Data.List.Unrolled.Drop c, Data.List.Unrolled.ChunksOf (n GHC.TypeNats.- 1) c) => Data.List.Unrolled.ChunksOf n c instance Data.List.Unrolled.Take 0 instance Data.List.Unrolled.Take (n GHC.TypeNats.- 1) => Data.List.Unrolled.Take n instance Data.List.Unrolled.Drop 0 instance Data.List.Unrolled.Drop (n GHC.TypeNats.- 1) => Data.List.Unrolled.Drop n instance Data.List.Unrolled.Append 0 instance Data.List.Unrolled.Append (n GHC.TypeNats.- 1) => Data.List.Unrolled.Append n module Type.List -- | Demote type-level list of Nat. class KnownNats (ns :: [Nat]) natsVal :: KnownNats ns => [Int] -- | Make a constraint for type x :: kx from TyFun, or -- partially applied constraint, or make an empty constraint. -- | Demote a type-level list to value-level list with a type-indexed -- function. The function takes list element as type parameter x -- and applies constraints ctx for that element. class DemoteWith (kx :: Type) (kctx :: Type) (ctx :: kctx) (xs :: [kx]) demoteWith :: DemoteWith kx kctx ctx xs => (forall (x :: kx). (MkCtx kx kctx ctx x) => Proxy x -> a) -> [a] instance forall kx kctx (ctxs :: kctx). Type.List.DemoteWith kx kctx ctxs '[] instance forall kx kctx (ctx :: kctx) (xs :: [kx]) (x :: kx). (Type.List.DemoteWith kx kctx ctx xs, Type.List.MkCtx kx kctx ctx x) => Type.List.DemoteWith kx kctx ctx (x : xs) instance Type.List.KnownNats '[] instance (GHC.TypeNats.KnownNat n, Type.List.KnownNats ns) => Type.List.KnownNats (n : ns) module Data.Tensor.Static -- | Data family of unboxed tensors. Dimensions of a tensor are represented -- as type-level list of naturals. For instance, Tensor [3] -- Float is a vector of 3 Float elements; Tensor [4,3] -- Double is a matrix with 4 rows 3 columns of Double and so -- on. class (PositiveDims dims, KnownNats dims) => IsTensor (dims :: [Nat]) e where { data family Tensor dims e :: Type; } -- | Alias for a concrete tensor data constructor. -- --
--   >>> tensor @[2,2] @Int 0 1 2 3
--   Tensor'2'2 [[0,1],[2,3]]
--   
tensor :: IsTensor dims e => TensorConstructor dims e -- | Build tensor from the list. The list must contain at least -- length elements or method will throw an exception. unsafeFromList :: IsTensor dims e => [e] -> Tensor dims e -- | Convert tensor to list. toList :: IsTensor dims e => Tensor dims e -> [] e -- | Type of a tensor data constructor. -- --
--   >>> :kind! TensorConstructor '[2,2] Float
--   TensorConstructor '[2,2] Float :: *
--   = Float -> Float -> Float -> Float -> Tensor '[2, 2] Float
--   
type TensorConstructor (dims :: [Nat]) (e :: Type) = NAry (ElemsNumber dims) e (Tensor dims e) -- | Check if all dimensions are greater than 0. -- | Tensor filled with given elements. fill :: forall (dims :: [Nat]) e. (Fill dims e) => e -> Tensor dims e -- | Tensor filled with zeros. zero :: (Fill dims e, Num e) => Tensor dims e -- | Tensor which elements are enumeration starting from given value. enumFromN :: forall (dims :: [Nat]) e. (EnumFromN dims e) => e -> Tensor dims e -- | Constraints for enumFromN function. type EnumFromN (dims :: [Nat]) e = (IsTensor dims e, EnumFromN (ElemsNumber dims), Num e) -- | Tensor which elements are enumeration starting from given value with -- given step. enumFromStepN :: forall (dims :: [Nat]) e. (EnumFromStepN dims e) => e -> e -> Tensor dims e -- | Constraints for enumFromStepN function. type EnumFromStepN (dims :: [Nat]) e = (IsTensor dims e, EnumFromStepN (ElemsNumber dims), Num e) -- | Generate a tensor by applying the function to each index. ctx -- type parameter is a producer of constraint of kind kctx for -- each index. See MkCtx for more info. -- --
--   >>> import Data.Singletons
--   
--   >>> type Ctx (dims :: [Nat]) (index :: [Nat]) = KnownNat (FlattenIndex index dims); $(genDefunSymbols [''Ctx])
--   
--   >>> generate @[2,3,4] @Int @([Nat] ~> Constraint) @(CtxSym1 [2,3,4]) $ \(Proxy :: Proxy index) -> fromIntegral $ natVal (Proxy @(FlattenIndex index [2,3,4]))
--   Tensor'2'3'4 [[[0,1,2,3],[4,5,6,7],[8,9,10,11]],[[12,13,14,15],[16,17,18,19],[20,21,22,23]]]
--   
generate :: forall (dims :: [Nat]) (e :: Type) (kctx :: Type) (ctx :: kctx). (Generate dims e kctx ctx) => (forall (index :: [Nat]). (MkCtx [Nat] kctx ctx index) => Proxy index -> e) -> Tensor dims e -- | Constraints for generate function. type Generate (dims :: [Nat]) (e :: Type) (kctx :: Type) (ctx :: kctx) = (IsTensor dims e, DemoteWith [Nat] kctx ctx (AllIndexes dims)) -- | Dimensions of a tensor. dimensions :: forall (dims :: [Nat]). (KnownNats dims) => [Int] -- | Number of elements in a tensor. elemsNumber :: forall (dims :: [Nat]). (KnownNat (ElemsNumber dims)) => Int -- | Number of elements of all subtensors of a tensor. -- --
--   >>> subtensorsElemsNumbers @[2,3,4]
--   [12,4,1]
--   
-- --
--   >>> subtensorsElemsNumbers @[4,4]
--   [4,1]
--   
subtensorsElemsNumbers :: forall (dims :: [Nat]). (KnownNats (SubtensorsElemsNumbers dims)) => [Int] -- | Number of elements in a tensor. -- | Number of elements of all subtensors of a tensor with given shape -- dims. -- --
--   >>> :kind! SubtensorsElemsNumbers '[2,3,4]
--   SubtensorsElemsNumbers '[2,3,4] :: [Nat]
--   = '[12, 4, 1]
--   
-- --
--   >>> :kind! SubtensorsElemsNumbers '[4,4]
--   SubtensorsElemsNumbers '[4,4] :: [Nat]
--   = '[4, 1]
--   
type SubtensorsElemsNumbers (dims :: [Nat]) = Tail (SubtensorsElemsNumbers' dims) -- | Convert multidimentional index in tensor of shape -- dims to flat index. index parameter must have the -- same length as dims. -- --
--   >>> :kind! FlattenIndex '[1,1,1] '[2,3,4]
--   FlattenIndex '[1,1,1] '[2,3,4] :: Nat
--   = 17
--   
type FlattenIndex (index :: [Nat]) (dims :: [Nat]) = FlattenIndex' index (SubtensorsElemsNumbers dims) -- | Sequence of all indexes in a tensor of shape dims. -- --
--   >>> :kind! AllIndexes '[2,3,4]
--   AllIndexes '[2,3,4] :: [[Nat]]
--   = '['[0, 0, 0], '[0, 0, 1], '[0, 0, 2], '[0, 0, 3], '[0, 1, 0],
--       '[0, 1, 1], '[0, 1, 2], '[0, 1, 3], '[0, 2, 0], '[0, 2, 1],
--       '[0, 2, 2], '[0, 2, 3], '[1, 0, 0], '[1, 0, 1], '[1, 0, 2],
--       '[1, 0, 3], '[1, 1, 0], '[1, 1, 1], '[1, 1, 2], '[1, 1, 3],
--       '[1, 2, 0], '[1, 2, 1], '[1, 2, 2], '[1, 2, 3]]
--   
type AllIndexes (dims :: [Nat]) = Sequence (IndexesRanges dims) -- | Generate range of naturals starting from from param inclusive -- and up to to param inclusive. type NatsFromTo (from :: Nat) (to :: Nat) = NatsFromTo' from to (from <=? to) -- | Remove unit dimentions, i.e. dimensions with size 1. -- --
--   >>> :kind! NormalizeDims '[2, 1, 3]
--   '[2, 3]
--   
-- | Pass tensor elements to a function. -- --
--   >>> withTensor (matrix @2 @2 @Float 0 1 2 3) (\a b c d -> a * d - b * c)
--   -2.0
--   
-- --
--   >>> withTensor (vector @2 @Float 3 4) (\x y -> sqrt $ x * x + y * y)
--   5.0
--   
withTensor :: forall dims e r. (IsTensor dims e, ApplyNAry (ElemsNumber dims) e r) => Tensor dims e -> (NAry (ElemsNumber dims) e r) -> r -- | Add two tensors element-wise. add :: (Add dims e) => Tensor dims e -> Tensor dims e -> Tensor dims e -- | Constraints for add. type Add (dims :: [Nat]) e = (IsTensor dims e, Num e, ZipWith (ElemsNumber dims), Zip (ElemsNumber dims), Unzip (ElemsNumber dims), Map (ElemsNumber dims)) -- | Substract two tensors element-wise. diff :: (Diff dims e) => Tensor dims e -> Tensor dims e -> Tensor dims e -- | Constraints for diff. type Diff (dims :: [Nat]) e = (IsTensor dims e, Num e, ZipWith (ElemsNumber dims), Zip (ElemsNumber dims), Unzip (ElemsNumber dims), Map (ElemsNumber dims)) -- | Multiply every element of a tensor by given value. scale :: (Scale dims e) => Tensor dims e -> e -> Tensor dims e -- | Constraints for scale. type Scale (dims :: [Nat]) e = (IsTensor dims e, Num e, Map (ElemsNumber dims)) -- | Prepend a subtensor along axis to the tensor with shape -- dims -- --
--   >>> cons @0 (enumFromStepN @[3,4] @Int (-1) (-1)) (enumFromN @[2,3,4] 0)
--   Tensor'3'3'4 [[[ -1,  -2,  -3,  -4]
--                 ,[ -5,  -6,  -7,  -8]
--                 ,[ -9, -10, -11, -12]]
--                ,[[  0,   1,   2,   3]
--                 ,[  4,   5,   6,   7]
--                 ,[  8,   9,  10,  11]]
--                ,[[ 12,  13,  14,  15]
--                 ,[ 16,  17,  18,  19]
--                 ,[ 20,  21,  22,  23]]]
--   
-- --
--   >>> cons @1 (enumFromStepN @[2,4] @Int (-1) (-1)) (enumFromN @[2,3,4] 0)
--   Tensor'2'4'4 [[[ -1,  -2,  -3,  -4]
--                 ,[  0,   1,   2,   3]
--                 ,[  4,   5,   6,   7]
--                 ,[  8,   9,  10,  11]]
--                ,[[ -5,  -6,  -7,  -8]
--                 ,[ 12,  13,  14,  15]
--                 ,[ 16,  17,  18,  19]
--                 ,[ 20,  21,  22,  23]]]
--   
-- --
--   >>> cons @2 (enumFromStepN @[2,3] @Int (-1) (-1)) (enumFromN @[2,3,4] 0)
--   Tensor'2'3'5 [[[ -1,   0,   1,   2,   3]
--                 ,[ -2,   4,   5,   6,   7]
--                 ,[ -3,   8,   9,  10,  11]]
--                ,[[ -4,  12,  13,  14,  15]
--                 ,[ -5,  16,  17,  18,  19]
--                 ,[ -6,  20,  21,  22,  23]]]
--   
cons :: forall (axis :: Nat) (dims :: [Nat]) e. (Cons axis dims e) => Tensor (NormalizeDims (ConsSubtensorDims axis dims)) e -> Tensor dims e -> Tensor (DimsAfterCons axis dims) e -- | Constraints for cons. type Cons (axis :: Nat) (dims :: [Nat]) e = (SetSlice (ConsSubtensorStartingIndex dims) (ConsSubtensorDims axis dims) (DimsAfterCons axis dims) e, SetSlice (ConsTensorStartingIndex axis dims) dims (DimsAfterCons axis dims) e, dims ~ NormalizeDims dims, Fill (DimsAfterCons axis dims) e) -- | Shape of subtensor being cons'ed to the tensor dims. -- --
--   >>> :kind! ConsSubtensorDims 0 [2,3,4]
--   ConsSubtensorDims 0 [2,3,4] :: [Nat] 
--   = '[1, 3, 4]                
--   
-- --
--   >>> :kind! ConsSubtensorDims 1 [2,3,4]
--   ConsSubtensorDims 1 [2,3,4] :: [Nat] 
--   = '[2, 1, 4]                
--   
-- --
--   >>> :kind! ConsSubtensorDims 2 [2,3,4]
--   ConsSubtensorDims 2 [2,3,4] :: [Nat] 
--   = '[2, 3, 1]                
--   
type ConsSubtensorDims (axis :: Nat) (dims :: [Nat]) = ConsSubtensorDims' axis dims 0 -- | Shape of the tensor after cons'ing -- --
--   >>> :kind! DimsAfterCons 0 [2,3,4]
--   DimsAfterCons 0 [2,3,4] :: [Nat]
--   = '[3, 3, 4]
--   
-- --
--   >>> :kind! DimsAfterCons 1 [2,3,4]
--   DimsAfterCons 1 [2,3,4] :: [Nat]
--   = '[2, 4, 4]
--   
-- --
--   >>> :kind! DimsAfterCons 2 [2,3,4]
--   DimsAfterCons 2 [2,3,4] :: [Nat]
--   = '[2, 3, 5]
--   
-- | Append a subtensor along axis to the tensor with shape -- dims -- --
--   >>> snoc @0 (enumFromN @[2,3,4] 0) (enumFromStepN @[3,4] @Int (-1) (-1))
--   Tensor'3'3'4 [[[  0,   1,   2,   3]
--                 ,[  4,   5,   6,   7]
--                 ,[  8,   9,  10,  11]]
--                ,[[ 12,  13,  14,  15]
--                 ,[ 16,  17,  18,  19]
--                 ,[ 20,  21,  22,  23]]
--                ,[[ -1,  -2,  -3,  -4]
--                 ,[ -5,  -6,  -7,  -8]
--                 ,[ -9, -10, -11, -12]]]
--   
-- --
--   >>> snoc @1 (enumFromN @[2,3,4] 0) (enumFromStepN @[2,4] @Int (-1) (-1))
--   Tensor'2'4'4 [[[  0,   1,   2,   3]
--                 ,[  4,   5,   6,   7]
--                 ,[  8,   9,  10,  11]
--                 ,[ -1,  -2,  -3,  -4]]
--                ,[[ 12,  13,  14,  15]
--                 ,[ 16,  17,  18,  19]
--                 ,[ 20,  21,  22,  23]
--                 ,[ -5,  -6,  -7,  -8]]]
--   
-- --
--   >>> snoc @2 (enumFromN @[2,3,4] 0) (enumFromStepN @[2,3] @Int (-1) (-1))
--   Tensor'2'3'5 [[[  0,   1,   2,   3,  -1]
--                 ,[  4,   5,   6,   7,  -2]
--                 ,[  8,   9,  10,  11,  -3]]
--                ,[[ 12,  13,  14,  15,  -4]
--                 ,[ 16,  17,  18,  19,  -5]
--                 ,[ 20,  21,  22,  23,  -6]]]
--   
snoc :: forall (axis :: Nat) (dims :: [Nat]) e. (Snoc axis dims e) => Tensor dims e -> Tensor (NormalizeDims (SnocSubtensorDims axis dims)) e -> Tensor (DimsAfterSnoc axis dims) e -- | Constraints for snoc. type Snoc (axis :: Nat) (dims :: [Nat]) e = (SetSlice (SnocSubtensorStartingIndex axis dims) (SnocSubtensorDims axis dims) (DimsAfterSnoc axis dims) e, SetSlice (SnocTensorStartingIndex dims) dims (DimsAfterSnoc axis dims) e, dims ~ NormalizeDims dims, Fill (DimsAfterSnoc axis dims) e) -- | Shape of subtensor being snoc'ed to the tensor dims. -- --
--   >>> :kind! SnocSubtensorDims 0 [2,3,4]
--   SnocSubtensorDims 0 [2,3,4] :: [Nat] 
--   = '[1, 3, 4]
--   
-- --
--   >>> :kind! SnocSubtensorDims 1 [2,3,4]
--   SnocSubtensorDims 1 [2,3,4] :: [Nat] 
--   = '[2, 1, 4]
--   
-- --
--   >>> :kind! SnocSubtensorDims 2 [2,3,4]
--   SnocSubtensorDims 2 [2,3,4] :: [Nat] 
--   = '[2, 3, 1]
--   
type SnocSubtensorDims (axis :: Nat) (dims :: [Nat]) = SnocSubtensorDims' axis dims 0 -- | Shape of the tensor after snoc'ing -- --
--   >>> :kind! DimsAfterSnoc 0 [2,3,4]
--   DimsAfterSnoc 0 [2,3,4] :: [Nat]
--   = '[3, 3, 4]
--   
-- --
--   >>> :kind! DimsAfterSnoc 1 [2,3,4]
--   DimsAfterSnoc 1 [2,3,4] :: [Nat]
--   = '[2, 4, 4]
--   
-- --
--   >>> :kind! DimsAfterSnoc 2 [2,3,4]
--   DimsAfterSnoc 2 [2,3,4] :: [Nat]
--   = '[2, 3, 5]
--   
-- | Append the second tensor dims1 to the first tensor -- dims0 along axis. -- --
--   >>> append @0 (enumFromN @[2,3,4] 0) (enumFromStepN @[2,3,4] @Int (-1) (-1))
--   Tensor'4'3'4 [[[   0,   1,   2,   3]
--                 ,[   4,   5,   6,   7]
--                 ,[   8,   9,  10,  11]]
--                ,[[  12,  13,  14,  15]
--                 ,[  16,  17,  18,  19]
--                 ,[  20,  21,  22,  23]]
--                ,[[  -1,  -2,  -3,  -4]
--                 ,[  -5,  -6,  -7,  -8]
--                 ,[  -9, -10, -11, -12]]
--                ,[[ -13, -14, -15, -16]
--                 ,[ -17, -18, -19, -20]
--                 ,[ -21, -22, -23, -24]]]
--   
-- --
--   >>> append @1 (enumFromN @[2,3,4] 0) (enumFromStepN @[2,3,4] @Int (-1) (-1))
--   Tensor'2'6'4 [[[   0,   1,   2,   3]
--                 ,[   4,   5,   6,   7]
--                 ,[   8,   9,  10,  11]
--                 ,[  -1,  -2,  -3,  -4]
--                 ,[  -5,  -6,  -7,  -8]
--                 ,[  -9, -10, -11, -12]]
--                ,[[  12,  13,  14,  15]
--                 ,[  16,  17,  18,  19]
--                 ,[  20,  21,  22,  23]
--                 ,[ -13, -14, -15, -16]
--                 ,[ -17, -18, -19, -20]
--                 ,[ -21, -22, -23, -24]]]
--   
--   >>> append @2 (enumFromN @[2,3,4] 0) (enumFromStepN @[2,3,4] @Int (-1) (-1))
--   Tensor'2'3'8 [[[   0,   1,   2,   3,  -1,  -2,  -3,  -4]
--                 ,[   4,   5,   6,   7,  -5,  -6,  -7,  -8]
--                 ,[   8,   9,  10,  11,  -9, -10, -11, -12]]
--                ,[[  12,  13,  14,  15, -13, -14, -15, -16]
--                 ,[  16,  17,  18,  19, -17, -18, -19, -20]
--                 ,[  20,  21,  22,  23, -21, -22, -23, -24]]]
--   
append :: forall (axis :: Nat) (dims0 :: [Nat]) (dims1 :: [Nat]) e. (Append axis dims0 dims1 e) => Tensor dims0 e -> Tensor dims1 e -> Tensor (DimsAfterAppend axis dims0 dims1) e -- | Constraints for append. type Append (axis :: Nat) (dims0 :: [Nat]) (dims1 :: [Nat]) e = (SetSlice (AppendFstTensorStartingIndex dims0) dims0 (DimsAfterAppend axis dims0 dims1) e, SetSlice (AppendSndTensorStartingIndex axis dims1) dims1 (DimsAfterAppend axis dims0 dims1) e, dims0 ~ NormalizeDims dims0, dims1 ~ NormalizeDims dims1, Fill (DimsAfterAppend axis dims0 dims1) e) -- | Shape of the tensor after appending -- --
--   >>> :kind! DimsAfterAppend 0 [2,3,4] [5,3,4]
--   DimsAfterAppend 0 [2,3,4] [5,3,4] :: [Nat]
--   = '[7, 3, 4]
--   
-- --
--   >>> :kind! DimsAfterAppend 1 [2,3,4] [2,5,4]
--   DimsAfterAppend 1 [2,3,4] [2,5,4] :: [Nat]
--   = '[2, 8, 4]
--   
-- --
--   >>> :kind! DimsAfterAppend 2 [2,3,4] [2,3,5]
--   DimsAfterAppend 2 [2,3,4] [2,3,5] :: [Nat]
--   = '[2, 3, 9]
--   
type DimsAfterAppend (axis :: Nat) (dims0 :: [Nat]) (dims1 :: [Nat]) = DimsAfterAppend' axis dims0 dims1 0 -- | Remove a slice from the tensor. We can only remove slices which have -- one dimension fewer than the tensor, and which span from borders of -- the tensor to opposite borders of the tensor (i.e. contain all -- elements of the tensor in their dimensions). -- -- axis is the index of dimension in dims -- indexOnAxis is offset along axis that points to the -- slice to be removed. -- -- For example, suppose we have tensor t :: Tensor '[2,3,4] -- Float that is, tensor made of two matrices of 3*4 elements. -- -- If we want to remove first matrix we write remove @0 @0 t, if -- second - remove @0 @1 t. -- -- If we want to remove n-th row in all matrices we write remove @1 -- @n t. -- -- If we want to remove n-th column in all matrices we write remove -- @2 @n t. -- --
--   >>> let t = enumFromN @[2,3,4] @Int 0
--   
--   >>> t
--   Tensor'2'3'4 [[[ 0, 1, 2, 3]
--                 ,[ 4, 5, 6, 7]
--                 ,[ 8, 9,10,11]]
--                ,[[12,13,14,15]
--                 ,[16,17,18,19]
--                 ,[20,21,22,23]]]
--   
--   >>> remove @0 @0 t
--   Tensor'1'3'4 [[[12,13,14,15]
--                 ,[16,17,18,19]
--                 ,[20,21,22,23]]]
--   
--   >>> remove @1 @0 t
--   Tensor'2'2'4 [[[ 4, 5, 6, 7]
--                 ,[ 8, 9,10,11]]
--                ,[[16,17,18,19]
--                 ,[20,21,22,23]]]
--   
--   >>> remove @2 @0 t
--   Tensor'2'3'3 [[[ 1, 2, 3]
--                 ,[ 5, 6, 7]
--                 ,[ 9,10,11]]
--                ,[[13,14,15]
--                 ,[17,18,19]
--                 ,[21,22,23]]]
--   
remove :: forall (axis :: Nat) (indexOnAxis :: Nat) (dims :: [Nat]) e. (Remove axis indexOnAxis dims e) => Tensor dims e -> Tensor (DimsAfterRemove axis indexOnAxis dims) e -- | Constraints for remove. type Remove (axis :: Nat) (indexOnAxis :: Nat) (dims :: [Nat]) e = (IsTensor dims e, IsTensor (DimsAfterRemove axis indexOnAxis dims) e, RemoveWrk (ElemsInSlice (RemoveSliceStartIndex axis indexOnAxis dims) (RemoveSliceDims axis indexOnAxis dims) dims)) -- | Shape of a tensor dims after removing a slice at -- index along axis. -- --
--   >>> :kind! DimsAfterRemove 0 0 [2,3,4]
--   DimsAfterRemove 0 0 [2,3,4] :: [Nat]
--   = '[1, 3, 4]
--   
-- --
--   >>> :kind! DimsAfterRemove 1 0 [2,3,4]
--   DimsAfterRemove 1 0 [2,3,4] :: [Nat]
--   = '[2, 2, 4]
--   
-- --
--   >>> :kind! DimsAfterRemove 2 0 [2,3,4]
--   DimsAfterRemove 2 0 [2,3,4] :: [Nat]
--   = '[2, 3, 3]
--   
-- | Nested list of given depth. -- --
--   >>> :kind! NestedList 3 Float
--   [[[Float]]]
--   
-- --
--   >>> :kind! NestedList 2 Float
--   [[Float]]
--   
-- | Convert tensor to nested list. toNestedList :: forall dims e. (ToNestedList dims e) => Tensor dims e -> NestedList (Length dims) e -- | Constraints for toNestedList function. type ToNestedList (dims :: [Nat]) e = (IsTensor dims e, ToNestedListWrk dims e) -- | Lens for an element of a tensor. -- --
--   >>> let t = enumFromN @[2,3,4] @Int 0
--   
--   >>> t
--   Tensor'2'3'4 [[[  0,  1,  2,  3]
--                 ,[  4,  5,  6,  7]
--                 ,[  8,  9, 10, 11]]
--                ,[[ 12, 13, 14, 15]
--                 ,[ 16, 17, 18, 19]
--                 ,[ 20, 21, 22, 23]]]
--   
--   >>> t ^. tensorElem @[1,1,1]
--   17
--   
--   >>> set (tensorElem @[1,1,1]) 0 t
--   Tensor'2'3'4 [[[  0,  1,  2,  3]
--                 ,[  4,  5,  6,  7]
--                 ,[  8,  9, 10, 11]]
--                ,[[ 12, 13, 14, 15]
--                 ,[ 16,  0, 18, 19]
--                 ,[ 20, 21, 22, 23]]]
--   
tensorElem :: forall (index :: [Nat]) (dims :: [Nat]) e. (TensorElem index dims e) => Lens' (Tensor dims e) e -- | Constraint for tensorElem function. type TensorElem index dims e = (SubtensorCtx index dims e, NormalizeDims (SubtensorDims index dims) ~ '[]) -- | Subtensor at index of a tensor of shape dims. -- --
--   >>> :kind! Subtensor '[] '[2,3,4] Float
--   Subtensor '[] '[2,3,4] Float :: *
--   = Tensor '[2, 3, 4] Float
--   
-- --
--   >>> :kind! Subtensor '[0] '[2,3,4] Float
--   Subtensor '[0] '[2,3,4] Float :: *
--   = Tensor '[3, 4] Float
--   
-- --
--   >>> :kind! Subtensor '[0,0] '[2,3,4] Float
--   Subtensor '[0,0] '[2,3,4] Float :: *
--   = Tensor '[4] Float
--   
-- --
--   >>> :kind! Subtensor '[0,0,0] '[2,3,4] Float
--   Subtensor '[0,0,0] '[2,3,4] Float :: *
--   = Tensor '[] Float
--   
type Subtensor index dims e = Tensor (NormalizeDims (SubtensorDims index dims)) e -- | Index of the first element of the subtensor of the tensor of shape -- dims at index. This function returns index with -- number of dimensions equal to number of dimensions of the tensor. -- --
--   >>> :kind! SubtensorStartIndex '[1] '[2,3,4]
--   SubtensorStartIndex '[1] '[2,3,4] :: [Nat]
--   = '[1, 0, 0]
--   
-- --
--   >>> :kind! SubtensorStartIndex '[0,1] '[2,3,4]
--   SubtensorStartIndex '[0,1] '[2,3,4] :: [Nat]
--   = '[0, 1, 0]
--   
-- --
--   >>> :kind! SubtensorStartIndex '[1,1] '[2,3,4]
--   SubtensorStartIndex '[1,1] '[2,3,4] :: [Nat]
--   = '[1, 1, 0]
--   
-- | Shape of a subtensor of tensor of shape dims located at -- index. Resulting shape is not normalized. -- --
--   >>> :kind! SubtensorDims '[0] '[2,3,4]
--   SubtensorDims '[0] '[2,3,4] :: [Nat]
--   = '[1, 3, 4]
--   
-- --
--   >>> :kind! SubtensorDims '[0,0] '[2,3,4]
--   SubtensorDims '[0,0] '[2,3,4] :: [Nat]
--   = '[1, 1, 4]
--   
-- | Lens for subtensor at given index. -- --
--   >>> let t = enumFromN @[2,3,4] @Int 0
--   
--   >>> t
--   Tensor'2'3'4 [[[  0,  1,  2,  3]
--                 ,[  4,  5,  6,  7]
--                 ,[  8,  9, 10, 11]]
--                ,[[ 12, 13, 14, 15]
--                 ,[ 16, 17, 18, 19]
--                 ,[ 20, 21, 22, 23]]]
--   
--   >>> t ^. subtensor @'[0]
--   Tensor'3'4    [[  0,  1,  2,  3]
--                 ,[  4,  5,  6,  7]
--                 ,[  8,  9, 10, 11]]
--   
--   >>> t ^. subtensor @'[1]
--   Tensor'3'4    [[ 12, 13, 14, 15]
--                 ,[ 16, 17, 18, 19]
--                 ,[ 20, 21, 22, 23]]
--   
--   >>> t ^. subtensor @'[0,0]
--   Tensor'4       [  0,  1,  2,  3]
--   
--   >>> t ^. subtensor @'[1,0]
--   Tensor'4       [ 12, 13, 14, 15]
--   
subtensor :: forall (index :: [Nat]) (dims :: [Nat]) e. (SubtensorCtx index dims e) => Lens' (Tensor dims e) (Subtensor index dims e) -- | Constraint for subtensor function. type SubtensorCtx index dims e = (GetSubtensor index dims e, SetSubtensor index dims e) -- | Extract subtensor at given index. getSubtensor :: forall (index :: [Nat]) (dims :: [Nat]) e. (GetSubtensor index dims e) => Tensor dims e -> Subtensor index dims e -- | Constraint for getSubtensor function. type GetSubtensor index dims e = (GetSlice (SubtensorStartIndex index dims) (SubtensorDims index dims) dims e) -- | Extract elements of subtensor at given index. Like -- getSubtensor, but without building actual subtensor. getSubtensorElems :: forall (index :: [Nat]) (dims :: [Nat]) e. (GetSubtensorElems index dims e) => Tensor dims e -> [e] -- | Constraint for getSubtensorElems function. type GetSubtensorElems index dims e = GetSliceElems (SubtensorStartIndex index dims) (SubtensorDims index dims) dims e -- | Set subtensor at given index. setSubtensor :: forall (index :: [Nat]) (dims :: [Nat]) e. (SetSubtensor index dims e) => Tensor dims e -> Subtensor index dims e -> Tensor dims e -- | Constraint for setSubtensor function. type SetSubtensor index dims e = SetSlice (SubtensorStartIndex index dims) (SubtensorDims index dims) dims e -- | Like setSubtensor but takes a list of elements instead of a -- tensor. Returns Nothing if list has not enough elements. setSubtensorElems :: forall (index :: [Nat]) (dims :: [Nat]) e. (SetSubtensorElems index dims e) => Tensor dims e -> [e] -> Maybe (Tensor dims e) -- | Constraint for setSubtensorElems function. type SetSubtensorElems index dims e = SetSliceElems (SubtensorStartIndex index dims) (SubtensorDims index dims) dims e -- | Modify subtensor elements with a function. mapSubtensorElems :: forall (index :: [Nat]) (dims :: [Nat]) e. (MapSubtensorElems index dims e) => Tensor dims e -> (e -> e) -> Tensor dims e -- | Constraints for mapSubtensorElems. type MapSubtensorElems index dims e = MapSliceElems (SubtensorStartIndex index dims) (SubtensorDims index dims) dims e -- | Index of the end of the slice of the tensor. startIndex -- parameter is the starting index of the slice, sliceDims is -- the shape of the slice, dims is the shape of the tensor. The -- slice must be contained inside the tensor. All dimensions of the slice -- must be positive. startIndex, sliceDims and -- dims must have the same length. If you want to get slice of -- lower rank than the tensor's, set one or more dimensions in -- sliceDims to 1. -- --
--   >>> :kind! SliceEndIndex '[0,0,0] '[2,2,2] '[2,3,4]
--   SliceEndIndex '[0,0,0] '[2,2,2] '[2,3,4] :: [Nat]
--   = '[1, 1, 1]
--   
-- --
--   >>> :kind! SliceEndIndex '[1,1,0] '[1,2,4] '[2,3,4]
--   SliceEndIndex '[1,1,0] '[1,2,4] '[2,3,4] :: [Nat]
--   = '[1, 2, 3]
--   
-- | Check each element of the tensor of shape dims if it is -- inside the slice from startIndex of shape sliceDims. -- The slice must be contained inside the tensor. All dimensions of the -- slice must be positive. startIndex, sliceDims and -- dims must have the same length. -- --
--   >>> :kind! ElemsInSlice '[0,0,0] '[2,2,2] '[2,3,4]
--   ElemsInSlice '[0,0,0] '[2,2,2] '[2,3,4] :: [Bool]
--   = '['True, 'True, 'False, 'False, 'True, 'True, 'False, 'False,
--       'False, 'False, 'False, 'False, 'True, 'True, 'False, 'False,
--       'True, 'True, 'False, 'False, 'False, 'False, 'False, 'False]
--   
-- --
--   >>> :kind! ElemsInSlice '[1,1,0] '[1,2,4] '[2,3,4]
--   ElemsInSlice '[1,1,0] '[1,2,4] '[2,3,4] :: [Bool]
--   = '['False, 'False, 'False, 'False, 'False, 'False, 'False, 'False,
--       'False, 'False, 'False, 'False, 'False, 'False, 'False, 'False,
--       'True, 'True, 'True, 'True, 'True, 'True, 'True, 'True]
--   
type ElemsInSlice (startIndex :: [Nat]) (sliceDims :: [Nat]) (dims :: [Nat]) = ElemsInSlice' startIndex (SliceEndIndex startIndex sliceDims dims) (AllIndexes dims) -- | Lens for the slice starting from startIndex of shape -- sliceDims of the tensor of shape dims. -- --
--   >>> let t = (enumFromN @[2,3,4] @Int 0)
--   
--   >>> t
--   Tensor'2'3'4 [[[  0,  1,  2,  3]
--                 ,[  4,  5,  6,  7]
--                 ,[  8,  9, 10, 11]]
--                ,[[ 12, 13, 14, 15]
--                 ,[ 16, 17, 18, 19]
--                 ,[ 20, 21, 22, 23]]]
--   
--   >>> t ^. slice @[0,0,0] @[2,2,2]
--   Tensor'2'2'2 [[[  0,  1]
--                 ,[  4,  5]]
--                ,[[ 12, 13]
--                 ,[ 16, 17]]]
--   
--   >>> set (slice @[0,0,0] @[2,2,2]) zero t
--   Tensor'2'3'4 [[[  0,  0,  2,  3]
--                 ,[  0,  0,  6,  7]
--                 ,[  8,  9, 10, 11]]
--                ,[[  0,  0, 14, 15]
--                 ,[  0,  0, 18, 19]
--                 ,[ 20, 21, 22, 23]]]
--   
slice :: forall startIndex sliceDims dims e. (Slice startIndex sliceDims dims e) => Lens' (Tensor dims e) (Tensor (NormalizeDims sliceDims) e) -- | Constraints for slice function. type Slice startIndex sliceDims dims e = (IsTensor dims e, IsTensor (NormalizeDims sliceDims) e, GetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims), SetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims)) -- | Extract slice of shape sliceDims from a tensor of shape -- dims starting at startIndex for each axis. getSlice :: forall startIndex sliceDims dims e. (GetSlice startIndex sliceDims dims e) => Tensor dims e -> Tensor (NormalizeDims sliceDims) e -- | Constraints for getSlice. type GetSlice startIndex sliceDims dims e = (IsTensor dims e, IsTensor (NormalizeDims sliceDims) e, GetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims)) -- | Same as slice but returns list of elements instead of tensor data -- type. getSliceElems :: forall startIndex sliceDims dims e. (GetSliceElems startIndex sliceDims dims e) => Tensor dims e -> [e] -- | Constraints for getSliceElems. type GetSliceElems startIndex sliceDims dims e = (IsTensor dims e, GetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims)) -- | Set elements of the slice. setSlice :: forall startIndex sliceDims dims e. (SetSlice startIndex sliceDims dims e) => Tensor dims e -> Tensor (NormalizeDims sliceDims) e -> Tensor dims e -- | Constraints for setSlice. type SetSlice startIndex sliceDims dims e = (IsTensor dims e, IsTensor (NormalizeDims sliceDims) e, SetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims)) -- | Like setSlice but takes a list of elements instead of a tensor. -- Returns Nothing if list has less than ElemsNumber -- sliceDims elements. setSliceElems :: forall startIndex sliceDims dims e. (SetSliceElems startIndex sliceDims dims e) => Tensor dims e -> [e] -> Maybe (Tensor dims e) -- | Constraints for setSliceElems. type SetSliceElems startIndex sliceDims dims e = (IsTensor dims e, SetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims)) -- | Modify slice elements with a function. mapSliceElems :: forall startIndex sliceDims dims e. (MapSliceElems startIndex sliceDims dims e) => Tensor dims e -> (e -> e) -> Tensor dims e -- | Constraints for mapSliceElems. type MapSliceElems startIndex sliceDims dims e = (IsTensor dims e, GetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims), SetSliceElemsWrk (ElemsInSlice startIndex sliceDims dims), Map (ElemsNumber sliceDims)) -- | Constraints for MonoFunctor instance for Tensor dims -- e. type MonoFunctorCtx (dims :: [Nat]) e = (IsTensor dims e, Map (ElemsNumber dims)) -- | Constraints for MonoFoldable instance for Tensor -- dims e. type MonoFoldableCtx (dims :: [Nat]) e = (IsTensor dims e, Foldr (ElemsNumber dims), Foldl (ElemsNumber dims), Foldr1 (ElemsNumber dims), Foldl1 (ElemsNumber dims)) -- | Constraints for MonoTraversable instance for Tensor -- dims e. type MonoTraversableCtx (dims :: [Nat]) e = (IsTensor dims e, Map (ElemsNumber dims), Foldr (ElemsNumber dims), Foldl (ElemsNumber dims), Foldr1 (ElemsNumber dims), Foldl1 (ElemsNumber dims)) -- | Constraints for MonoZip instance for Tensor dims -- e. type MonoZipCtx (dims :: [Nat]) e = (IsTensor dims e, Map (ElemsNumber dims), ZipWith (ElemsNumber dims), Zip (ElemsNumber dims), Unzip (ElemsNumber dims)) -- | Pass a pointer to the tensor's data to the IO action. The data may not -- be modified through the 'Ptr. Pointer may not be used after action is -- complete. unsafeWithTensorPtr :: (IsTensor dims e, Storable e, KnownNat (ElemsNumber dims)) => Tensor dims e -> (Ptr e -> IO a) -> IO a instance Data.Tensor.Static.MonoZipCtx dims e => Data.Containers.MonoZip (Data.Tensor.Static.Tensor dims e) instance Data.Tensor.Static.MonoTraversableCtx dims e => Data.MonoTraversable.MonoTraversable (Data.Tensor.Static.Tensor dims e) instance Data.Tensor.Static.MonoFoldableCtx dims e => Data.MonoTraversable.MonoFoldable (Data.Tensor.Static.Tensor dims e) instance Data.Tensor.Static.MonoFunctorCtx dims e => Data.MonoTraversable.MonoFunctor (Data.Tensor.Static.Tensor dims e) instance Data.Tensor.Static.RemoveWrk '[] instance Data.Tensor.Static.RemoveWrk xs => Data.Tensor.Static.RemoveWrk ('GHC.Types.False : xs) instance Data.Tensor.Static.RemoveWrk xs => Data.Tensor.Static.RemoveWrk ('GHC.Types.True : xs) instance Data.Tensor.Static.SetSliceElemsWrk '[] instance Data.Tensor.Static.SetSliceElemsWrk xs => Data.Tensor.Static.SetSliceElemsWrk ('GHC.Types.True : xs) instance Data.Tensor.Static.SetSliceElemsWrk xs => Data.Tensor.Static.SetSliceElemsWrk ('GHC.Types.False : xs) instance Data.Tensor.Static.GetSliceElemsWrk '[] instance Data.Tensor.Static.GetSliceElemsWrk xs => Data.Tensor.Static.GetSliceElemsWrk ('GHC.Types.True : xs) instance Data.Tensor.Static.GetSliceElemsWrk xs => Data.Tensor.Static.GetSliceElemsWrk ('GHC.Types.False : xs) instance (GHC.Show.Show (Data.Tensor.Static.NestedList (Data.Singletons.Prelude.List.Length dims) e), Data.Tensor.Static.IsTensor dims e, Data.Tensor.Static.ToNestedListWrk dims e, Type.List.KnownNats dims) => GHC.Show.Show (Data.Tensor.Static.Tensor dims e) instance Data.Tensor.Static.ToNestedListWrk '[] e instance Data.Tensor.Static.ToNestedListWrk '[x] e instance (Data.Tensor.Static.ToNestedListWrk (xx : xs) e, GHC.TypeNats.KnownNat (Data.Singletons.Prelude.List.Product (xx : xs)), Data.Tensor.Static.NestedList (Data.Singletons.Prelude.List.Length (x : xx : xs)) e ~ [Data.Tensor.Static.NestedList (Data.Singletons.Prelude.List.Length (xx : xs)) e]) => Data.Tensor.Static.ToNestedListWrk (x : xx : xs) e instance Data.Tensor.Static.IsTensor '[] e instance GHC.Show.Show e => GHC.Show.Show (Data.Tensor.Static.Tensor '[] e) instance (Data.Tensor.Static.IsTensor dims a, Data.Tensor.Static.IsTensor dims b) => Control.Lens.Each.Each (Data.Tensor.Static.Tensor dims a) (Data.Tensor.Static.Tensor dims b) a b instance (Data.Tensor.Static.IsTensor dims e, Foreign.Storable.Storable e, GHC.TypeNats.KnownNat (Data.Tensor.Static.ElemsNumber dims)) => Foreign.Storable.Storable (Data.Tensor.Static.Tensor dims e) module Data.Tensor.Static.TH -- | Generate instance for tensor and lenses for its elements. genTensorInstance :: NonEmpty Int -> Name -> Q [Dec] module Data.Vector.Static -- | N-dimensional vector. type Vector n e = Tensor '[n] e -- | Type of vector data constructor. type VectorConstructor n e = TensorConstructor '[n] e -- | Vector constraint. type IsVector n e = IsTensor '[n] e -- | Alias for a conrete vector data constructor. vector :: forall n e. (IsVector n e) => VectorConstructor n e -- | Normalize vector. normalize :: (Normalize n e) => Vector n e -> NormalizedVector n e -- | Normalized vector. data NormalizedVector n e -- | Constraints for normalize function. type Normalize (n :: Nat) e = (VectorLen n e, Scale '[n] e) -- | unwrap NormalizedVector. Note: this does not give you original -- vector back. -- --
--   unNormalizedVector . normalize /= id
--   
unNormalizedVector :: NormalizedVector n e -> Vector n e -- | Get square of length of a vector. vectorLenSquare :: (VectorLenSquare n e) => Vector n e -> e -- | Constraints for vectorLenSquare function. type VectorLenSquare (n :: Nat) e = (Num e, IsVector n e, MonoFunctorCtx '[n] e, MonoFoldableCtx '[n] e) -- | Get length of a vector. vectorLen :: (VectorLen n e) => Vector n e -> e -- | Constraints for vectorLen function. type VectorLen (n :: Nat) e = (Floating e, VectorLenSquare n e) -- | Dot product of two vectors. dot :: (Dot n e) => Vector n e -> Vector n e -> e -- | Constraints for dot function. type Dot (n :: Nat) e = (Num e, IsVector n e, MonoFunctorCtx '[n] e, MonoFoldableCtx '[n] e, MonoZipCtx '[n] e) -- | Cross product is only defined for 3-dimensional vectors. cross :: (Num e, IsVector 3 e) => Vector 3 e -> Vector 3 e -> Vector 3 e -- | Generate instance of a vector. genVectorInstance :: Int -> Name -> Q [Dec] instance GHC.Generics.Generic (Data.Vector.Static.NormalizedVector n e) instance GHC.Classes.Eq (Data.Vector.Static.Vector n e) => GHC.Classes.Eq (Data.Vector.Static.NormalizedVector n e) instance GHC.Show.Show (Data.Vector.Static.Vector n e) => GHC.Show.Show (Data.Vector.Static.NormalizedVector n e) module Data.Matrix.Static -- | Matrix with m rows, n columns type Matrix m n e = Tensor '[m, n] e -- | Type of matrix data constructor. type MatrixConstructor m n e = TensorConstructor '[m, n] e -- | Matrix constraint. type IsMatrix m n e = IsTensor '[m, n] e -- | Alias for a conrete matrix data constructor. matrix :: forall m n e. (IsMatrix m n e) => MatrixConstructor m n e -- | Identity matrix of size m*m identity :: forall m e. (IsMatrix m m e, Generate '[m, m] e ([Nat] -> Constraint) (IdentityWrk e), Num e) => Matrix m m e -- | Constraints for identity function. type Identity m e = (IsMatrix m m e, Generate '[m, m] e ([Nat] -> Constraint) (IdentityWrk e), Num e) -- | Lens for the row number r of the matrix -- mxn. -- --
--   >>> matrix @2 @2 @Float 0 1 2 3 ^. row @0
--   Tensor'2 [0.0,1.0]
--   
-- --
--   >>> set (row @1) (vector @2 @Float 20 30) (matrix @2 @2 @Float 0 1 2 3)
--   Tensor'2'2 [[0.0,1.0],[20.0,30.0]]
--   
row :: forall (r :: Nat) (m :: Nat) (n :: Nat) e. (Row r m n e) => Lens' (Matrix m n e) (Vector n e) -- | Constraints for row function. type Row (r :: Nat) (m :: Nat) (n :: Nat) e = (SubtensorCtx '[r] '[m, n] e, r <= (m - 1), NormalizeDims '[n] ~ '[n]) -- | List of elements of the row number r of the matrix -- mxn. -- --
--   >>> getRowElems @0 (matrix @2 @2 @Float 0 1 2 3)
--   [0.0,1.0]
--   
getRowElems :: forall (r :: Nat) (m :: Nat) (n :: Nat) e. (GetRowElems r m n e) => Matrix m n e -> [e] -- | Constraints for getRowElems function. type GetRowElems (r :: Nat) (m :: Nat) (n :: Nat) e = GetSubtensorElems '[r] '[m, n] e -- | Put elements of the list into row number r. The list must -- have enough elements. -- --
--   >>> setRowElems @1 (matrix @2 @2 @Float 0 1 2 3) [20, 30]
--   Just Tensor'2'2 [[0.0,1.0],[20.0,30.0]]
--   
-- --
--   >>> setRowElems @1 (matrix @2 @2 @Float 0 1 2 3) [20]
--   Nothing
--   
setRowElems :: forall (r :: Nat) (m :: Nat) (n :: Nat) e. (SetRowElems r m n e) => Matrix m n e -> [e] -> Maybe (Matrix m n e) -- | Constraints for setRowElems function. type SetRowElems (r :: Nat) (m :: Nat) (n :: Nat) e = SetSubtensorElems '[r] '[m, n] e -- | Apply a function to all elements of the row number r. -- --
--   >>> mapRowElems @1 (matrix @2 @2 @Float 0 1 2 3) (* 100)
--   Tensor'2'2 [[0.0,1.0],[200.0,300.0]]
--   
mapRowElems :: forall (r :: Nat) (m :: Nat) (n :: Nat) e. (MapRowElems r m n e) => Matrix m n e -> (e -> e) -> Matrix m n e -- | Constraints for mapRowElems function. type MapRowElems (r :: Nat) (m :: Nat) (n :: Nat) e = MapSubtensorElems '[r] '[m, n] e -- | Lens for the column number c of the matrix -- mxn. -- --
--   >>> matrix @2 @2 @Float 0 1 2 3 ^. col @0
--   Tensor'2 [0.0,2.0]
--   
-- --
--   >>> set (col @1) (vector @2 @Float 10 30) (matrix @2 @2 @Float 0 1 2 3)
--   Tensor'2'2 [[0.0,10.0],[2.0,30.0]]
--   
col :: forall (c :: Nat) (m :: Nat) (n :: Nat) e. (Col c m n e) => Lens' (Matrix m n e) (Vector m e) -- | Constraints for col function. type Col (c :: Nat) (m :: Nat) (n :: Nat) e = (Slice '[0, c] '[m, 1] '[m, n] e, NormalizeDims '[m, 1] ~ '[m]) -- | List of elements of the column number c of the matrix -- mxn. -- --
--   >>> getColElems @0 (matrix @2 @2 @Float 0 1 2 3)
--   [0.0,2.0]
--   
getColElems :: forall (c :: Nat) (m :: Nat) (n :: Nat) e. (GetColElems c m n e) => Matrix m n e -> [e] -- | Constraints for getColElems function. type GetColElems (c :: Nat) (m :: Nat) (n :: Nat) e = GetSliceElems '[0, c] '[m, 1] '[m, n] e -- | Put elements of the list into column number r. The list must -- have enough elements. -- --
--   >>> setColElems @1 (matrix @2 @2 @Float 0 1 2 3) [10, 30]
--   Just Tensor'2'2 [[0.0,10.0],[2.0,30.0]]
--   
-- --
--   >>> setColElems @1 (matrix @2 @2 @Float 0 1 2 3) [10]
--   Nothing
--   
setColElems :: forall (c :: Nat) (m :: Nat) (n :: Nat) e. (SetColElems c m n e) => Matrix m n e -> [e] -> Maybe (Matrix m n e) -- | Constraints for setColElems function. type SetColElems (c :: Nat) (m :: Nat) (n :: Nat) e = SetSliceElems '[0, c] '[m, 1] '[m, n] e -- | Apply a function to all elements of the column number c. -- --
--   >>> mapColElems @1 (matrix @2 @2 @Float 0 1 2 3) (* 100)
--   Tensor'2'2 [[0.0,100.0],[2.0,300.0]]
--   
mapColElems :: forall (c :: Nat) (m :: Nat) (n :: Nat) e. (MapColElems c m n e) => Matrix m n e -> (e -> e) -> Matrix m n e -- | Constraints for mapColElems function. type MapColElems (c :: Nat) (m :: Nat) (n :: Nat) e = MapSliceElems '[0, c] '[m, 1] '[m, n] e -- | Shape of the result of matrix multiplication. -- | Matrix multiplication. class MatrixMult (dims0 :: [Nat]) (dims1 :: [Nat]) e -- | Multiply two matrices, or matrix and vector. Matrices (or matrix and -- vector) must have compatible dimensions. mult :: (MatrixMult dims0 dims1 e, IsTensor dims0 e, IsTensor dims1 e, IsTensor (MatrixMultDims dims0 dims1) e) => Tensor dims0 e -> Tensor dims1 e -> Tensor (MatrixMultDims dims0 dims1) e -- | Transpose a matrix. transpose :: forall m n e. (Transpose m n e) => Matrix m n e -> Matrix n m e -- | Constraints for transpose function. type Transpose m n e = (IsMatrix m n e, IsMatrix n m e, Generate '[n, m] e ([Nat] ~> Constraint) (TransposeGoSym3 m n e)) -- | Minor matrix is a matrix made by deleting i-th row and -- j-th column from given square matrix. minorMatrix :: forall (i :: Nat) (j :: Nat) (n :: Nat) e. (Generate ([n - 1, n - 1]) e ([Nat] ~> Constraint) (MinorMatrixGoSym4 i j n e)) => Matrix n n e -> Matrix (n - 1) (n - 1) e -- | Constraint for minorMatrix function. type MinorMatrix (i :: Nat) (j :: Nat) (n :: Nat) e = Generate ([n - 1, n - 1]) e ([Nat] ~> Constraint) (MinorMatrixGoSym4 i j n e) -- | Determinant of a matrix. class Determinant (n :: Nat) e determinant :: (Determinant n e, (Num e)) => Matrix n n e -> e -- | Minor is the determinant of minor matrix. minor :: forall (i :: Nat) (j :: Nat) (n :: Nat) e. (Minor i j n e) => Matrix n n e -> e -- | Constraint for minor function. type Minor (i :: Nat) (j :: Nat) (n :: Nat) e = (MinorMatrix i j n e, Determinant (n - 1) e, Num e) -- | cofactor @i @j is the minor @i @j -- multiplied by (-1) ^ (i + j). cofactor :: forall (i :: Nat) (j :: Nat) (n :: Nat) e. (Cofactor i j n e) => Matrix n n e -> e -- | Constraint for cofactor function. type Cofactor (i :: Nat) (j :: Nat) (n :: Nat) e = (Minor i j n e, Sign (i + j)) -- | The matrix formed by all of the cofactors of given square matrix. cofactorMatrix :: forall (n :: Nat) e. (CofactorMatrix n e) => Matrix n n e -> Matrix n n e -- | Constraint for cofactorMatrix function. type CofactorMatrix (n :: Nat) e = Generate [n, n] e ([Nat] ~> Constraint) (CofactorMatrixGoSym2 n e) -- | Adjugate matrix of given square matrix is the transpose of its -- cofactor matrix. -- --
--   adjugateMatrix = transpose . cofactorMatrix
--   
adjugateMatrix :: forall (n :: Nat) e. (AdjugateMatrix n e) => Matrix n n e -> Matrix n n e -- | Constraint for adjugateMatrix function. type AdjugateMatrix (n :: Nat) e = (CofactorMatrix n e, Transpose n n e) -- | Inverse of the matrix. inverse :: forall (n :: Nat) e. (Inverse n e) => Matrix n n e -> Matrix n n e -- | Constraint for inverse function. type Inverse (n :: Nat) e = (AdjugateMatrix n e, Determinant n e, Fractional e, Scale '[n, n] e) -- | Generate instance of a matrix. genMatrixInstance :: Int -> Int -> Name -> Q [Dec] instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.CofactorMatrixGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.CofactorMatrixGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.CofactorMatrixGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.DeterminantGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.DeterminantGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.DeterminantGoSym2 instance (GHC.Num.Num e, Data.Matrix.Static.IsMatrix n n e, Type.List.DemoteWith GHC.Types.Nat (GHC.Types.Nat Data.Singletons.~> GHC.Types.Constraint) (Data.Matrix.Static.DeterminantGoSym2 n e) (Data.Tensor.Static.NatsFromTo 0 (n GHC.TypeNats.- 1)), Data.List.Unrolled.Sum n e) => Data.Matrix.Static.Determinant n e instance Data.Matrix.Static.Sign 0 instance Data.Matrix.Static.Sign (n GHC.TypeNats.- 1) => Data.Matrix.Static.Sign n instance (GHC.Num.Num e, Data.Matrix.Static.IsMatrix 2 2 e) => Data.Matrix.Static.Determinant 2 e instance (GHC.Num.Num e, Data.Matrix.Static.IsMatrix 3 3 e) => Data.Matrix.Static.Determinant 3 e instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MinorMatrixGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MinorMatrixGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MinorMatrixGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MinorMatrixGoSym3 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MinorMatrixGoSym4 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatVecGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatVecGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatVecGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatVecGoSym3 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatVecGoSym4 instance (GHC.Num.Num e, Data.Tensor.Static.Generate (Data.Matrix.Static.MatrixMultDims '[m, n] '[n]) e ([GHC.Types.Nat] Data.Singletons.~> GHC.Types.Constraint) (Data.Matrix.Static.MultMatVecGoSym4 m n o e)) => Data.Matrix.Static.MatrixMult '[m, n] '[n] e instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultVecMatGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultVecMatGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultVecMatGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultVecMatGoSym3 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultVecMatGoSym4 instance (GHC.Num.Num e, Data.Tensor.Static.Generate (Data.Matrix.Static.MatrixMultDims '[n] '[n, o]) e ([GHC.Types.Nat] Data.Singletons.~> GHC.Types.Constraint) (Data.Matrix.Static.MultVecMatGoSym4 m n o e)) => Data.Matrix.Static.MatrixMult '[n] '[n, o] e instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatMatGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatMatGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatMatGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatMatGoSym3 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.MultMatMatGoSym4 instance (GHC.Num.Num e, Data.Tensor.Static.Generate (Data.Matrix.Static.MatrixMultDims '[m, n] '[n, o]) e ([GHC.Types.Nat] Data.Singletons.~> GHC.Types.Constraint) (Data.Matrix.Static.MultMatMatGoSym4 m n o e)) => Data.Matrix.Static.MatrixMult '[m, n] '[n, o] e instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.TransposeGoSym0 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.TransposeGoSym1 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.TransposeGoSym2 instance Data.Singletons.SuppressUnusedWarnings.SuppressUnusedWarnings Data.Matrix.Static.TransposeGoSym3 instance GHC.Num.Num e => Data.Matrix.Static.IdentityWrk e '[i, j] instance GHC.Num.Num e => Data.Matrix.Static.IdentityWrk e '[i, i]