Add enumFromN, enumFromStepN
[darcs-mirrors/vector.git] / Data / Vector / Unboxed.hs
1 -- |
2 -- Module : Data.Vector.Unboxed
3 -- Copyright : (c) Roman Leshchinskiy 2009
4 -- License : BSD-style
5 --
6 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
7 -- Stability : experimental
8 -- Portability : non-portable
9 --
10 -- Adaptive unboxed vectors
11 --
12
13 module Data.Vector.Unboxed (
14 Vector, MVector(..), Unbox,
15
16 -- * Length information
17 length, null,
18
19 -- * Construction
20 empty, singleton, cons, snoc, replicate, generate, (++), copy,
21
22 -- * Accessing individual elements
23 (!), head, last, indexM, headM, lastM,
24 unsafeIndex, unsafeHead, unsafeLast,
25 unsafeIndexM, unsafeHeadM, unsafeLastM,
26
27 -- * Subvectors
28 slice, init, tail, take, drop,
29 unsafeSlice, unsafeInit, unsafeTail, unsafeTake, unsafeDrop,
30
31 -- * Permutations
32 accum, accumulate, accumulate_,
33 (//), update, update_,
34 backpermute, reverse,
35 unsafeAccum, unsafeAccumulate, unsafeAccumulate_,
36 unsafeUpd, unsafeUpdate, unsafeUpdate_,
37 unsafeBackpermute,
38
39 -- * Mapping
40 map, imap, concatMap,
41
42 -- * Zipping and unzipping
43 zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
44 izipWith, izipWith3, izipWith4, izipWith5, izipWith6,
45 zip, zip3, zip4, zip5, zip6,
46 unzip, unzip3, unzip4, unzip5, unzip6,
47
48 -- * Filtering
49 filter, ifilter, takeWhile, dropWhile,
50 partition, unstablePartition, span, break,
51
52 -- * Searching
53 elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,
54
55 -- * Folding
56 foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',
57 ifoldl, ifoldl', ifoldr, ifoldr',
58
59 -- * Specialised folds
60 all, any, and, or,
61 sum, product,
62 maximum, maximumBy, minimum, minimumBy,
63 minIndex, minIndexBy, maxIndex, maxIndexBy,
64
65 -- * Unfolding
66 unfoldr,
67
68 -- * Scans
69 prescanl, prescanl',
70 postscanl, postscanl',
71 scanl, scanl', scanl1, scanl1',
72 prescanr, prescanr',
73 postscanr, postscanr',
74 scanr, scanr', scanr1, scanr1',
75
76 -- * Enumeration
77 enumFromN, enumFromStepN, enumFromTo, enumFromThenTo,
78
79 -- * Conversion to/from lists
80 toList, fromList
81 ) where
82
83 import Data.Vector.Unboxed.Base
84 import qualified Data.Vector.Generic as G
85 import qualified Data.Vector.Fusion.Stream as Stream
86
87 import Prelude hiding ( length, null,
88 replicate, (++),
89 head, last,
90 init, tail, take, drop, reverse,
91 map, concatMap,
92 zipWith, zipWith3, zip, zip3, unzip, unzip3,
93 filter, takeWhile, dropWhile, span, break,
94 elem, notElem,
95 foldl, foldl1, foldr, foldr1,
96 all, any, and, or, sum, product, minimum, maximum,
97 scanl, scanl1, scanr, scanr1,
98 enumFromTo, enumFromThenTo )
99 import qualified Prelude
100
101 #include "vector.h"
102
103 instance (Unbox a, Eq a) => Eq (Vector a) where
104 {-# INLINE (==) #-}
105 (==) = G.eq
106
107 instance (Unbox a, Ord a) => Ord (Vector a) where
108 {-# INLINE compare #-}
109 compare = G.cmp
110
111 instance (Show a, Unbox a) => Show (Vector a) where
112 show = (Prelude.++ " :: Data.Vector.Unboxed.Vector") . ("fromList " Prelude.++) . show . toList
113
114 -- Length
115 -- ------
116
117 length :: Unbox a => Vector a -> Int
118 {-# INLINE length #-}
119 length = G.length
120
121 null :: Unbox a => Vector a -> Bool
122 {-# INLINE null #-}
123 null = G.null
124
125 -- Construction
126 -- ------------
127
128 -- | Empty vector
129 empty :: Unbox a => Vector a
130 {-# INLINE empty #-}
131 empty = G.empty
132
133 -- | Vector with exaclty one element
134 singleton :: Unbox a => a -> Vector a
135 {-# INLINE singleton #-}
136 singleton = G.singleton
137
138 -- | Vector of the given length with the given value in each position
139 replicate :: Unbox a => Int -> a -> Vector a
140 {-# INLINE replicate #-}
141 replicate = G.replicate
142
143 -- | Generate a vector of the given length by applying the function to each
144 -- index
145 generate :: Unbox a => Int -> (Int -> a) -> Vector a
146 {-# INLINE generate #-}
147 generate = G.generate
148
149 -- | Prepend an element
150 cons :: Unbox a => a -> Vector a -> Vector a
151 {-# INLINE cons #-}
152 cons = G.cons
153
154 -- | Append an element
155 snoc :: Unbox a => Vector a -> a -> Vector a
156 {-# INLINE snoc #-}
157 snoc = G.snoc
158
159 infixr 5 ++
160 -- | Concatenate two vectors
161 (++) :: Unbox a => Vector a -> Vector a -> Vector a
162 {-# INLINE (++) #-}
163 (++) = (G.++)
164
165 -- | Create a copy of a vector. Useful when dealing with slices.
166 copy :: Unbox a => Vector a -> Vector a
167 {-# INLINE copy #-}
168 copy = G.copy
169
170 -- Accessing individual elements
171 -- -----------------------------
172
173 -- | Indexing
174 (!) :: Unbox a => Vector a -> Int -> a
175 {-# INLINE (!) #-}
176 (!) = (G.!)
177
178 -- | First element
179 head :: Unbox a => Vector a -> a
180 {-# INLINE head #-}
181 head = G.head
182
183 -- | Last element
184 last :: Unbox a => Vector a -> a
185 {-# INLINE last #-}
186 last = G.last
187
188 -- | Unsafe indexing without bounds checking
189 unsafeIndex :: Unbox a => Vector a -> Int -> a
190 {-# INLINE unsafeIndex #-}
191 unsafeIndex = G.unsafeIndex
192
193 -- | Yield the first element of a vector without checking if the vector is
194 -- empty
195 unsafeHead :: Unbox a => Vector a -> a
196 {-# INLINE unsafeHead #-}
197 unsafeHead = G.unsafeHead
198
199 -- | Yield the last element of a vector without checking if the vector is
200 -- empty
201 unsafeLast :: Unbox a => Vector a -> a
202 {-# INLINE unsafeLast #-}
203 unsafeLast = G.unsafeLast
204
205 -- | Monadic indexing which can be strict in the vector while remaining lazy in
206 -- the element
207 indexM :: (Unbox a, Monad m) => Vector a -> Int -> m a
208 {-# INLINE indexM #-}
209 indexM = G.indexM
210
211 headM :: (Unbox a, Monad m) => Vector a -> m a
212 {-# INLINE headM #-}
213 headM = G.headM
214
215 lastM :: (Unbox a, Monad m) => Vector a -> m a
216 {-# INLINE lastM #-}
217 lastM = G.lastM
218
219 -- | Unsafe monadic indexing without bounds checks
220 unsafeIndexM :: (Unbox a, Monad m) => Vector a -> Int -> m a
221 {-# INLINE unsafeIndexM #-}
222 unsafeIndexM = G.unsafeIndexM
223
224 unsafeHeadM :: (Unbox a, Monad m) => Vector a -> m a
225 {-# INLINE unsafeHeadM #-}
226 unsafeHeadM = G.unsafeHeadM
227
228 unsafeLastM :: (Unbox a, Monad m) => Vector a -> m a
229 {-# INLINE unsafeLastM #-}
230 unsafeLastM = G.unsafeLastM
231
232 -- Subarrays
233 -- ---------
234
235 -- | Yield a part of the vector without copying it. Safer version of
236 -- 'basicUnsafeSlice'.
237 slice :: Unbox a => Int -- ^ starting index
238 -> Int -- ^ length
239 -> Vector a
240 -> Vector a
241 {-# INLINE slice #-}
242 slice = G.slice
243
244 -- | Yield all but the last element without copying.
245 init :: Unbox a => Vector a -> Vector a
246 {-# INLINE init #-}
247 init = G.init
248
249 -- | All but the first element (without copying).
250 tail :: Unbox a => Vector a -> Vector a
251 {-# INLINE tail #-}
252 tail = G.tail
253
254 -- | Yield the first @n@ elements without copying.
255 take :: Unbox a => Int -> Vector a -> Vector a
256 {-# INLINE take #-}
257 take = G.take
258
259 -- | Yield all but the first @n@ elements without copying.
260 drop :: Unbox a => Int -> Vector a -> Vector a
261 {-# INLINE drop #-}
262 drop = G.drop
263
264 -- | Unsafely yield a part of the vector without copying it and without
265 -- performing bounds checks.
266 unsafeSlice :: Unbox a => Int -- ^ starting index
267 -> Int -- ^ length
268 -> Vector a
269 -> Vector a
270 {-# INLINE unsafeSlice #-}
271 unsafeSlice = G.unsafeSlice
272
273 unsafeInit :: Unbox a => Vector a -> Vector a
274 {-# INLINE unsafeInit #-}
275 unsafeInit = G.unsafeInit
276
277 unsafeTail :: Unbox a => Vector a -> Vector a
278 {-# INLINE unsafeTail #-}
279 unsafeTail = G.unsafeTail
280
281 unsafeTake :: Unbox a => Int -> Vector a -> Vector a
282 {-# INLINE unsafeTake #-}
283 unsafeTake = G.unsafeTake
284
285 unsafeDrop :: Unbox a => Int -> Vector a -> Vector a
286 {-# INLINE unsafeDrop #-}
287 unsafeDrop = G.unsafeDrop
288
289 -- Permutations
290 -- ------------
291
292 unsafeAccum :: Unbox a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
293 {-# INLINE unsafeAccum #-}
294 unsafeAccum = G.unsafeAccum
295
296 unsafeAccumulate :: (Unbox a, Unbox b)
297 => (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
298 {-# INLINE unsafeAccumulate #-}
299 unsafeAccumulate = G.unsafeAccumulate
300
301 unsafeAccumulate_ :: (Unbox a, Unbox b) =>
302 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
303 {-# INLINE unsafeAccumulate_ #-}
304 unsafeAccumulate_ = G.unsafeAccumulate_
305
306 accum :: Unbox a => (a -> b -> a) -> Vector a -> [(Int,b)] -> Vector a
307 {-# INLINE accum #-}
308 accum = G.accum
309
310 accumulate :: (Unbox a, Unbox b)
311 => (a -> b -> a) -> Vector a -> Vector (Int,b) -> Vector a
312 {-# INLINE accumulate #-}
313 accumulate = G.accumulate
314
315 accumulate_ :: (Unbox a, Unbox b) =>
316 (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
317 {-# INLINE accumulate_ #-}
318 accumulate_ = G.accumulate_
319
320 unsafeUpd :: Unbox a => Vector a -> [(Int, a)] -> Vector a
321 {-# INLINE unsafeUpd #-}
322 unsafeUpd = G.unsafeUpd
323
324 unsafeUpdate :: Unbox a => Vector a -> Vector (Int, a) -> Vector a
325 {-# INLINE unsafeUpdate #-}
326 unsafeUpdate = G.unsafeUpdate
327
328 unsafeUpdate_ :: Unbox a => Vector a -> Vector Int -> Vector a -> Vector a
329 {-# INLINE unsafeUpdate_ #-}
330 unsafeUpdate_ = G.unsafeUpdate_
331
332 (//) :: Unbox a => Vector a -> [(Int, a)] -> Vector a
333 {-# INLINE (//) #-}
334 (//) = (G.//)
335
336 update :: Unbox a => Vector a -> Vector (Int, a) -> Vector a
337 {-# INLINE update #-}
338 update = G.update
339
340 update_ :: Unbox a => Vector a -> Vector Int -> Vector a -> Vector a
341 {-# INLINE update_ #-}
342 update_ = G.update_
343
344 backpermute :: Unbox a => Vector a -> Vector Int -> Vector a
345 {-# INLINE backpermute #-}
346 backpermute = G.backpermute
347
348 unsafeBackpermute :: Unbox a => Vector a -> Vector Int -> Vector a
349 {-# INLINE unsafeBackpermute #-}
350 unsafeBackpermute = G.unsafeBackpermute
351
352 reverse :: Unbox a => Vector a -> Vector a
353 {-# INLINE reverse #-}
354 reverse = G.reverse
355
356 -- Mapping
357 -- -------
358
359 -- | Map a function over a vector
360 map :: (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b
361 {-# INLINE map #-}
362 map = G.map
363
364 -- | Apply a function to every index/value pair
365 imap :: (Unbox a, Unbox b) => (Int -> a -> b) -> Vector a -> Vector b
366 {-# INLINE imap #-}
367 imap = G.imap
368
369 concatMap :: (Unbox a, Unbox b) => (a -> Vector b) -> Vector a -> Vector b
370 {-# INLINE concatMap #-}
371 concatMap = G.concatMap
372
373 -- Zipping/unzipping
374 -- -----------------
375
376 -- | Zip two vectors with the given function.
377 zipWith :: (Unbox a, Unbox b, Unbox c)
378 => (a -> b -> c) -> Vector a -> Vector b -> Vector c
379 {-# INLINE zipWith #-}
380 zipWith = G.zipWith
381
382 -- | Zip three vectors with the given function.
383 zipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d)
384 => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
385 {-# INLINE zipWith3 #-}
386 zipWith3 = G.zipWith3
387
388 zipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e)
389 => (a -> b -> c -> d -> e)
390 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
391 {-# INLINE zipWith4 #-}
392 zipWith4 = G.zipWith4
393
394 zipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f)
395 => (a -> b -> c -> d -> e -> f)
396 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
397 -> Vector f
398 {-# INLINE zipWith5 #-}
399 zipWith5 = G.zipWith5
400
401 zipWith6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox g)
402 => (a -> b -> c -> d -> e -> f -> g)
403 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
404 -> Vector f -> Vector g
405 {-# INLINE zipWith6 #-}
406 zipWith6 = G.zipWith6
407
408 -- | Zip two vectors and their indices with the given function.
409 izipWith :: (Unbox a, Unbox b, Unbox c)
410 => (Int -> a -> b -> c) -> Vector a -> Vector b -> Vector c
411 {-# INLINE izipWith #-}
412 izipWith = G.izipWith
413
414 -- | Zip three vectors and their indices with the given function.
415 izipWith3 :: (Unbox a, Unbox b, Unbox c, Unbox d)
416 => (Int -> a -> b -> c -> d)
417 -> Vector a -> Vector b -> Vector c -> Vector d
418 {-# INLINE izipWith3 #-}
419 izipWith3 = G.izipWith3
420
421 izipWith4 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e)
422 => (Int -> a -> b -> c -> d -> e)
423 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
424 {-# INLINE izipWith4 #-}
425 izipWith4 = G.izipWith4
426
427 izipWith5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f)
428 => (Int -> a -> b -> c -> d -> e -> f)
429 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
430 -> Vector f
431 {-# INLINE izipWith5 #-}
432 izipWith5 = G.izipWith5
433
434 izipWith6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f, Unbox g)
435 => (Int -> a -> b -> c -> d -> e -> f -> g)
436 -> Vector a -> Vector b -> Vector c -> Vector d -> Vector e
437 -> Vector f -> Vector g
438 {-# INLINE izipWith6 #-}
439 izipWith6 = G.izipWith6
440
441 -- Filtering
442 -- ---------
443
444 -- | Drop elements which do not satisfy the predicate
445 filter :: Unbox a => (a -> Bool) -> Vector a -> Vector a
446 {-# INLINE filter #-}
447 filter = G.filter
448
449 -- | Drop elements that do not satisfy the predicate (applied to values and
450 -- their indices)
451 ifilter :: Unbox a => (Int -> a -> Bool) -> Vector a -> Vector a
452 {-# INLINE ifilter #-}
453 ifilter = G.ifilter
454
455 -- | Yield the longest prefix of elements satisfying the predicate.
456 takeWhile :: Unbox a => (a -> Bool) -> Vector a -> Vector a
457 {-# INLINE takeWhile #-}
458 takeWhile = G.takeWhile
459
460 -- | Drop the longest prefix of elements that satisfy the predicate.
461 dropWhile :: Unbox a => (a -> Bool) -> Vector a -> Vector a
462 {-# INLINE dropWhile #-}
463 dropWhile = G.dropWhile
464
465 -- | Split the vector in two parts, the first one containing those elements
466 -- that satisfy the predicate and the second one those that don't. The
467 -- relative order of the elements is preserved at the cost of a (sometimes)
468 -- reduced performance compared to 'unstablePartition'.
469 partition :: Unbox a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
470 {-# INLINE partition #-}
471 partition = G.partition
472
473 -- | Split the vector in two parts, the first one containing those elements
474 -- that satisfy the predicate and the second one those that don't. The order
475 -- of the elements is not preserved.
476 unstablePartition :: Unbox a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
477 {-# INLINE unstablePartition #-}
478 unstablePartition = G.unstablePartition
479
480 -- | Split the vector into the longest prefix of elements that satisfy the
481 -- predicate and the rest.
482 span :: Unbox a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
483 {-# INLINE span #-}
484 span = G.span
485
486 -- | Split the vector into the longest prefix of elements that do not satisfy
487 -- the predicate and the rest.
488 break :: Unbox a => (a -> Bool) -> Vector a -> (Vector a, Vector a)
489 {-# INLINE break #-}
490 break = G.break
491
492 -- Searching
493 -- ---------
494
495 infix 4 `elem`
496 -- | Check whether the vector contains an element
497 elem :: (Unbox a, Eq a) => a -> Vector a -> Bool
498 {-# INLINE elem #-}
499 elem = G.elem
500
501 infix 4 `notElem`
502 -- | Inverse of `elem`
503 notElem :: (Unbox a, Eq a) => a -> Vector a -> Bool
504 {-# INLINE notElem #-}
505 notElem = G.notElem
506
507 -- | Yield 'Just' the first element matching the predicate or 'Nothing' if no
508 -- such element exists.
509 find :: Unbox a => (a -> Bool) -> Vector a -> Maybe a
510 {-# INLINE find #-}
511 find = G.find
512
513 -- | Yield 'Just' the index of the first element matching the predicate or
514 -- 'Nothing' if no such element exists.
515 findIndex :: Unbox a => (a -> Bool) -> Vector a -> Maybe Int
516 {-# INLINE findIndex #-}
517 findIndex = G.findIndex
518
519 -- | Yield the indices of elements satisfying the predicate
520 findIndices :: Unbox a => (a -> Bool) -> Vector a -> Vector Int
521 {-# INLINE findIndices #-}
522 findIndices = G.findIndices
523
524 -- | Yield 'Just' the index of the first occurence of the given element or
525 -- 'Nothing' if the vector does not contain the element
526 elemIndex :: (Unbox a, Eq a) => a -> Vector a -> Maybe Int
527 {-# INLINE elemIndex #-}
528 elemIndex = G.elemIndex
529
530 -- | Yield the indices of all occurences of the given element
531 elemIndices :: (Unbox a, Eq a) => a -> Vector a -> Vector Int
532 {-# INLINE elemIndices #-}
533 elemIndices = G.elemIndices
534
535 -- Folding
536 -- -------
537
538 -- | Left fold
539 foldl :: Unbox b => (a -> b -> a) -> a -> Vector b -> a
540 {-# INLINE foldl #-}
541 foldl = G.foldl
542
543 -- | Lefgt fold on non-empty vectors
544 foldl1 :: Unbox a => (a -> a -> a) -> Vector a -> a
545 {-# INLINE foldl1 #-}
546 foldl1 = G.foldl1
547
548 -- | Left fold with strict accumulator
549 foldl' :: Unbox b => (a -> b -> a) -> a -> Vector b -> a
550 {-# INLINE foldl' #-}
551 foldl' = G.foldl'
552
553 -- | Left fold on non-empty vectors with strict accumulator
554 foldl1' :: Unbox a => (a -> a -> a) -> Vector a -> a
555 {-# INLINE foldl1' #-}
556 foldl1' = G.foldl1'
557
558 -- | Right fold
559 foldr :: Unbox a => (a -> b -> b) -> b -> Vector a -> b
560 {-# INLINE foldr #-}
561 foldr = G.foldr
562
563 -- | Right fold on non-empty vectors
564 foldr1 :: Unbox a => (a -> a -> a) -> Vector a -> a
565 {-# INLINE foldr1 #-}
566 foldr1 = G.foldr1
567
568 -- | Right fold with a strict accumulator
569 foldr' :: Unbox a => (a -> b -> b) -> b -> Vector a -> b
570 {-# INLINE foldr' #-}
571 foldr' = G.foldr'
572
573 -- | Right fold on non-empty vectors with strict accumulator
574 foldr1' :: Unbox a => (a -> a -> a) -> Vector a -> a
575 {-# INLINE foldr1' #-}
576 foldr1' = G.foldr1'
577
578 -- | Left fold (function applied to each element and its index)
579 ifoldl :: Unbox b => (a -> Int -> b -> a) -> a -> Vector b -> a
580 {-# INLINE ifoldl #-}
581 ifoldl = G.ifoldl
582
583 -- | Left fold with strict accumulator (function applied to each element and
584 -- its index)
585 ifoldl' :: Unbox b => (a -> Int -> b -> a) -> a -> Vector b -> a
586 {-# INLINE ifoldl' #-}
587 ifoldl' = G.ifoldl'
588
589 -- | Right fold (function applied to each element and its index)
590 ifoldr :: Unbox a => (Int -> a -> b -> b) -> b -> Vector a -> b
591 {-# INLINE ifoldr #-}
592 ifoldr = G.ifoldr
593
594 -- | Right fold with strict accumulator (function applied to each element and
595 -- its index)
596 ifoldr' :: Unbox a => (Int -> a -> b -> b) -> b -> Vector a -> b
597 {-# INLINE ifoldr' #-}
598 ifoldr' = G.ifoldr'
599
600 -- Specialised folds
601 -- -----------------
602
603 all :: Unbox a => (a -> Bool) -> Vector a -> Bool
604 {-# INLINE all #-}
605 all = G.all
606
607 any :: Unbox a => (a -> Bool) -> Vector a -> Bool
608 {-# INLINE any #-}
609 any = G.any
610
611 and :: Vector Bool -> Bool
612 {-# INLINE and #-}
613 and = G.and
614
615 or :: Vector Bool -> Bool
616 {-# INLINE or #-}
617 or = G.or
618
619 sum :: (Unbox a, Num a) => Vector a -> a
620 {-# INLINE sum #-}
621 sum = G.sum
622
623 product :: (Unbox a, Num a) => Vector a -> a
624 {-# INLINE product #-}
625 product = G.product
626
627 maximum :: (Unbox a, Ord a) => Vector a -> a
628 {-# INLINE maximum #-}
629 maximum = G.maximum
630
631 maximumBy :: Unbox a => (a -> a -> Ordering) -> Vector a -> a
632 {-# INLINE maximumBy #-}
633 maximumBy = G.maximumBy
634
635 minimum :: (Unbox a, Ord a) => Vector a -> a
636 {-# INLINE minimum #-}
637 minimum = G.minimum
638
639 minimumBy :: Unbox a => (a -> a -> Ordering) -> Vector a -> a
640 {-# INLINE minimumBy #-}
641 minimumBy = G.minimumBy
642
643 maxIndex :: (Unbox a, Ord a) => Vector a -> Int
644 {-# INLINE maxIndex #-}
645 maxIndex = G.maxIndex
646
647 maxIndexBy :: Unbox a => (a -> a -> Ordering) -> Vector a -> Int
648 {-# INLINE maxIndexBy #-}
649 maxIndexBy = G.maxIndexBy
650
651 minIndex :: (Unbox a, Ord a) => Vector a -> Int
652 {-# INLINE minIndex #-}
653 minIndex = G.minIndex
654
655 minIndexBy :: Unbox a => (a -> a -> Ordering) -> Vector a -> Int
656 {-# INLINE minIndexBy #-}
657 minIndexBy = G.minIndexBy
658
659 -- Unfolding
660 -- ---------
661
662 unfoldr :: Unbox a => (b -> Maybe (a, b)) -> b -> Vector a
663 {-# INLINE unfoldr #-}
664 unfoldr = G.unfoldr
665
666 -- Scans
667 -- -----
668
669 -- | Prefix scan
670 prescanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
671 {-# INLINE prescanl #-}
672 prescanl = G.prescanl
673
674 -- | Prefix scan with strict accumulator
675 prescanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
676 {-# INLINE prescanl' #-}
677 prescanl' = G.prescanl'
678
679 -- | Suffix scan
680 postscanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
681 {-# INLINE postscanl #-}
682 postscanl = G.postscanl
683
684 -- | Suffix scan with strict accumulator
685 postscanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
686 {-# INLINE postscanl' #-}
687 postscanl' = G.postscanl'
688
689 -- | Haskell-style scan
690 scanl :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
691 {-# INLINE scanl #-}
692 scanl = G.scanl
693
694 -- | Haskell-style scan with strict accumulator
695 scanl' :: (Unbox a, Unbox b) => (a -> b -> a) -> a -> Vector b -> Vector a
696 {-# INLINE scanl' #-}
697 scanl' = G.scanl'
698
699 -- | Scan over a non-empty 'Vector'
700 scanl1 :: Unbox a => (a -> a -> a) -> Vector a -> Vector a
701 {-# INLINE scanl1 #-}
702 scanl1 = G.scanl1
703
704 -- | Scan over a non-empty 'Vector' with a strict accumulator
705 scanl1' :: Unbox a => (a -> a -> a) -> Vector a -> Vector a
706 {-# INLINE scanl1' #-}
707 scanl1' = G.scanl1'
708
709
710 -- | Prefix right-to-left scan
711 prescanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
712 {-# INLINE prescanr #-}
713 prescanr = G.prescanr
714
715 -- | Prefix right-to-left scan with strict accumulator
716 prescanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
717 {-# INLINE prescanr' #-}
718 prescanr' = G.prescanr'
719
720 -- | Suffix right-to-left scan
721 postscanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
722 {-# INLINE postscanr #-}
723 postscanr = G.postscanr
724
725 -- | Suffix right-to-left scan with strict accumulator
726 postscanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
727 {-# INLINE postscanr' #-}
728 postscanr' = G.postscanr'
729
730 -- | Haskell-style right-to-left scan
731 scanr :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
732 {-# INLINE scanr #-}
733 scanr = G.scanr
734
735 -- | Haskell-style right-to-left scan with strict accumulator
736 scanr' :: (Unbox a, Unbox b) => (a -> b -> b) -> b -> Vector a -> Vector b
737 {-# INLINE scanr' #-}
738 scanr' = G.scanr'
739
740 -- | Right-to-left scan over a non-empty vector
741 scanr1 :: Unbox a => (a -> a -> a) -> Vector a -> Vector a
742 {-# INLINE scanr1 #-}
743 scanr1 = G.scanr1
744
745 -- | Right-to-left scan over a non-empty vector with a strict accumulator
746 scanr1' :: Unbox a => (a -> a -> a) -> Vector a -> Vector a
747 {-# INLINE scanr1' #-}
748 scanr1' = G.scanr1'
749
750 -- Enumeration
751 -- -----------
752
753 -- | Yield a vector of the given length containing the values @x@, @x+1@ etc.
754 -- This operation is usually more efficient than 'enumFromTo'.
755 enumFromN :: (Unbox a, Num a) => a -> Int -> Vector a
756 {-# INLINE enumFromN #-}
757 enumFromN = G.enumFromN
758
759 -- | Yield a vector of the given length containing the values @x@, @x+y@,
760 -- @x+y+y@ etc. This operations is usually more efficient than
761 -- 'enumFromThenTo'.
762 enumFromStepN :: (Unbox a, Num a) => a -> a -> Int -> Vector a
763 {-# INLINE enumFromStepN #-}
764 enumFromStepN = G.enumFromStepN
765
766 -- | Enumerate values from @x@ to @y@.
767 --
768 -- /WARNING:/ This operation can be very inefficient. If at all possible, use
769 -- 'enumFromN' instead.
770 enumFromTo :: (Unbox a, Enum a) => a -> a -> Vector a
771 {-# INLINE enumFromTo #-}
772 enumFromTo = G.enumFromTo
773
774 -- | Enumerate values from @x@ to @y@ with a specific step @z@.
775 --
776 -- /WARNING:/ This operation can be very inefficient. If at all possible, use
777 -- 'enumFromStepN' instead.
778 enumFromThenTo :: (Unbox a, Enum a) => a -> a -> a -> Vector a
779 {-# INLINE enumFromThenTo #-}
780 enumFromThenTo = G.enumFromThenTo
781
782 -- Conversion to/from lists
783 -- ------------------------
784
785 -- | Convert a vector to a list
786 toList :: Unbox a => Vector a -> [a]
787 {-# INLINE toList #-}
788 toList = G.toList
789
790 -- | Convert a list to a vector
791 fromList :: Unbox a => [a] -> Vector a
792 {-# INLINE fromList #-}
793 fromList = G.fromList
794
795 #define DEFINE_IMMUTABLE
796 #include "unbox-tuple-instances"
797