Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
numhask orphan instances and shim for harpie.
Synopsis
- ident :: (KnownNats s, Additive a, Multiplicative a) => Array s a
- undiag :: forall s' a s. (KnownNats s, KnownNats s', s' ~ Eval ((++) s s), Additive a) => Array s a -> Array s' a
- mult :: forall a ds0 ds1 s0 s1 so0 so1 st si. (Ring a, KnownNats s0, KnownNats s1, KnownNats ds0, KnownNats ds1, KnownNats so0, KnownNats so1, KnownNats st, KnownNats si, so0 ~ Eval (DeleteDims ds0 s0), so1 ~ Eval (DeleteDims ds1 s1), si ~ Eval (GetDims ds0 s0), si ~ Eval (GetDims ds1 s1), st ~ Eval ((++) so0 so1), ds0 ~ '[Eval ((-) (Eval (Rank s0)) 1)], ds1 ~ '[0]) => Array s0 a -> Array s1 a -> Array st a
- invtri :: forall a n. (KnownNat n, ExpField a, Eq a) => Matrix n n a -> Matrix n n a
- inverse :: (Eq a, ExpField a, KnownNat m) => Matrix m m a -> Matrix m m a
- chol :: (KnownNat m, ExpField a) => Matrix m m a -> Matrix m m a
Usage
ident :: (KnownNats s, Additive a, Multiplicative a) => Array s a Source #
The identity array.
>>>
pretty $ ident @[3,3]
[[1,0,0], [0,1,0], [0,0,1]]
undiag :: forall s' a s. (KnownNats s, KnownNats s', s' ~ Eval ((++) s s), Additive a) => Array s a -> Array s' a Source #
Expand the array to form a diagonal array
>>>
pretty $ undiag (range @'[3])
[[0,0,0], [0,1,0], [0,0,2]]
mult :: forall a ds0 ds1 s0 s1 so0 so1 st si. (Ring a, KnownNats s0, KnownNats s1, KnownNats ds0, KnownNats ds1, KnownNats so0, KnownNats so1, KnownNats st, KnownNats si, so0 ~ Eval (DeleteDims ds0 s0), so1 ~ Eval (DeleteDims ds1 s1), si ~ Eval (GetDims ds0 s0), si ~ Eval (GetDims ds1 s1), st ~ Eval ((++) so0 so1), ds0 ~ '[Eval ((-) (Eval (Rank s0)) 1)], ds1 ~ '[0]) => Array s0 a -> Array s1 a -> Array st a Source #
Array multiplication.
matrix multiplication
>>>
pretty $ mult m (F.transpose m)
[[5,14], [14,50]]
inner product
>>>
pretty $ mult v v
5
matrix-vector multiplication
>>>
pretty $ mult v (F.transpose m)
[5,14]
>>>
pretty $ mult m v
[5,14]
invtri :: forall a n. (KnownNat n, ExpField a, Eq a) => Matrix n n a -> Matrix n n a Source #
Inversion of a Triangular Matrix
>>>
t = array @[3,3] @Double [1,0,1,0,1,2,0,0,1]
>>>
pretty (invtri t)
[[1.0,0.0,-1.0], [0.0,1.0,-2.0], [0.0,0.0,1.0]]
ident == mult t (invtri t)
True
inverse :: (Eq a, ExpField a, KnownNat m) => Matrix m m a -> Matrix m m a Source #
Inverse of a square matrix.
mult (inverse a) a == a
>>>
e = array @[3,3] @Double [4,12,-16,12,37,-43,-16,-43,98]
>>>
pretty (inverse e)
[[49.36111111111111,-13.555555555555554,2.1111111111111107], [-13.555555555555554,3.7777777777777772,-0.5555555555555555], [2.1111111111111107,-0.5555555555555555,0.1111111111111111]]
chol :: (KnownNat m, ExpField a) => Matrix m m a -> Matrix m m a Source #
cholesky decomposition
Uses the Cholesky-Crout algorithm.
>>>
e = array @[3,3] @Double [4,12,-16,12,37,-43,-16,-43,98]
>>>
pretty (chol e)
[[2.0,0.0,0.0], [6.0,1.0,0.0], [-8.0,5.0,3.0]]>>>
mult (chol e) (F.transpose (chol e)) == e
True