summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Container.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-06-15 12:52:46 +0200
committerAlberto Ruiz <aruiz@um.es>2015-06-15 12:52:46 +0200
commit7376d022b12a27db5a396f89806a709555c1c522 (patch)
treef5bab9687cf775185f20dbc22713eddb360b495a /packages/base/src/Internal/Container.hs
parent57487d828065ea219cdb33c9dc177b67c60b34c7 (diff)
documentation, more general cond, remove some unicode, minor changes
Diffstat (limited to 'packages/base/src/Internal/Container.hs')
-rw-r--r--packages/base/src/Internal/Container.hs85
1 files changed, 69 insertions, 16 deletions
diff --git a/packages/base/src/Internal/Container.hs b/packages/base/src/Internal/Container.hs
index 7fe5758..1c158ff 100644
--- a/packages/base/src/Internal/Container.hs
+++ b/packages/base/src/Internal/Container.hs
@@ -53,28 +53,23 @@ linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n
53 53
54-------------------------------------------------------------------------------- 54--------------------------------------------------------------------------------
55 55
56infixl 7 <.> 56infixr 8 <.>
57-- | An infix synonym for 'dot' 57{- | An infix synonym for 'dot'
58(<.>) :: Numeric t => Vector t -> Vector t -> t
59(<.>) = dot
60 58
59>>> vector [1,2,3,4] <.> vector [-2,0,1,1]
605.0
61 61
62infixr 8 <ยท>, #> 62>>> let ๐‘– = 0:+1 :: C
63>>> fromList [1+๐‘–,1] <.> fromList [1,1+๐‘–]
642.0 :+ 0.0
63 65
64{- | infix synonym for 'dot' 66-}
65 67
66>>> vector [1,2,3,4] <ยท> vector [-2,0,1,1] 68(<.>) :: Numeric t => Vector t -> Vector t -> t
675.0 69(<.>) = dot
68 70
69>>> let ๐‘– = 0:+1 :: โ„‚
70>>> fromList [1+๐‘–,1] <ยท> fromList [1,1+๐‘–]
712.0 :+ 0.0
72 71
73(the dot symbol "ยท" is obtained by Alt-Gr .)
74 72
75-}
76(<ยท>) :: Numeric t => Vector t -> Vector t -> t
77(<ยท>) = dot
78 73
79 74
80{- | infix synonym for 'app' 75{- | infix synonym for 'app'
@@ -91,6 +86,7 @@ infixr 8 <ยท>, #>
91fromList [140.0,320.0] 86fromList [140.0,320.0]
92 87
93-} 88-}
89infixr 8 #>
94(#>) :: Numeric t => Matrix t -> Vector t -> Vector t 90(#>) :: Numeric t => Matrix t -> Vector t -> Vector t
95(#>) = mXv 91(#>) = mXv
96 92
@@ -264,6 +260,24 @@ instance Numeric Z
264sortVector :: (Ord t, Element t) => Vector t -> Vector t 260sortVector :: (Ord t, Element t) => Vector t -> Vector t
265sortVector = sortV 261sortVector = sortV
266 262
263{- |
264
265>>> m <- randn 4 10
266>>> disp 2 m
2674x10
268-0.31 0.41 0.43 -0.19 -0.17 -0.23 -0.17 -1.04 -0.07 -1.24
269 0.26 0.19 0.14 0.83 -1.54 -0.09 0.37 -0.63 0.71 -0.50
270-0.11 -0.10 -1.29 -1.40 -1.04 -0.89 -0.68 0.35 -1.46 1.86
271 1.04 -0.29 0.19 -0.75 -2.20 -0.01 1.06 0.11 -2.09 -1.58
272
273>>> disp 2 $ m ?? (All, Pos $ sortIndex (m!1))
2744x10
275-0.17 -1.04 -1.24 -0.23 0.43 0.41 -0.31 -0.17 -0.07 -0.19
276-1.54 -0.63 -0.50 -0.09 0.14 0.19 0.26 0.37 0.71 0.83
277-1.04 0.35 1.86 -0.89 -1.29 -0.10 -0.11 -0.68 -1.46 -1.40
278-2.20 0.11 -1.58 -0.01 0.19 -0.29 1.04 1.06 -2.09 -0.75
279
280-}
267sortIndex :: (Ord t, Element t) => Vector t -> Vector I 281sortIndex :: (Ord t, Element t) => Vector t -> Vector I
268sortIndex = sortI 282sortIndex = sortI
269 283
@@ -273,11 +287,50 @@ ccompare = ccompare'
273cselect :: (Container c t) => c I -> c t -> c t -> c t -> c t 287cselect :: (Container c t) => c I -> c t -> c t -> c t -> c t
274cselect = cselect' 288cselect = cselect'
275 289
290{- | Extract elements from positions given in matrices of rows and columns.
291
292>>> r
293(3><3)
294 [ 1, 1, 1
295 , 1, 2, 2
296 , 1, 2, 3 ]
297>>> c
298(3><3)
299 [ 0, 1, 5
300 , 2, 2, 1
301 , 4, 4, 1 ]
302>>> m
303(4><6)
304 [ 0, 1, 2, 3, 4, 5
305 , 6, 7, 8, 9, 10, 11
306 , 12, 13, 14, 15, 16, 17
307 , 18, 19, 20, 21, 22, 23 ]
308
309>>> remap r c m
310(3><3)
311 [ 6, 7, 11
312 , 8, 14, 13
313 , 10, 16, 19 ]
314
315The indexes are autoconformable.
316
317>>> c'
318(3><1)
319 [ 1
320 , 2
321 , 4 ]
322>>> remap r c' m
323(3><3)
324 [ 7, 7, 7
325 , 8, 14, 14
326 , 10, 16, 22 ]
327
328-}
276remap :: Element t => Matrix I -> Matrix I -> Matrix t -> Matrix t 329remap :: Element t => Matrix I -> Matrix I -> Matrix t -> Matrix t
277remap i j m 330remap i j m
278 | minElement i >= 0 && maxElement i < fromIntegral (rows m) && 331 | minElement i >= 0 && maxElement i < fromIntegral (rows m) &&
279 minElement j >= 0 && maxElement j < fromIntegral (cols m) = remapM i' j' m 332 minElement j >= 0 && maxElement j < fromIntegral (cols m) = remapM i' j' m
280 | otherwise = error $ "out of range index in rmap" 333 | otherwise = error $ "out of range index in remap"
281 where 334 where
282 [i',j'] = conformMs [i,j] 335 [i',j'] = conformMs [i,j]
283 336