summaryrefslogtreecommitdiff
path: root/lib/Numeric/ContainerBoot.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/ContainerBoot.hs')
-rw-r--r--lib/Numeric/ContainerBoot.hs40
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/Numeric/ContainerBoot.hs b/lib/Numeric/ContainerBoot.hs
index 4c5bbd0..8707473 100644
--- a/lib/Numeric/ContainerBoot.hs
+++ b/lib/Numeric/ContainerBoot.hs
@@ -36,9 +36,7 @@ module Numeric.ContainerBoot (
36 RealOf, ComplexOf, SingleOf, DoubleOf, 36 RealOf, ComplexOf, SingleOf, DoubleOf,
37 37
38 IndexOf, 38 IndexOf,
39 module Data.Complex, 39 module Data.Complex
40 -- * Experimental
41 build', konst'
42) where 40) where
43 41
44import Data.Packed 42import Data.Packed
@@ -91,15 +89,13 @@ class (Complexable c, Fractional e, Element e) => Container c e where
91 -- | cannot implement instance Functor because of Element class constraint 89 -- | cannot implement instance Functor because of Element class constraint
92 cmap :: (Element b) => (e -> b) -> c e -> c b 90 cmap :: (Element b) => (e -> b) -> c e -> c b
93 -- | constant structure of given size 91 -- | constant structure of given size
94 konst :: e -> IndexOf c -> c e 92 konst' :: e -> IndexOf c -> c e
95 -- | create a structure using a function 93 -- | create a structure using a function
96 -- 94 --
97 -- Hilbert matrix of order N: 95 -- Hilbert matrix of order N:
98 -- 96 --
99 -- @hilb n = build (n,n) (\\i j -> 1/(i+j+1))@ 97 -- @hilb n = build' (n,n) (\\i j -> 1/(i+j+1))@
100 build :: IndexOf c -> (ArgOf c e) -> c e 98 build' :: IndexOf c -> (ArgOf c e) -> c e
101 --build :: BoundsOf f -> f -> (ContainerOf f) e
102 --
103 -- | indexing function 99 -- | indexing function
104 atIndex :: c e -> IndexOf c -> e 100 atIndex :: c e -> IndexOf c -> e
105 -- | index of min element 101 -- | index of min element
@@ -186,8 +182,8 @@ instance Container Vector Float where
186 equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 182 equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0
187 arctan2 = vectorZipF ATan2 183 arctan2 = vectorZipF ATan2
188 scalar x = fromList [x] 184 scalar x = fromList [x]
189 konst = constantD 185 konst' = constantD
190 build = buildV 186 build' = buildV
191 conj = id 187 conj = id
192 cmap = mapVector 188 cmap = mapVector
193 atIndex = (@>) 189 atIndex = (@>)
@@ -214,8 +210,8 @@ instance Container Vector Double where
214 equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 210 equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0
215 arctan2 = vectorZipR ATan2 211 arctan2 = vectorZipR ATan2
216 scalar x = fromList [x] 212 scalar x = fromList [x]
217 konst = constantD 213 konst' = constantD
218 build = buildV 214 build' = buildV
219 conj = id 215 conj = id
220 cmap = mapVector 216 cmap = mapVector
221 atIndex = (@>) 217 atIndex = (@>)
@@ -242,8 +238,8 @@ instance Container Vector (Complex Double) where
242 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 238 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0
243 arctan2 = vectorZipC ATan2 239 arctan2 = vectorZipC ATan2
244 scalar x = fromList [x] 240 scalar x = fromList [x]
245 konst = constantD 241 konst' = constantD
246 build = buildV 242 build' = buildV
247 conj = conjugateC 243 conj = conjugateC
248 cmap = mapVector 244 cmap = mapVector
249 atIndex = (@>) 245 atIndex = (@>)
@@ -270,8 +266,8 @@ instance Container Vector (Complex Float) where
270 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 266 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0
271 arctan2 = vectorZipQ ATan2 267 arctan2 = vectorZipQ ATan2
272 scalar x = fromList [x] 268 scalar x = fromList [x]
273 konst = constantD 269 konst' = constantD
274 build = buildV 270 build' = buildV
275 conj = conjugateQ 271 conj = conjugateQ
276 cmap = mapVector 272 cmap = mapVector
277 atIndex = (@>) 273 atIndex = (@>)
@@ -300,8 +296,8 @@ instance (Container Vector a) => Container Matrix a where
300 equal a b = cols a == cols b && flatten a `equal` flatten b 296 equal a b = cols a == cols b && flatten a `equal` flatten b
301 arctan2 = liftMatrix2 arctan2 297 arctan2 = liftMatrix2 arctan2
302 scalar x = (1><1) [x] 298 scalar x = (1><1) [x]
303 konst v (r,c) = reshape c (konst v (r*c)) 299 konst' v (r,c) = reshape c (konst' v (r*c))
304 build = buildM 300 build' = buildM
305 conj = liftMatrix conj 301 conj = liftMatrix conj
306 cmap f = liftMatrix (mapVector f) 302 cmap f = liftMatrix (mapVector f)
307 atIndex = (@@>) 303 atIndex = (@@>)
@@ -506,7 +502,7 @@ type instance ElementOf (Vector a) = a
506type instance ElementOf (Matrix a) = a 502type instance ElementOf (Matrix a) = a
507 503
508------------------------------------------------------------ 504------------------------------------------------------------
509 505{-
510class Build f where 506class Build f where
511 build' :: BoundsOf f -> f -> ContainerOf f 507 build' :: BoundsOf f -> f -> ContainerOf f
512 508
@@ -546,6 +542,8 @@ instance (Element a,
546 => Build (a->a->a) where 542 => Build (a->a->a) where
547 build' = buildM 543 build' = buildM
548 544
545-}
546
549buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ] 547buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ]
550 where rs = map fromIntegral [0 .. (rc-1)] 548 where rs = map fromIntegral [0 .. (rc-1)]
551 cs = map fromIntegral [0 .. (cc-1)] 549 cs = map fromIntegral [0 .. (cc-1)]
@@ -553,6 +551,8 @@ buildM (rc,cc) f = fromLists [ [f r c | c <- cs] | r <- rs ]
553buildV n f = fromList [f k | k <- ks] 551buildV n f = fromList [f k | k <- ks]
554 where ks = map fromIntegral [0 .. (n-1)] 552 where ks = map fromIntegral [0 .. (n-1)]
555 553
554{-
555
556---------------------------------------------------- 556----------------------------------------------------
557-- experimental 557-- experimental
558 558
@@ -570,6 +570,8 @@ instance Konst Int where
570instance Konst (Int,Int) where 570instance Konst (Int,Int) where
571 konst' k (r,c) = reshape c $ konst' k (r*c) 571 konst' k (r,c) = reshape c $ konst' k (r*c)
572 572
573-}
574
573-------------------------------------------------------- 575--------------------------------------------------------
574-- | conjugate transpose 576-- | conjugate transpose
575ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e 577ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e