diff options
Diffstat (limited to 'packages/base/src/Internal/Element.hs')
-rw-r--r-- | packages/base/src/Internal/Element.hs | 38 |
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 '??'. | |
84 | data Extractor | 84 | data 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 | |||
102 | ppext (TakeLast n) = printf "TakeLast %d" n | 102 | ppext (TakeLast n) = printf "TakeLast %d" n |
103 | ppext (DropLast n) = printf "DropLast %d" n | 103 | ppext (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 | -} | ||
106 | infixl 9 ?? | 131 | infixl 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 | ||
332 | takeRows :: Element t => Int -> Matrix t -> Matrix t | 356 | takeRows :: Element t => Int -> Matrix t -> Matrix t |
333 | takeRows n mt = subMatrix (0,0) (n, cols mt) mt | 357 | takeRows 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 |
335 | takeLastRows :: Element t => Int -> Matrix t -> Matrix t | 360 | takeLastRows :: Element t => Int -> Matrix t -> Matrix t |
336 | takeLastRows n mt = subMatrix (rows mt - n, 0) (n, cols mt) mt | 361 | takeLastRows n mt = subMatrix (rows mt - n, 0) (n, cols mt) mt |
337 | -- | Creates a copy of a matrix without the first n rows | 362 | |
338 | dropRows :: Element t => Int -> Matrix t -> Matrix t | 363 | dropRows :: Element t => Int -> Matrix t -> Matrix t |
339 | dropRows n mt = subMatrix (n,0) (rows mt - n, cols mt) mt | 364 | dropRows 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 |
341 | dropLastRows :: Element t => Int -> Matrix t -> Matrix t | 367 | dropLastRows :: Element t => Int -> Matrix t -> Matrix t |
342 | dropLastRows n mt = subMatrix (0,0) (rows mt - n, cols mt) mt | 368 | dropLastRows n mt = subMatrix (0,0) (rows mt - n, cols mt) mt |
343 | -- |Creates a matrix with the first n columns of another matrix | 369 | |
344 | takeColumns :: Element t => Int -> Matrix t -> Matrix t | 370 | takeColumns :: Element t => Int -> Matrix t -> Matrix t |
345 | takeColumns n mt = subMatrix (0,0) (rows mt, n) mt | 371 | takeColumns 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 |
347 | takeLastColumns :: Element t => Int -> Matrix t -> Matrix t | 374 | takeLastColumns :: Element t => Int -> Matrix t -> Matrix t |
348 | takeLastColumns n mt = subMatrix (0, cols mt - n) (rows mt, n) mt | 375 | takeLastColumns n mt = subMatrix (0, cols mt - n) (rows mt, n) mt |
349 | -- | Creates a copy of a matrix without the first n columns | 376 | |
350 | dropColumns :: Element t => Int -> Matrix t -> Matrix t | 377 | dropColumns :: Element t => Int -> Matrix t -> Matrix t |
351 | dropColumns n mt = subMatrix (0,n) (rows mt, cols mt - n) mt | 378 | dropColumns 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 |
353 | dropLastColumns :: Element t => Int -> Matrix t -> Matrix t | 381 | dropLastColumns :: Element t => Int -> Matrix t -> Matrix t |
354 | dropLastColumns n mt = subMatrix (0,0) (rows mt, cols mt - n) mt | 382 | dropLastColumns n mt = subMatrix (0,0) (rows mt, cols mt - n) mt |