summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/Container.hs14
-rw-r--r--lib/Numeric/ContainerBoot.hs62
2 files changed, 13 insertions, 63 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index a31acfe..46c2903 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -28,7 +28,7 @@
28module Numeric.Container ( 28module Numeric.Container (
29 -- * Basic functions 29 -- * Basic functions
30 module Data.Packed, 30 module Data.Packed,
31 konst, -- build, 31 konst, build,
32 constant, linspace, 32 constant, linspace,
33 diag, ident, 33 diag, ident,
34 ctrans, 34 ctrans,
@@ -188,3 +188,15 @@ instance Container Vector e => Konst e (Int,Int) Matrix
188 where 188 where
189 konst = konst' 189 konst = konst'
190 190
191class Build d f c e | d -> c, c -> d, f -> e, f -> d, f -> c, c e -> f, d e -> f
192 where
193 build :: d -> f -> c e
194
195instance Container Vector e => Build Int (e -> e) Vector e
196 where
197 build = build'
198
199instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e
200 where
201 build = build'
202
diff --git a/lib/Numeric/ContainerBoot.hs b/lib/Numeric/ContainerBoot.hs
index 8707473..d61633e 100644
--- a/lib/Numeric/ContainerBoot.hs
+++ b/lib/Numeric/ContainerBoot.hs
@@ -502,47 +502,6 @@ type instance ElementOf (Vector a) = a
502type instance ElementOf (Matrix a) = a 502type instance ElementOf (Matrix a) = a
503 503
504------------------------------------------------------------ 504------------------------------------------------------------
505{-
506class Build f where
507 build' :: BoundsOf f -> f -> ContainerOf f
508
509
510#if MIN_VERSION_base(4,7,0)
511-- ghc >= 7.7 considers:
512--
513-- > a -> a
514-- > b -> b -> b
515--
516-- to overlap
517type family BoundsOf x where
518 BoundsOf (a -> a) = Int
519 BoundsOf (a->a->a) = (Int,Int)
520type family ContainerOf x where
521 ContainerOf (a->a) = Vector a
522 ContainerOf (a->a->a) = Matrix a
523#else
524type family BoundsOf x
525type family ContainerOf x
526type instance BoundsOf (a->a) = Int
527type instance BoundsOf (a->a->a) = (Int,Int)
528type instance ContainerOf (a->a) = Vector a
529type instance ContainerOf (a->a->a) = Matrix a
530#endif
531
532
533instance (Element a, Num a) => Build (a->a) where
534 build' = buildV
535
536instance (Element a,
537#if MIN_VERSION_base(4,7,0)
538 BoundsOf (a -> a -> a) ~ (Int,Int),
539 ContainerOf (a -> a -> a) ~ Matrix a,
540#endif
541 Num a)
542 => Build (a->a->a) where
543 build' = buildM
544
545-}
546 505
547buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] 506buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ]
548 where rs = map fromIntegral [0 .. (rc-1)] 507 where rs = map fromIntegral [0 .. (rc-1)]
@@ -551,27 +510,6 @@ buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ]
551buildV n f = fromList [f k | k <- ks] 510buildV n f = fromList [f k | k <- ks]
552 where ks = map fromIntegral [0 .. (n-1)] 511 where ks = map fromIntegral [0 .. (n-1)]
553 512
554{-
555
556----------------------------------------------------
557-- experimental
558
559class Konst s where
560 konst' :: Element e => e -> s -> ContainerOf' s e
561
562type family ContainerOf' x y
563
564type instance ContainerOf' Int a = Vector a
565type instance ContainerOf' (Int,Int) a = Matrix a
566
567instance Konst Int where
568 konst' = constantD
569
570instance Konst (Int,Int) where
571 konst' k (r,c) = reshape c $ konst' k (r*c)
572
573-}
574
575-------------------------------------------------------- 513--------------------------------------------------------
576-- | conjugate transpose 514-- | conjugate transpose
577ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e 515ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e