summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Element.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/Element.hs')
-rw-r--r--packages/base/src/Internal/Element.hs38
1 files changed, 33 insertions, 5 deletions
diff --git a/packages/base/src/Internal/Element.hs b/packages/base/src/Internal/Element.hs
index 4007491..51d5686 100644
--- a/packages/base/src/Internal/Element.hs
+++ b/packages/base/src/Internal/Element.hs
@@ -80,7 +80,7 @@ breakAt c l = (a++[c],tail b) where
80 (a,b) = break (==c) l 80 (a,b) = break (==c) l
81 81
82-------------------------------------------------------------------------------- 82--------------------------------------------------------------------------------
83 83-- | Specification of indexes for the operator '??'.
84data Extractor 84data Extractor
85 = All 85 = All
86 | Range Int Int Int 86 | Range Int Int Int
@@ -102,7 +102,32 @@ ppext (Drop n) = printf "Drop %d" n
102ppext (TakeLast n) = printf "TakeLast %d" n 102ppext (TakeLast n) = printf "TakeLast %d" n
103ppext (DropLast n) = printf "DropLast %d" n 103ppext (DropLast n) = printf "DropLast %d" n
104 104
105{- | General matrix slicing.
106
107>>> m
108(4><5)
109 [ 0, 1, 2, 3, 4
110 , 5, 6, 7, 8, 9
111 , 10, 11, 12, 13, 14
112 , 15, 16, 17, 18, 19 ]
113
114>>> m ?? (Take 3, DropLast 2)
115(3><3)
116 [ 0, 1, 2
117 , 5, 6, 7
118 , 10, 11, 12 ]
119
120>>> m ?? (Pos (idxs[2,1]), All)
121(2><5)
122 [ 10, 11, 12, 13, 14
123 , 5, 6, 7, 8, 9 ]
124
125>>> m ?? (PosCyc (idxs[-7,80]), Range 4 (-2) 0)
126(2><3)
127 [ 9, 7, 5
128 , 4, 2, 0 ]
105 129
130-}
106infixl 9 ?? 131infixl 9 ??
107(??) :: Element t => Matrix t -> (Extractor,Extractor) -> Matrix t 132(??) :: Element t => Matrix t -> (Extractor,Extractor) -> Matrix t
108 133
@@ -328,27 +353,30 @@ r >< c = f where
328 353
329---------------------------------------------------------------- 354----------------------------------------------------------------
330 355
331-- | Creates a matrix with the first n rows of another matrix
332takeRows :: Element t => Int -> Matrix t -> Matrix t 356takeRows :: Element t => Int -> Matrix t -> Matrix t
333takeRows n mt = subMatrix (0,0) (n, cols mt) mt 357takeRows n mt = subMatrix (0,0) (n, cols mt) mt
358
334-- | Creates a matrix with the last n rows of another matrix 359-- | Creates a matrix with the last n rows of another matrix
335takeLastRows :: Element t => Int -> Matrix t -> Matrix t 360takeLastRows :: Element t => Int -> Matrix t -> Matrix t
336takeLastRows n mt = subMatrix (rows mt - n, 0) (n, cols mt) mt 361takeLastRows n mt = subMatrix (rows mt - n, 0) (n, cols mt) mt
337-- | Creates a copy of a matrix without the first n rows 362
338dropRows :: Element t => Int -> Matrix t -> Matrix t 363dropRows :: Element t => Int -> Matrix t -> Matrix t
339dropRows n mt = subMatrix (n,0) (rows mt - n, cols mt) mt 364dropRows n mt = subMatrix (n,0) (rows mt - n, cols mt) mt
365
340-- | Creates a copy of a matrix without the last n rows 366-- | Creates a copy of a matrix without the last n rows
341dropLastRows :: Element t => Int -> Matrix t -> Matrix t 367dropLastRows :: Element t => Int -> Matrix t -> Matrix t
342dropLastRows n mt = subMatrix (0,0) (rows mt - n, cols mt) mt 368dropLastRows n mt = subMatrix (0,0) (rows mt - n, cols mt) mt
343-- |Creates a matrix with the first n columns of another matrix 369
344takeColumns :: Element t => Int -> Matrix t -> Matrix t 370takeColumns :: Element t => Int -> Matrix t -> Matrix t
345takeColumns n mt = subMatrix (0,0) (rows mt, n) mt 371takeColumns n mt = subMatrix (0,0) (rows mt, n) mt
372
346-- |Creates a matrix with the last n columns of another matrix 373-- |Creates a matrix with the last n columns of another matrix
347takeLastColumns :: Element t => Int -> Matrix t -> Matrix t 374takeLastColumns :: Element t => Int -> Matrix t -> Matrix t
348takeLastColumns n mt = subMatrix (0, cols mt - n) (rows mt, n) mt 375takeLastColumns n mt = subMatrix (0, cols mt - n) (rows mt, n) mt
349-- | Creates a copy of a matrix without the first n columns 376
350dropColumns :: Element t => Int -> Matrix t -> Matrix t 377dropColumns :: Element t => Int -> Matrix t -> Matrix t
351dropColumns n mt = subMatrix (0,n) (rows mt, cols mt - n) mt 378dropColumns n mt = subMatrix (0,n) (rows mt, cols mt - n) mt
379
352-- | Creates a copy of a matrix without the last n columns 380-- | Creates a copy of a matrix without the last n columns
353dropLastColumns :: Element t => Int -> Matrix t -> Matrix t 381dropLastColumns :: Element t => Int -> Matrix t -> Matrix t
354dropLastColumns n mt = subMatrix (0,0) (rows mt, cols mt - n) mt 382dropLastColumns n mt = subMatrix (0,0) (rows mt, cols mt - n) mt