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