summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Numeric')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra.hs2
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/HMatrix.hs2
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Static.hs2
-rw-r--r--packages/base/src/Numeric/Matrix.hs14
-rw-r--r--packages/base/src/Numeric/Vector.hs14
5 files changed, 30 insertions, 4 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra.hs b/packages/base/src/Numeric/LinearAlgebra.hs
index 520eeb7..91923e9 100644
--- a/packages/base/src/Numeric/LinearAlgebra.hs
+++ b/packages/base/src/Numeric/LinearAlgebra.hs
@@ -1,6 +1,8 @@
1{-# LANGUAGE CPP #-} 1{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleContexts #-} 2{-# LANGUAGE FlexibleContexts #-}
3 3
4{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
5
4----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
5{- | 7{- |
6Module : Numeric.LinearAlgebra 8Module : Numeric.LinearAlgebra
diff --git a/packages/base/src/Numeric/LinearAlgebra/HMatrix.hs b/packages/base/src/Numeric/LinearAlgebra/HMatrix.hs
index 3a84645..57e5cf1 100644
--- a/packages/base/src/Numeric/LinearAlgebra/HMatrix.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/HMatrix.hs
@@ -28,7 +28,9 @@ infixr 8 <·>
28(<·>) :: Numeric t => Vector t -> Vector t -> t 28(<·>) :: Numeric t => Vector t -> Vector t -> t
29(<·>) = dot 29(<·>) = dot
30 30
31app :: Numeric t => Matrix t -> Vector t -> Vector t
31app m v = m #> v 32app m v = m #> v
32 33
34mul :: Numeric t => Matrix t -> Matrix t -> Matrix t
33mul a b = a <> b 35mul a b = a <> b
34 36
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs
index e328904..2e05c90 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Static.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs
@@ -14,6 +14,8 @@
14{-# LANGUAGE GADTs #-} 14{-# LANGUAGE GADTs #-}
15{-# LANGUAGE TypeFamilies #-} 15{-# LANGUAGE TypeFamilies #-}
16 16
17{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
18{-# OPTIONS_GHC -fno-warn-orphans #-}
17 19
18{- | 20{- |
19Module : Numeric.LinearAlgebra.Static 21Module : Numeric.LinearAlgebra.Static
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
diff --git a/packages/base/src/Numeric/Vector.hs b/packages/base/src/Numeric/Vector.hs
index 017196c..1e5877d 100644
--- a/packages/base/src/Numeric/Vector.hs
+++ b/packages/base/src/Numeric/Vector.hs
@@ -3,6 +3,9 @@
3{-# LANGUAGE FlexibleInstances #-} 3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE UndecidableInstances #-} 4{-# LANGUAGE UndecidableInstances #-}
5{-# LANGUAGE MultiParamTypeClasses #-} 5{-# LANGUAGE MultiParamTypeClasses #-}
6
7{-# OPTIONS_GHC -fno-warn-orphans #-}
8
6----------------------------------------------------------------------------- 9-----------------------------------------------------------------------------
7-- | 10-- |
8-- Module : Numeric.Vector 11-- Module : Numeric.Vector
@@ -14,7 +17,7 @@
14-- 17--
15-- Provides instances of standard classes 'Show', 'Read', 'Eq', 18-- Provides instances of standard classes 'Show', 'Read', 'Eq',
16-- 'Num', 'Fractional', and 'Floating' for 'Vector'. 19-- 'Num', 'Fractional', and 'Floating' for 'Vector'.
17-- 20--
18----------------------------------------------------------------------------- 21-----------------------------------------------------------------------------
19 22
20module Numeric.Vector () where 23module Numeric.Vector () where
@@ -23,9 +26,17 @@ import Internal.Vectorized
23import Internal.Vector 26import Internal.Vector
24import Internal.Numeric 27import Internal.Numeric
25import Internal.Conversion 28import Internal.Conversion
29import Foreign.Storable(Storable)
26 30
27------------------------------------------------------------------- 31-------------------------------------------------------------------
28 32
33adaptScalar :: (Foreign.Storable.Storable t1, Foreign.Storable.Storable t2)
34 => (t1 -> Vector t2 -> t)
35 -> (Vector t1 -> Vector t2 -> t)
36 -> (Vector t1 -> t2 -> t)
37 -> Vector t1
38 -> Vector t2
39 -> t
29adaptScalar f1 f2 f3 x y 40adaptScalar f1 f2 f3 x y
30 | dim x == 1 = f1 (x@>0) y 41 | dim x == 1 = f1 (x@>0) y
31 | dim y == 1 = f3 x (y@>0) 42 | dim y == 1 = f3 x (y@>0)
@@ -172,4 +183,3 @@ instance Floating (Vector (Complex Float)) where
172 sqrt = vectorMapQ Sqrt 183 sqrt = vectorMapQ Sqrt
173 (**) = adaptScalar (vectorMapValQ PowSV) (vectorZipQ Pow) (flip (vectorMapValQ PowVS)) 184 (**) = adaptScalar (vectorMapValQ PowSV) (vectorZipQ Pow) (flip (vectorMapValQ PowVS))
174 pi = fromList [pi] 185 pi = fromList [pi]
175