Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data family Array (c :: Type -> Type) (ds :: [k]) (a :: Type)
- newtype AnyArray c a = AnyArray ([Int], c a)
- anyArray :: Dimensions ds => Array c ds a -> AnyArray c a
- class Functor f => Container f where
- xdimList :: XDim ds -> [Int]
- dimList :: Dim ds -> [Int]
- ind :: [Int] -> [Int] -> Int
- unind :: [Int] -> Int -> [Int]
- flatten1 :: Container c => AnyArray c a -> [AnyArray c a]
- type Vector c n = Array c '[n]
- type Matrix c m n = Array c '[m, n]
- (><) :: forall c (r :: [Nat]) (s :: [Nat]) a. (Container c, CRing a, Dimensions r, Dimensions s, Dimensions (r ++ s)) => Array c r a -> Array c s a -> Array c (r ++ s) a
- mmult :: forall c m n k a. (Hilbert (Vector c k) a, Dimensions '[m, k], Dimensions '[k, n], Dimensions '[m, n], Container c, Semiring a, Num a, CRing a, KnownNat m, KnownNat n, KnownNat k) => Matrix c m k a -> Matrix c k n a -> Matrix c m n a
- row :: forall c i a m n. (Dimensions '[m, n], Container c, KnownNat m, KnownNat n, KnownNat i, (i :< m) ~ True) => Proxy i -> Matrix c m n a -> Vector c n a
- unsafeRow :: forall c a m n. (Container c, KnownNat m, KnownNat n, Dimensions '[m, n]) => Int -> Matrix c m n a -> Vector c n a
- col :: forall c j a m n. (Dimensions '[m, n], Container c, KnownNat m, KnownNat n, KnownNat j, (j :< n) ~ True) => Proxy j -> Matrix c m n a -> Vector c m a
- unsafeCol :: forall c a m n. (Container c, KnownNat m, KnownNat n, Dimensions '[m, n]) => Int -> Matrix c m n a -> Vector c m a
- unsafeIndex :: (Container c, Dimensions r) => Array c r a -> [Int] -> a
- unsafeSlice :: (Container c, IsList (c a), Item (c a) ~ a, Dimensions r, Dimensions r0) => [[Int]] -> Array c r a -> Array c r0 a
- type family Slice (xss :: [[Nat]]) :: [Nat] where ...
- data AllLTSym0 (a :: TyFun [Nat] (TyFun Nat Bool -> Type))
- data AllLTSym1 (l :: [Nat]) (a :: TyFun Nat Bool)
- slice :: ((~#) * * (Item (c a1)) a1, SingI [[Nat]] a2, Dimensions r0, Dimensions r, IsList (c a1), Container c) => proxy a2 -> Array Nat c r a1 -> Array Nat c r0 a1
- foldAlong :: forall c s vw uvw uw w a. (Container c, KnownNat s, Dimensions uvw, uw ~ Fold s uvw, w ~ Drop 1 vw, vw ~ TailModule s uvw) => Proxy s -> (Array c vw a -> Array c w a) -> Array c uvw a -> Array c uw a
- mapAlong :: forall c s uvw vw a. (Container c, KnownNat s, Dimensions uvw, vw ~ HeadModule s uvw) => Proxy s -> (Array c vw a -> Array c vw a) -> Array c uvw a -> Array c uvw a
- concatenate :: forall c s r t a. (Container c, SingI s, Dimensions r, Dimensions t, IsValidConcat s t r ~ True) => Proxy s -> Array c r a -> Array c t a -> Array c (Concatenate s t r) a
- transpose :: forall c s t a. (t ~ Transpose s, Container c, Dimensions s, Dimensions t) => Array c s a -> Array c t a
- squeeze :: forall c s t a. t ~ Squeeze s => Array c s a -> Array c t a
Documentation
>>>
:set -XDataKinds
>>>
:set -XOverloadedLists
>>>
:set -XTypeFamilies
>>>
let a = [1..24] :: Array [] '[2,3,4] Int
>>>
let v = [1,2,3] :: Array [] '[3] Int
data family Array (c :: Type -> Type) (ds :: [k]) (a :: Type) Source #
an array polymorphic in container and shape
>>>
a
[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]
an array with dimensions represented at the value level
anyArray :: Dimensions ds => Array c ds a -> AnyArray c a Source #
convert an array with type-level shape to value-level shape
class Functor f => Container f where Source #
a sweet class of container with attributes necessary to supply the set of operations here
generate :: Int -> (Int -> a) -> f a Source #
idx :: f a -> Int -> a Source #
cslice :: Int -> Int -> f a -> f a Source #
zipWith :: (a -> a -> a) -> f a -> f a -> f a Source #
chunkItUp :: [f a] -> Int -> f a -> [f a] Source #
cfoldl' :: (b -> a -> b) -> b -> f a -> b Source #
shape helpers where dimensions ~ [Int]
ind :: [Int] -> [Int] -> Int Source #
convert from n-dim shape index to a flat index
>>>
ind [2,3,4] [1,1,1]
17
unind :: [Int] -> Int -> [Int] Source #
convert from a flat index to a shape index
>>>
unind [2,3,4] 17
[1,1,1]
flatten1 :: Container c => AnyArray c a -> [AnyArray c a] Source #
convert the top layer of a SomeArray to a [SomeArray]
Operations
(><) :: forall c (r :: [Nat]) (s :: [Nat]) a. (Container c, CRing a, Dimensions r, Dimensions s, Dimensions (r ++ s)) => Array c r a -> Array c s a -> Array c (r ++ s) a Source #
outer product
todo: reconcile with numhask version
>>>
v NumHask.Array.>< v
[[1, 2, 3], [2, 4, 6], [3, 6, 9]]
mmult :: forall c m n k a. (Hilbert (Vector c k) a, Dimensions '[m, k], Dimensions '[k, n], Dimensions '[m, n], Container c, Semiring a, Num a, CRing a, KnownNat m, KnownNat n, KnownNat k) => Matrix c m k a -> Matrix c k n a -> Matrix c m n a Source #
matrix multiplication
>>>
let a = [1, 2, 3, 4] :: Array [] '[2, 2] Int
>>>
let b = [5, 6, 7, 8] :: Array [] '[2, 2] Int
>>>
a
[[1, 2], [3, 4]]
>>>
b
[[5, 6], [7, 8]]
>>>
mmult a b
[[19, 22], [43, 50]]
row :: forall c i a m n. (Dimensions '[m, n], Container c, KnownNat m, KnownNat n, KnownNat i, (i :< m) ~ True) => Proxy i -> Matrix c m n a -> Vector c n a Source #
extract the row of a matrix
unsafeRow :: forall c a m n. (Container c, KnownNat m, KnownNat n, Dimensions '[m, n]) => Int -> Matrix c m n a -> Vector c n a Source #
col :: forall c j a m n. (Dimensions '[m, n], Container c, KnownNat m, KnownNat n, KnownNat j, (j :< n) ~ True) => Proxy j -> Matrix c m n a -> Vector c m a Source #
extract the column of a matrix
unsafeCol :: forall c a m n. (Container c, KnownNat m, KnownNat n, Dimensions '[m, n]) => Int -> Matrix c m n a -> Vector c m a Source #
unsafeIndex :: (Container c, Dimensions r) => Array c r a -> [Int] -> a Source #
>>>
unsafeIndex a [0,2,1]
10
unsafeSlice :: (Container c, IsList (c a), Item (c a) ~ a, Dimensions r, Dimensions r0) => [[Int]] -> Array c r a -> Array c r0 a Source #
>>>
unsafeSlice [[0,1],[2],[1,2]] a :: Array [] '[2,1,2] Int
[[[10, 11]], [[22, 23]]]
type family Slice (xss :: [[Nat]]) :: [Nat] where ... Source #
Slice xs = Map Length xs
Slice xss = Map LengthSym0 xss |
slice :: ((~#) * * (Item (c a1)) a1, SingI [[Nat]] a2, Dimensions r0, Dimensions r, IsList (c a1), Container c) => proxy a2 -> Array Nat c r a1 -> Array Nat c r0 a1 Source #
todo: an ambiguous type variable has snucjk in here somewhere
slice (Proxy :: Proxy '[ '[0,1],'[2],'[1,2]]) a
- [[10, 11
- ],
- [22, 23
- ]]
foldAlong :: forall c s vw uvw uw w a. (Container c, KnownNat s, Dimensions uvw, uw ~ Fold s uvw, w ~ Drop 1 vw, vw ~ TailModule s uvw) => Proxy s -> (Array c vw a -> Array c w a) -> Array c uvw a -> Array c uw a Source #
>>>
foldAlong (Proxy :: Proxy 1) (\_ -> ([0..3] :: Array [] '[4] Int)) a
[[0, 1, 2, 3], [0, 1, 2, 3]]
todo: resolution of a primitive and a scalar eg Expected type: Array '[10] Int -> Array '[] Int Actual type: Array '[10] (Array '[] Int) -> Array '[] Int
mapAlong :: forall c s uvw vw a. (Container c, KnownNat s, Dimensions uvw, vw ~ HeadModule s uvw) => Proxy s -> (Array c vw a -> Array c vw a) -> Array c uvw a -> Array c uvw a Source #
todo: No instance for (Container (Array [] '[]) error
mapAlong (Proxy :: Proxy 0) (\x -> NumHask.Array.zipWith (*) x x) a
- [[1, 4, 9, 16
- ,
- 25, 36, 49, 64
- ,
- 81, 100, 121, 144
- ],
- [169, 196, 225, 256
- ,
- 289, 324, 361, 400
- ,
- 441, 484, 529, 576
- ]]
concatenate :: forall c s r t a. (Container c, SingI s, Dimensions r, Dimensions t, IsValidConcat s t r ~ True) => Proxy s -> Array c r a -> Array c t a -> Array c (Concatenate s t r) a Source #
>>>
concatenate (Proxy :: Proxy 2) a a
[[[1, 2, 3, 4, 1, 2, 3, 4], [5, 6, 7, 8, 5, 6, 7, 8], [9, 10, 11, 12, 9, 10, 11, 12]], [[13, 14, 15, 16, 13, 14, 15, 16], [17, 18, 19, 20, 17, 18, 19, 20], [21, 22, 23, 24, 21, 22, 23, 24]]]
transpose :: forall c s t a. (t ~ Transpose s, Container c, Dimensions s, Dimensions t) => Array c s a -> Array c t a Source #
>>>
NumHask.Array.transpose a
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]], [[13, 14], [15, 16], [17, 18]], [[19, 20], [21, 22], [23, 24]]]
squeeze :: forall c s t a. t ~ Squeeze s => Array c s a -> Array c t a Source #
>>>
let a = [1..24] :: Array [] '[2,1,3,4,1] Int
>>>
a
[[[[[1], [2], [3], [4]], [[5], [6], [7], [8]], [[9], [10], [11], [12]]]], [[[[13], [14], [15], [16]], [[17], [18], [19], [20]], [[21], [22], [23], [24]]]]]>>>
squeeze a
[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]]]