summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index dd33943..9895393 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -144,13 +144,17 @@ transdata c1 d c2 | isReal baseOf d = scast $ transdataR c1 (scast d) c2
144--{-# RULES "transdataC" transdata=transdataC #-} 144--{-# RULES "transdataC" transdata=transdataC #-}
145 145
146----------------------------------------------------------------- 146-----------------------------------------------------------------
147liftMatrix :: (Vector a -> Vector b) -> Matrix a -> Matrix b 147liftMatrix :: (Field a, Field b) => (Vector a -> Vector b) -> Matrix a -> Matrix b
148liftMatrix f m = m { dat = f (dat m), tdat = f (tdat m) } -- check sizes 148liftMatrix f m = reshape (cols m) (f (cdat m))
149 149
150liftMatrix2 :: (Field t) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t 150liftMatrix2 :: (Field t) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
151liftMatrix2 f m1 m2 = reshape (cols m1) (f (cdat m1) (cdat m2)) -- check sizes 151liftMatrix2 f m1 m2 | compat m1 m2 = reshape (cols m1) (f (cdat m1) (cdat m2))
152 | otherwise = error "nonconformant matrices in liftMatrix2"
152------------------------------------------------------------------ 153------------------------------------------------------------------
153 154
155compat :: Matrix a -> Matrix b -> Bool
156compat m1 m2 = rows m1 == rows m2 && cols m1 == cols m2
157
154dotL a b = sum (zipWith (*) a b) 158dotL a b = sum (zipWith (*) a b)
155 159
156multiplyL a b | ok = [[dotL x y | y <- transpose b] | x <- a] 160multiplyL a b | ok = [[dotL x y | y <- transpose b] | x <- a]