diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 18 |
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 | ||
74 | liftMatrix2' :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t | 74 | liftMatrix2' :: (Element t, Element a, Element b) |
75 | liftMatrix2' 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'" | 76 | liftMatrix2' 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 | |||
85 | lM f m1 m2 = reshape (max (cols m1) (cols m2)) (f (flatten m1) (flatten m2)) | ||
86 | |||
87 | repRows n x = fromRows (replicate n (flatten x)) | ||
88 | repCols n x = fromColumns (replicate n (flatten x)) | ||
77 | 89 | ||
78 | compat' :: Matrix a -> Matrix b -> Bool | 90 | compat' :: Matrix a -> Matrix b -> Bool |
79 | compat' m1 m2 = rows m1 == 1 && cols m1 == 1 | 91 | compat' m1 m2 = rows m1 == 1 && cols m1 == 1 |