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