summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-01-31 18:21:52 +0000
committerAlberto Ruiz <aruiz@um.es>2010-01-31 18:21:52 +0000
commitc3fb38f685fa4a5705ac229fa8b87968efa95ead (patch)
tree557b109fd3ad18422775e80ed082c95436ce8727
parent887622a8e23d862160489c7f8912c85e86d5d911 (diff)
auto replicate single row/column
-rw-r--r--CHANGES5
-rw-r--r--hmatrix.cabal2
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs18
3 files changed, 21 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 4411099..76345fc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
10.8.3.0
2=======
3
4- Matrix arithmetic automatically replicates single row/column matrices
5
10.8.2.0 60.8.2.0
2======= 7=======
3 8
diff --git a/hmatrix.cabal b/hmatrix.cabal
index 0037ad0..4749640 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.8.2.0 2Version: 0.8.3.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
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