39 lines
751 B
Haskell
39 lines
751 B
Haskell
import Clash.Prelude
|
|
|
|
type Matrix a rows cols = Vec rows (Vec cols a)
|
|
|
|
getNthCol
|
|
:: (KnownNat rows, KnownNat cols)
|
|
=> Matrix a rows cols -- matrix
|
|
-> Int -- n
|
|
-> Vec rows a -- nth column of matrix
|
|
getNthCol mat n = map (\rw -> rw !! n) mat
|
|
|
|
transpRow
|
|
:: KnownNat n
|
|
=> Vec n a
|
|
-> Matrix a n 1
|
|
transpRow Nil = Nil
|
|
transpRow v = ((head v) :> Nil) :> (transpRow $ tail v)
|
|
--transpRow (x :> xs) = (x :> Nil) :> (transpRow xs)
|
|
|
|
|
|
dotProduct
|
|
:: (KnownNat n, Num a)
|
|
=> Vec n a
|
|
-> Vec n a
|
|
-> a
|
|
dotProduct p q
|
|
= foldr (\x acc -> acc+x) 0
|
|
$ map (\x -> (fst x)*(snd x))
|
|
$ zipWith (,) p q
|
|
|
|
-- matProd p q
|
|
|
|
eg1
|
|
= (0 :> 1 :> 2 :> Nil) :>
|
|
(3 :> 4 :> 5 :> Nil) :>
|
|
Nil
|
|
-- λ> getNthCol eg1 0
|
|
-- 0 :> 3 :> Nil
|