summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Numeric/Matrix.hs')
-rw-r--r--packages/base/src/Numeric/Matrix.hs14
1 files changed, 12 insertions, 2 deletions
diff --git a/packages/base/src/Numeric/Matrix.hs b/packages/base/src/Numeric/Matrix.hs
index 06da150..6e3db61 100644
--- a/packages/base/src/Numeric/Matrix.hs
+++ b/packages/base/src/Numeric/Matrix.hs
@@ -4,6 +4,8 @@
4{-# LANGUAGE UndecidableInstances #-} 4{-# LANGUAGE UndecidableInstances #-}
5{-# LANGUAGE MultiParamTypeClasses #-} 5{-# LANGUAGE MultiParamTypeClasses #-}
6 6
7{-# OPTIONS_GHC -fno-warn-orphans #-}
8
7----------------------------------------------------------------------------- 9-----------------------------------------------------------------------------
8-- | 10-- |
9-- Module : Numeric.Matrix 11-- Module : Numeric.Matrix
@@ -35,6 +37,7 @@ import Data.List(partition)
35import qualified Data.Foldable as F 37import qualified Data.Foldable as F
36import qualified Data.Semigroup as S 38import qualified Data.Semigroup as S
37import Internal.Chain 39import Internal.Chain
40import Foreign.Storable(Storable)
38 41
39 42
40------------------------------------------------------------------- 43-------------------------------------------------------------------
@@ -80,8 +83,16 @@ instance (Floating a, Container Vector a, Floating (Vector a), Fractional (Matri
80 83
81-------------------------------------------------------------------------------- 84--------------------------------------------------------------------------------
82 85
86isScalar :: Matrix t -> Bool
83isScalar m = rows m == 1 && cols m == 1 87isScalar m = rows m == 1 && cols m == 1
84 88
89adaptScalarM :: (Foreign.Storable.Storable t1, Foreign.Storable.Storable t2)
90 => (t1 -> Matrix t2 -> t)
91 -> (Matrix t1 -> Matrix t2 -> t)
92 -> (Matrix t1 -> t2 -> t)
93 -> Matrix t1
94 -> Matrix t2
95 -> t
85adaptScalarM f1 f2 f3 x y 96adaptScalarM f1 f2 f3 x y
86 | isScalar x = f1 (x @@>(0,0) ) y 97 | isScalar x = f1 (x @@>(0,0) ) y
87 | isScalar y = f3 x (y @@>(0,0) ) 98 | isScalar y = f3 x (y @@>(0,0) )
@@ -96,7 +107,7 @@ instance (Container Vector t, Eq t, Num (Vector t), Product t) => M.Monoid (Matr
96 where 107 where
97 mempty = 1 108 mempty = 1
98 mappend = adaptScalarM scale mXm (flip scale) 109 mappend = adaptScalarM scale mXm (flip scale)
99 110
100 mconcat xs = work (partition isScalar xs) 111 mconcat xs = work (partition isScalar xs)
101 where 112 where
102 work (ss,[]) = product ss 113 work (ss,[]) = product ss
@@ -106,4 +117,3 @@ instance (Container Vector t, Eq t, Num (Vector t), Product t) => M.Monoid (Matr
106 | otherwise = scale x00 m 117 | otherwise = scale x00 m
107 where 118 where
108 x00 = x @@> (0,0) 119 x00 = x @@> (0,0)
109