summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index f3e1b5f..ffc4f17 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -71,9 +71,21 @@ adaptScalar f1 f2 f3 x y
71 | dim y == 1 = f3 x (y@>0) 71 | dim y == 1 = f3 x (y@>0)
72 | otherwise = f2 x y 72 | otherwise = f2 x y
73 73
74liftMatrix2' :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t 74liftMatrix2' :: (Element t, Element a, Element b)
75liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (flatten m1) (flatten m2)) 75 => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
76 | otherwise = error "nonconformant matrices in liftMatrix2'" 76liftMatrix2' f m1 m2 | compat' m1 m2 = lM f m1 m2
77 | rows m1 == rows m2 && cols m2 == 1 = lM f m1 (repCols (cols m1) m2)
78 | rows m1 == rows m2 && cols m1 == 1 = lM f (repCols (cols m2) m1) m2
79 | cols m1 == cols m2 && rows m2 == 1 = lM f m1 (repRows (rows m1) m2)
80 | cols m1 == cols m2 && cols m1 == 1 = lM f (repRows (rows m2) m1) m2
81 | rows m1 == 1 && cols m2 == 1 = lM f (repRows (rows m2) m1) (repCols (cols m1) m2)
82 | cols m1 == 1 && rows m2 == 1 = lM f (repCols (cols m2) m1) (repRows (rows m1) m2)
83 | otherwise = error "nonconformable matrices in liftMatrix2'"
84
85lM f m1 m2 = reshape (max (cols m1) (cols m2)) (f (flatten m1) (flatten m2))
86
87repRows n x = fromRows (replicate n (flatten x))
88repCols n x = fromColumns (replicate n (flatten x))
77 89
78compat' :: Matrix a -> Matrix b -> Bool 90compat' :: Matrix a -> Matrix b -> Bool
79compat' m1 m2 = rows m1 == 1 && cols m1 == 1 91compat' m1 m2 = rows m1 == 1 && cols m1 == 1