summaryrefslogtreecommitdiff
path: root/packages/base/src
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-07-13 12:28:15 +0200
committerAlberto Ruiz <aruiz@um.es>2015-07-13 12:28:15 +0200
commit14f492c0139c7d7e2768311068beda5441730ce3 (patch)
tree14f325bbfa9b7d1bc7ccf16e6b73ac4db14db953 /packages/base/src
parenta3b28fdf0b6a335b4905c25413cf82438383319e (diff)
make Numeric superclass of Field
Diffstat (limited to 'packages/base/src')
-rw-r--r--packages/base/src/Internal/Algorithms.hs5
-rw-r--r--packages/base/src/Internal/Container.hs41
-rw-r--r--packages/base/src/Internal/Numeric.hs42
-rw-r--r--packages/base/src/Internal/Sparse.hs1
4 files changed, 43 insertions, 46 deletions
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs
index 99c90aa..3d25491 100644
--- a/packages/base/src/Internal/Algorithms.hs
+++ b/packages/base/src/Internal/Algorithms.hs
@@ -38,14 +38,11 @@ import Internal.Vectorized(range)
38(Single precision data can be converted using 'single' and 'double'). 38(Single precision data can be converted using 'single' and 'double').
39 39
40-} 40-}
41class (Product t, 41class (Numeric t,
42 Convert t, 42 Convert t,
43 Container Vector t,
44 Container Matrix t,
45 Normed Matrix t, 43 Normed Matrix t,
46 Normed Vector t, 44 Normed Vector t,
47 Floating t, 45 Floating t,
48 CTrans t,
49 RealOf t ~ Double) => Field t where 46 RealOf t ~ Double) => Field t where
50 svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t) 47 svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t)
51 thinSVD' :: Matrix t -> (Matrix t, Vector Double, Matrix t) 48 thinSVD' :: Matrix t -> (Matrix t, Vector Double, Matrix t)
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs
index 307c6a8..b08f892 100644
--- a/packages/base/src/Internal/Container.hs
+++ b/packages/base/src/Internal/Container.hs
@@ -28,7 +28,6 @@ import Internal.Vector
28import Internal.Matrix 28import Internal.Matrix
29import Internal.Element 29import Internal.Element
30import Internal.Numeric 30import Internal.Numeric
31import Data.Complex
32import Internal.Algorithms(Field,linearSolveSVD) 31import Internal.Algorithms(Field,linearSolveSVD)
33 32
34------------------------------------------------------------------ 33------------------------------------------------------------------
@@ -158,29 +157,6 @@ instance LSDiv Matrix
158 157
159-------------------------------------------------------------------------------- 158--------------------------------------------------------------------------------
160 159
161class Konst e d c | d -> c, c -> d
162 where
163 -- |
164 -- >>> konst 7 3 :: Vector Float
165 -- fromList [7.0,7.0,7.0]
166 --
167 -- >>> konst i (3::Int,4::Int)
168 -- (3><4)
169 -- [ 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
170 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
171 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 ]
172 --
173 konst :: e -> d -> c e
174
175instance Container Vector e => Konst e Int Vector
176 where
177 konst = konst'
178
179instance (Num e, Container Vector e) => Konst e (Int,Int) Matrix
180 where
181 konst = konst'
182
183--------------------------------------------------------------------------------
184 160
185class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f 161class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f
186 where 162 where
@@ -241,23 +217,6 @@ meanCov x = (med,cov) where
241 217
242-------------------------------------------------------------------------------- 218--------------------------------------------------------------------------------
243 219
244class ( Container Vector t
245 , Container Matrix t
246 , Konst t Int Vector
247 , Konst t (Int,Int) Matrix
248 , CTrans t
249 , Product t
250 ) => Numeric t
251
252instance Numeric Double
253instance Numeric (Complex Double)
254instance Numeric Float
255instance Numeric (Complex Float)
256instance Numeric I
257instance Numeric Z
258
259--------------------------------------------------------------------------------
260
261sortVector :: (Ord t, Element t) => Vector t -> Vector t 220sortVector :: (Ord t, Element t) => Vector t -> Vector t
262sortVector = sortV 221sortVector = sortV
263 222
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs
index 4d34885..a8ae2bb 100644
--- a/packages/base/src/Internal/Numeric.hs
+++ b/packages/base/src/Internal/Numeric.hs
@@ -549,6 +549,48 @@ accum
549 -> c e -- ^ result 549 -> c e -- ^ result
550accum = accum' 550accum = accum'
551 551
552--------------------------------------------------------------------------------
553
554class Konst e d c | d -> c, c -> d
555 where
556 -- |
557 -- >>> konst 7 3 :: Vector Float
558 -- fromList [7.0,7.0,7.0]
559 --
560 -- >>> konst i (3::Int,4::Int)
561 -- (3><4)
562 -- [ 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
563 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0
564 -- , 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0, 0.0 :+ 1.0 ]
565 --
566 konst :: e -> d -> c e
567
568instance Container Vector e => Konst e Int Vector
569 where
570 konst = konst'
571
572instance (Num e, Container Vector e) => Konst e (Int,Int) Matrix
573 where
574 konst = konst'
575
576--------------------------------------------------------------------------------
577
578class ( Container Vector t
579 , Container Matrix t
580 , Konst t Int Vector
581 , Konst t (Int,Int) Matrix
582 , CTrans t
583 , Product t
584 ) => Numeric t
585
586instance Numeric Double
587instance Numeric (Complex Double)
588instance Numeric Float
589instance Numeric (Complex Float)
590instance Numeric I
591instance Numeric Z
592
593--------------------------------------------------------------------------------
552 594
553-------------------------------------------------------------------------------- 595--------------------------------------------------------------------------------
554 596
diff --git a/packages/base/src/Internal/Sparse.hs b/packages/base/src/Internal/Sparse.hs
index eb4ee1b..1604e7e 100644
--- a/packages/base/src/Internal/Sparse.hs
+++ b/packages/base/src/Internal/Sparse.hs
@@ -13,7 +13,6 @@ module Internal.Sparse(
13import Internal.Vector 13import Internal.Vector
14import Internal.Matrix 14import Internal.Matrix
15import Internal.Numeric 15import Internal.Numeric
16import Internal.Container
17import qualified Data.Vector.Storable as V 16import qualified Data.Vector.Storable as V
18import Data.Function(on) 17import Data.Function(on)
19import Control.Arrow((***)) 18import Control.Arrow((***))