{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Vector.SEXP
( Vector(..)
, Mutable.MVector(..)
, ElemRep
, VECTOR
, Data.Vector.SEXP.fromSEXP
, unsafeFromSEXP
, Data.Vector.SEXP.toSEXP
, unsafeToSEXP
, length
, null
, (!)
, (!?)
, head
, last
, unsafeIndex
, unsafeHead
, unsafeLast
, indexM
, headM
, lastM
, unsafeIndexM
, unsafeHeadM
, unsafeLastM
, slice
, init
, take
, drop
, tail
, splitAt
, unsafeTail
, unsafeSlice
, unsafeDrop
, unsafeTake
, unsafeInit
, empty
, singleton
, replicate
, generate
, iterateN
, replicateM
, generateM
, create
, unfoldr
, unfoldrN
, constructN
, constructrN
, enumFromN
, enumFromStepN
, enumFromTo
, enumFromThenTo
, cons
, snoc
, (++)
, concat
, force
, (//)
, unsafeUpd
, accum
, unsafeAccum
, reverse
, map
, imap
, concatMap
, mapM
, mapM_
, forM
, forM_
, zipWith
, zipWith3
, zipWith4
, zipWith5
, zipWith6
, izipWith
, izipWith3
, izipWith4
, izipWith5
, izipWith6
, zipWithM
, zipWithM_
, filter
, ifilter
, filterM
, takeWhile
, dropWhile
, partition
, unstablePartition
, span
, break
, elem
, notElem
, find
, findIndex
, elemIndex
, foldl
, foldl1
, foldl'
, foldl1'
, foldr
, foldr1
, foldr'
, foldr1'
, ifoldl
, ifoldl'
, ifoldr
, ifoldr'
, all
, any
, sum
, product
, maximum
, maximumBy
, minimum
, minimumBy
, minIndex
, minIndexBy
, maxIndex
, maxIndexBy
, foldM
, foldM'
, fold1M
, fold1M'
, foldM_
, foldM'_
, fold1M_
, fold1M'_
, prescanl
, prescanl'
, postscanl
, postscanl'
, scanl
, scanl'
, scanl1
, scanl1'
, prescanr
, prescanr'
, postscanr
, postscanr'
, scanr
, scanr'
, scanr1
, scanr1'
, toList
, fromList
, fromListN
, freeze
, thaw
, copy
, unsafeFreeze
, unsafeThaw
, unsafeCopy
, toString
, toByteString
) where
import Control.Monad.R.Class
import Control.Monad.R.Internal
import Control.Memory.Region
import Data.Vector.SEXP.Base
import Data.Vector.SEXP.Mutable (MVector)
import qualified Data.Vector.SEXP.Mutable as Mutable
import qualified Data.Vector.SEXP.Mutable.Internal as Mutable
import Foreign.R ( SEXP(..) )
import qualified Foreign.R as R
import Foreign.R.Type ( SEXPTYPE(Char) )
import Control.Monad.Primitive ( PrimMonad )
import Control.Monad.ST (ST, runST)
import Data.Int
import Data.Proxy (Proxy(..))
import Data.Reflection (Reifies(..), reify)
import qualified Data.Vector.Generic as G
import Data.Vector.Generic.New (run)
import Data.ByteString ( ByteString )
import qualified Data.ByteString as B
import Control.Applicative hiding (empty)
#if MIN_VERSION_vector(0,11,0)
import qualified Data.Vector.Fusion.Bundle.Monadic as Bundle
import Data.Vector.Fusion.Bundle.Monadic (sSize, sElems)
import Data.Vector.Fusion.Bundle.Size (Size(Unknown), smaller)
import Data.Vector.Fusion.Bundle (lift)
import qualified Data.Vector.Fusion.Stream.Monadic as Stream
import qualified Data.List as List
#else
import qualified Data.Vector.Fusion.Stream as Stream
import qualified Data.Vector.Fusion.Stream.Monadic as MStream
#endif
import Control.Monad.Primitive ( unsafeInlineIO, unsafePrimToPrim )
import Data.Word ( Word8 )
import Foreign ( Storable, Ptr, castPtr, peekElemOff )
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Marshal.Array ( copyArray )
import qualified GHC.Foreign as GHC
import qualified GHC.ForeignPtr as GHC
import GHC.IO.Encoding.UTF8
#if __GLASGOW_HASKELL__ >= 708
import qualified GHC.Exts as Exts
#endif
import System.IO.Unsafe
import Prelude
( Eq(..)
, Enum
, Monad(..)
, Num(..)
, Ord(..)
, Show(..)
, Bool
, IO
, Maybe
, Ordering
, String
, (.)
, ($)
, fromIntegral
, seq
, uncurry
)
import qualified Prelude
newtype ForeignSEXP (ty::SEXPTYPE) = ForeignSEXP (ForeignPtr ())
foreignSEXP :: PrimMonad m => SEXP s ty -> m (ForeignSEXP ty)
foreignSEXP sx@(SEXP ptr) =
unsafePrimToPrim $ do
R.preserveObject sx
ForeignSEXP <$> GHC.newConcForeignPtr (castPtr ptr) (R.releaseObject sx)
withForeignSEXP
:: ForeignSEXP ty
-> (SEXP s ty -> IO r)
-> IO r
withForeignSEXP (ForeignSEXP fptr) f =
withForeignPtr fptr $ \ptr -> f (SEXP (castPtr ptr))
data Vector s (ty :: SEXPTYPE) a = Vector
{ vectorBase :: {-# UNPACK #-} !(ForeignSEXP ty)
, vectorOffset :: {-# UNPACK #-} !Int32
, vectorLength :: {-# UNPACK #-} !Int32
}
instance (Eq a, VECTOR s ty a) => Eq (Vector s ty a) where
a == b = toList a == toList b
instance (Show a, VECTOR s ty a) => Show (Vector s ty a) where
show v = "fromList " Prelude.++ showList (toList v) ""
newtype W t ty s a = W { unW :: Vector s ty a }
withW :: proxy t -> Vector s ty a -> W t ty s a
withW _ v = W v
proxyFW :: (W t ty s a -> r) -> Vector s ty a -> p t -> r
proxyFW f v p = f (withW p v)
proxyFW2 :: (W t tya s a -> W t tyb s b -> r) -> Vector s tya a -> Vector s tyb b -> p t -> r
proxyFW2 f v1 v2 p = f (withW p v1) (withW p v2)
proxyW :: W t ty s a -> p t -> Vector s ty a
proxyW v _ = unW v
type instance G.Mutable (W t ty s) = Mutable.W t ty
instance (Reifies t (AcquireIO s), VECTOR s ty a) => G.Vector (W t ty s) a where
{-# INLINE basicUnsafeFreeze #-}
basicUnsafeFreeze (Mutable.unW -> Mutable.MVector sx off len) = do
fp <- foreignSEXP sx
return $ W $ Vector fp off len
{-# INLINE basicUnsafeThaw #-}
basicUnsafeThaw (unW -> Vector fp off len) = unsafePrimToPrim $
withForeignSEXP fp $ \ptr -> do
sx' <- acquireIO (R.release ptr)
return $ Mutable.withW p $ Mutable.MVector (R.unsafeRelease sx') off len
where
AcquireIO acquireIO = reflect (Proxy :: Proxy t)
p = Proxy :: Proxy t
basicLength (unW -> Vector _ _ len) = fromIntegral len
{-# INLINE basicUnsafeSlice #-}
basicUnsafeSlice (fromIntegral ->i)
(fromIntegral ->n) (unW -> Vector fp off _len) = W $ Vector fp (off + i) n
{-# INLINE basicUnsafeIndexM #-}
basicUnsafeIndexM v i = return . unsafeInlineIO $ peekElemOff (unsafeToPtr (unW v)) i
{-# INLINE basicUnsafeCopy #-}
basicUnsafeCopy mv v =
unsafePrimToPrim $
copyArray (Mutable.unsafeToPtr (Mutable.unW mv))
(unsafeToPtr (unW v))
(G.basicLength v)
{-# INLINE elemseq #-}
elemseq _ = seq
#if __GLASGOW_HASKELL__ >= 708
instance VECTOR s ty a => Exts.IsList (Vector s ty a) where
type Item (Vector s ty a) = a
fromList = fromList
fromListN = fromListN
toList = toList
#endif
unsafeToPtr :: Storable a => Vector s ty a -> Ptr a
{-# INLINE unsafeToPtr #-}
unsafeToPtr (Vector fp off len) = unsafeInlineIO $ withForeignSEXP fp $ \sx ->
return $ Mutable.unsafeToPtr $ Mutable.MVector sx off len
fromSEXP :: (VECTOR s ty a) => SEXP s ty -> Vector s ty a
fromSEXP s = phony $ \p -> runST $ do w <- run (proxyFW G.clone (unsafeFromSEXP s) p)
v <- G.unsafeFreeze w
return (unW v)
unsafeFromSEXP :: VECTOR s ty a
=> SEXP s ty
-> Vector s ty a
unsafeFromSEXP s = unsafeInlineIO $ do
sxp <- foreignSEXP s
l <- R.length s
return $ Vector sxp 0 (fromIntegral l)
toSEXP :: VECTOR s ty a => Vector s ty a -> SEXP s ty
toSEXP s = phony $ \p -> runST $ do w <- run (proxyFW G.clone s p)
v <- G.unsafeFreeze w
return (unsafeToSEXP (unW v))
unsafeToSEXP :: VECTOR s ty a => Vector s ty a -> SEXP s ty
unsafeToSEXP (Vector (ForeignSEXP fsx) _ _) = unsafePerformIO $
withForeignPtr fsx $ return . R.sexp . castPtr
toString :: Vector s 'Char Word8 -> String
toString v = unsafeInlineIO $
GHC.peekCStringLen utf8 ( castPtr $ unsafeToPtr v
, fromIntegral $ vectorLength v)
toByteString :: Vector s 'Char Word8 -> ByteString
toByteString v = unsafeInlineIO $
B.packCStringLen ( castPtr $ unsafeToPtr v
, fromIntegral $ vectorLength v)
length :: VECTOR s ty a => Vector s ty a -> Int
{-# INLINE length #-}
length v = phony $ proxyFW G.length v
null :: VECTOR s ty a => Vector s ty a -> Bool
{-# INLINE null #-}
null v = phony $ proxyFW G.null v
(!) :: VECTOR s ty a => Vector s ty a -> Int -> a
{-# INLINE (!) #-}
(!) v i = phony $ proxyFW (G.! i) v
(!?) :: VECTOR s ty a => Vector s ty a -> Int -> Maybe a
{-# INLINE (!?) #-}
(!?) v i = phony $ proxyFW (G.!? i) v
head :: VECTOR s ty a => Vector s ty a -> a
{-# INLINE head #-}
head v = phony $ proxyFW G.head v
last :: VECTOR s ty a => Vector s ty a -> a
{-# INLINE last #-}
last v = phony $ proxyFW G.last v
unsafeIndex :: VECTOR s ty a => Vector s ty a -> Int -> a
{-# INLINE unsafeIndex #-}
unsafeIndex v i = phony $ proxyFW (`G.unsafeIndex` i) v
unsafeHead :: VECTOR s ty a => Vector s ty a -> a
{-# INLINE unsafeHead #-}
unsafeHead v = phony $ proxyFW G.unsafeHead v
unsafeLast :: VECTOR s ty a => Vector s ty a -> a
{-# INLINE unsafeLast #-}
unsafeLast v = phony $ proxyFW G.unsafeLast v
indexM :: (VECTOR s ty a, Monad m) => Vector s ty a -> Int -> m a
{-# INLINE indexM #-}
indexM v i = phony $ proxyFW (`G.indexM` i) v
headM :: (VECTOR s ty a, Monad m) => Vector s ty a -> m a
{-# INLINE headM #-}
headM v = phony $ proxyFW G.headM v
lastM :: (VECTOR s ty a, Monad m) => Vector s ty a -> m a
{-# INLINE lastM #-}
lastM v = phony $ proxyFW G.lastM v
unsafeIndexM :: (VECTOR s ty a, Monad m) => Vector s ty a -> Int -> m a
{-# INLINE unsafeIndexM #-}
unsafeIndexM v = phony $ proxyFW G.unsafeIndexM v
unsafeHeadM :: (VECTOR s ty a, Monad m) => Vector s ty a -> m a
{-# INLINE unsafeHeadM #-}
unsafeHeadM v = phony $ proxyFW G.unsafeHeadM v
unsafeLastM :: (VECTOR s ty a, Monad m) => Vector s ty a -> m a
{-# INLINE unsafeLastM #-}
unsafeLastM v = phony $ proxyFW G.unsafeLastM v
slice :: VECTOR s ty a
=> Int
-> Int
-> Vector s ty a
-> Vector s ty a
{-# INLINE slice #-}
slice i n v = phony $ unW . proxyFW (G.slice i n) v
init :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE init #-}
init v = phony $ unW . proxyFW G.init v
tail :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE tail #-}
tail v = phony $ unW . proxyFW G.tail v
take :: VECTOR s ty a => Int -> Vector s ty a -> Vector s ty a
{-# INLINE take #-}
take i v = phony $ unW . proxyFW (G.take i) v
drop :: VECTOR s ty a => Int -> Vector s ty a -> Vector s ty a
{-# INLINE drop #-}
drop i v = phony $ unW . proxyFW (G.drop i) v
{-# INLINE splitAt #-}
splitAt :: VECTOR s ty a => Int -> Vector s ty a -> (Vector s ty a, Vector s ty a)
splitAt i v = phony $ (\(a,b) -> (unW a, unW b)) . proxyFW (G.splitAt i) v
unsafeSlice :: VECTOR s ty a => Int
-> Int
-> Vector s ty a
-> Vector s ty a
{-# INLINE unsafeSlice #-}
unsafeSlice i j v = phony $ unW . proxyFW (G.unsafeSlice i j) v
unsafeInit :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE unsafeInit #-}
unsafeInit v = phony $ unW . proxyFW G.unsafeInit v
unsafeTail :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE unsafeTail #-}
unsafeTail v = phony $ unW . proxyFW G.unsafeTail v
unsafeTake :: VECTOR s ty a => Int -> Vector s ty a -> Vector s ty a
{-# INLINE unsafeTake #-}
unsafeTake i v = phony $ unW . proxyFW (G.unsafeTake i) v
unsafeDrop :: VECTOR s ty a => Int -> Vector s ty a -> Vector s ty a
{-# INLINE unsafeDrop #-}
unsafeDrop i v = phony $ unW . proxyFW (G.unsafeDrop i) v
empty :: VECTOR s ty a => Vector s ty a
{-# INLINE empty #-}
empty = phony $ proxyW G.empty
singleton :: VECTOR s ty a => a -> Vector s ty a
{-# INLINE singleton #-}
singleton a = phony $ proxyW (G.singleton a)
replicate :: VECTOR s ty a => Int -> a -> Vector s ty a
{-# INLINE replicate #-}
replicate i v = phony $ proxyW (G.replicate i v)
generate :: VECTOR s ty a => Int -> (Int -> a) -> Vector s ty a
{-# INLINE generate #-}
generate i f = phony $ proxyW (G.generate i f)
iterateN :: VECTOR s ty a => Int -> (a -> a) -> a -> Vector s ty a
{-# INLINE iterateN #-}
iterateN i f a = phony $ proxyW (G.iterateN i f a)
unfoldr :: VECTOR s ty a => (b -> Maybe (a, b)) -> b -> Vector s ty a
{-# INLINE unfoldr #-}
unfoldr g a = phony $ proxyW (G.unfoldr g a)
unfoldrN :: VECTOR s ty a => Int -> (b -> Maybe (a, b)) -> b -> Vector s ty a
{-# INLINE unfoldrN #-}
unfoldrN n g a = phony $ proxyW (G.unfoldrN n g a)
constructN :: VECTOR s ty a => Int -> (Vector s ty a -> a) -> Vector s ty a
{-# INLINE constructN #-}
constructN n g = phony $ proxyW (G.constructN n (g.unW))
constructrN :: VECTOR s ty a => Int -> (Vector s ty a -> a) -> Vector s ty a
{-# INLINE constructrN #-}
constructrN n g = phony $ proxyW (G.constructrN n (g.unW))
enumFromN :: (VECTOR s ty a, Num a) => a -> Int -> Vector s ty a
{-# INLINE enumFromN #-}
enumFromN a i = phony $ proxyW (G.enumFromN a i)
enumFromStepN :: (VECTOR s ty a, Num a) => a -> a -> Int -> Vector s ty a
{-# INLINE enumFromStepN #-}
enumFromStepN f t s = phony $ proxyW (G.enumFromStepN f t s)
enumFromTo :: (VECTOR s ty a, Enum a) => a -> a -> Vector s ty a
{-# INLINE enumFromTo #-}
enumFromTo f t = phony $ proxyW (G.enumFromTo f t)
enumFromThenTo :: (VECTOR s ty a, Enum a) => a -> a -> a -> Vector s ty a
{-# INLINE enumFromThenTo #-}
enumFromThenTo f t s = phony $ proxyW (G.enumFromThenTo f t s)
cons :: VECTOR s ty a => a -> Vector s ty a -> Vector s ty a
{-# INLINE cons #-}
cons a v = phony $ unW . proxyFW (G.cons a) v
snoc :: VECTOR s ty a => Vector s ty a -> a -> Vector s ty a
{-# INLINE snoc #-}
snoc v a = phony $ unW . proxyFW (`G.snoc` a) v
infixr 5 ++
(++) :: VECTOR s ty a => Vector s ty a -> Vector s ty a -> Vector s ty a
{-# INLINE (++) #-}
v1 ++ v2 = phony $ unW . proxyFW2 (G.++) v1 v2
concat :: VECTOR s ty a => [Vector s ty a] -> Vector s ty a
{-# INLINE concat #-}
concat vs = phony $ \p -> unW $ G.concat $ Prelude.map (withW p) vs
replicateM :: (Monad m, VECTOR s ty a) => Int -> m a -> m (Vector s ty a)
{-# INLINE replicateM #-}
replicateM n f = phony $ \p -> (\v -> proxyW v p) <$> G.replicateM n f
generateM :: (Monad m, VECTOR s ty a) => Int -> (Int -> m a) -> m (Vector s ty a)
{-# INLINE generateM #-}
generateM n f = phony $ \p -> (\v -> proxyW v p) <$> G.generateM n f
create :: VECTOR s ty a => (forall r. ST r (MVector r ty a)) -> Vector s ty a
{-# INLINE create #-}
create f = phony $ \p -> unW $ G.create (Mutable.withW p <$> f)
force :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE force #-}
force v = phony $ unW . proxyFW G.force v
(//) :: VECTOR s ty a
=> Vector s ty a
-> [(Int, a)]
-> Vector s ty a
{-# INLINE (//) #-}
(//) v l = phony $ unW . proxyFW (G.// l) v
unsafeUpd :: VECTOR s ty a => Vector s ty a -> [(Int, a)] -> Vector s ty a
{-# INLINE unsafeUpd #-}
unsafeUpd v l = phony $ unW . proxyFW (`G.unsafeUpd` l) v
accum :: VECTOR s ty a
=> (a -> b -> a)
-> Vector s ty a
-> [(Int,b)]
-> Vector s ty a
{-# INLINE accum #-}
accum f v l = phony $ unW . proxyFW (\w -> G.accum f w l) v
unsafeAccum :: VECTOR s ty a => (a -> b -> a) -> Vector s ty a -> [(Int,b)] -> Vector s ty a
{-# INLINE unsafeAccum #-}
unsafeAccum f v l = phony $ unW . proxyFW (\w -> G.unsafeAccum f w l) v
reverse :: VECTOR s ty a => Vector s ty a -> Vector s ty a
{-# INLINE reverse #-}
reverse v = phony $ unW . proxyFW G.reverse v
map :: (VECTOR s ty a, VECTOR s ty b) => (a -> b) -> Vector s ty a -> Vector s ty b
{-# INLINE map #-}
map f v = phony $ unW . proxyFW (G.map f) v
imap :: (VECTOR s ty a, VECTOR s ty b) => (Int -> a -> b) -> Vector s ty a -> Vector s ty b
{-# INLINE imap #-}
imap f v = phony $ unW . proxyFW (G.imap f) v
concatMap :: (VECTOR s tya a, VECTOR s tyb b)
=> (a -> Vector s tyb b)
-> Vector s tya a
-> Vector s tyb b
{-# INLINE concatMap #-}
#if MIN_VERSION_vector(0,11,0)
concatMap f v = phony $ \p ->
let v' = G.stream (withW p v)
in proxyW (G.unstream $ Bundle.fromStream (Stream.concatMap (sElems . G.stream . withW p . f) (sElems v')) Unknown) p
#else
concatMap f v =
phony $ \p ->
(`proxyW` p) $
G.unstream $
Stream.concatMap (G.stream . withW p . f) $
G.stream $
withW p v
#endif
mapM :: (Monad m, VECTOR s ty a, VECTOR s ty b) => (a -> m b) -> Vector s ty a -> m (Vector s ty b)
{-# INLINE mapM #-}
mapM f v = phony $ \p -> unW <$> proxyFW (G.mapM f) v p
mapM_ :: (Monad m, VECTOR s ty a) => (a -> m b) -> Vector s ty a -> m ()
{-# INLINE mapM_ #-}
mapM_ f v = phony $ proxyFW (G.mapM_ f) v
forM :: (Monad m, VECTOR s ty a, VECTOR s ty b) => Vector s ty a -> (a -> m b) -> m (Vector s ty b)
{-# INLINE forM #-}
forM v f = phony $ \p -> unW <$> proxyFW (`G.forM` f) v p
forM_ :: (Monad m, VECTOR s ty a) => Vector s ty a -> (a -> m b) -> m ()
{-# INLINE forM_ #-}
forM_ v f = phony $ proxyFW (`G.forM_` f) v
#if MIN_VERSION_vector(0,11,0)
smallest :: [Size] -> Size
smallest = List.foldl1' smaller
#endif
zipWith :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c)
=> (a -> b -> c) -> Vector s tya a -> Vector s tyb b -> Vector s tyc c
{-# INLINE zipWith #-}
#if MIN_VERSION_vector(0,11,0)
zipWith f xs ys = phony $ \p ->
let xs' = G.stream (withW p xs)
ys' = G.stream (withW p ys)
sz = smaller (sSize xs') (sSize ys')
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith f (sElems xs') (sElems ys')) sz) p
#else
zipWith f xs ys = phony $ \p ->
proxyW (G.unstream (Stream.zipWith f (G.stream (withW p xs)) (G.stream (withW p ys)))) p
#endif
zipWith3 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d)
=> (a -> b -> c -> d) -> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d
{-# INLINE zipWith3 #-}
#if MIN_VERSION_vector(0,11,0)
zipWith3 f as bs cs = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
sz = smallest [sSize as', sSize bs', sSize cs']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith3 f (sElems as') (sElems bs') (sElems cs')) sz) p
#else
zipWith3 f as bs cs = phony $ \p ->
proxyW (G.unstream (Stream.zipWith3 f (G.stream (withW p as)) (G.stream (withW p bs)) (G.stream (withW p cs)))) p
#endif
zipWith4 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e)
=> (a -> b -> c -> d -> e)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
{-# INLINE zipWith4 #-}
#if MIN_VERSION_vector(0,11,0)
zipWith4 f as bs cs ds = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
sz = smallest [sSize as', sSize bs', sSize cs', sSize ds']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith4 f (sElems as') (sElems bs') (sElems cs') (sElems ds')) sz) p
#else
zipWith4 f as bs cs ds = phony $ \p ->
proxyW (G.unstream (Stream.zipWith4 f (G.stream (withW p as)) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)))) p
#endif
zipWith5 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e,
VECTOR s tyf f)
=> (a -> b -> c -> d -> e -> f)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
-> Vector s tyf f
{-# INLINE zipWith5 #-}
#if MIN_VERSION_vector(0,11,0)
zipWith5 f as bs cs ds es = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
es' = G.stream (withW p es)
sz = smallest [sSize as', sSize bs', sSize cs', sSize ds', sSize es']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith5 f (sElems as') (sElems bs') (sElems cs') (sElems ds') (sElems es')) sz) p
#else
zipWith5 f as bs cs ds es = phony $ \p ->
proxyW (G.unstream (Stream.zipWith5 f (G.stream (withW p as)) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)) (G.stream (withW p es)))) p
#endif
zipWith6 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e,
VECTOR s tyf f, VECTOR s tyg g)
=> (a -> b -> c -> d -> e -> f -> g)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
-> Vector s tyf f -> Vector s tyg g
{-# INLINE zipWith6 #-}
#if MIN_VERSION_vector(0,11,0)
zipWith6 f as bs cs ds es fs = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
es' = G.stream (withW p es)
fs' = G.stream (withW p fs)
sz = smallest [sSize as', sSize bs', sSize cs', sSize ds', sSize es', sSize fs']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith6 f (sElems as') (sElems bs') (sElems cs') (sElems ds') (sElems es') (sElems fs')) sz) p
#else
zipWith6 f as bs cs ds es fs = phony $ \p ->
proxyW (G.unstream (Stream.zipWith6 f (G.stream (withW p as)) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)) (G.stream (withW p es)) (G.stream (withW p fs)))) p
#endif
izipWith :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c)
=> (Int -> a -> b -> c) -> Vector s tya a -> Vector s tyb b -> Vector s tyc c
{-# INLINE izipWith #-}
#if MIN_VERSION_vector(0,11,0)
izipWith f as bs = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
sz = smaller (sSize as') (sSize bs')
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith (uncurry f) (Stream.indexed (sElems as')) (sElems bs')) sz) p
#else
izipWith f as bs = phony $ \p ->
proxyW (G.unstream (Stream.zipWith (uncurry f) (Stream.indexed (G.stream (withW p as))) (G.stream (withW p bs)))) p
#endif
izipWith3 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d)
=> (Int -> a -> b -> c -> d)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d
{-# INLINE izipWith3 #-}
#if MIN_VERSION_vector(0,11,0)
izipWith3 f as bs cs = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
sz = smallest [sSize as', sSize bs', sSize cs']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith3 (uncurry f) (Stream.indexed (sElems as')) (sElems bs') (sElems cs')) sz) p
#else
izipWith3 f as bs cs = phony $ \p ->
proxyW (G.unstream (Stream.zipWith3 (uncurry f) (Stream.indexed (G.stream (withW p as))) (G.stream (withW p bs)) (G.stream (withW p cs)))) p
#endif
izipWith4 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e)
=> (Int -> a -> b -> c -> d -> e)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
{-# INLINE izipWith4 #-}
#if MIN_VERSION_vector(0,11,0)
izipWith4 f as bs cs ds = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
sz = smallest [ sSize as', sSize bs', sSize cs', sSize ds']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith4 (uncurry f) (Stream.indexed (sElems as')) (sElems bs') (sElems cs') (sElems ds')) sz) p
#else
izipWith4 f as bs cs ds = phony $ \p ->
proxyW (G.unstream (Stream.zipWith4 (uncurry f) (Stream.indexed (G.stream (withW p as))) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)))) p
#endif
izipWith5 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e,
VECTOR s tyf f)
=> (Int -> a -> b -> c -> d -> e -> f)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
-> Vector s tyf f
{-# INLINE izipWith5 #-}
#if MIN_VERSION_vector(0,11,0)
izipWith5 f as bs cs ds es = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
es' = G.stream (withW p es)
sz = smallest [ sSize as', sSize bs', sSize cs', sSize ds', sSize es']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith5 (uncurry f) (Stream.indexed (sElems as')) (sElems bs') (sElems cs') (sElems ds') (sElems es')) sz) p
#else
izipWith5 f as bs cs ds es = phony $ \p ->
proxyW (G.unstream (Stream.zipWith5 (uncurry f) (Stream.indexed (G.stream (withW p as))) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)) (G.stream (withW p es)))) p
#endif
izipWith6 :: (VECTOR s tya a, VECTOR s tyb b, VECTOR s tyc c, VECTOR s tyd d, VECTOR s tye e,
VECTOR s tyf f, VECTOR s tyg g)
=> (Int -> a -> b -> c -> d -> e -> f -> g)
-> Vector s tya a -> Vector s tyb b -> Vector s tyc c -> Vector s tyd d -> Vector s tye e
-> Vector s tyf f -> Vector s tyg g
{-# INLINE izipWith6 #-}
#if MIN_VERSION_vector(0,11,0)
izipWith6 f as bs cs ds es fs = phony $ \p ->
let as' = G.stream (withW p as)
bs' = G.stream (withW p bs)
cs' = G.stream (withW p cs)
ds' = G.stream (withW p ds)
es' = G.stream (withW p es)
fs' = G.stream (withW p fs)
sz = smallest [ sSize as', sSize bs', sSize cs', sSize ds', sSize es', sSize fs']
in proxyW (G.unstream $ Bundle.fromStream (Stream.zipWith6 (uncurry f) (Stream.indexed (sElems as')) (sElems bs') (sElems cs') (sElems ds') (sElems es') (sElems fs')) sz) p
#else
izipWith6 f as bs cs ds es fs = phony $ \p ->
proxyW (G.unstream (Stream.zipWith6 (uncurry f) (Stream.indexed (G.stream (withW p as))) (G.stream (withW p bs)) (G.stream (withW p cs)) (G.stream (withW p ds)) (G.stream (withW p es)) (G.stream (withW p fs)))) p
#endif
zipWithM :: (MonadR m, VECTOR (Region m) tya a, VECTOR (Region m) tyb b, VECTOR (Region m) tyc c)
=> (a -> b -> m c)
-> Vector (Region m) tya a
-> Vector (Region m) tyb b
-> m (Vector (Region m) tyc c)
{-# INLINE zipWithM #-}
#if MIN_VERSION_vector(0,11,0)
zipWithM f xs ys = phony $ \p ->
let xs' = lift $ G.stream (withW p xs)
ys' = lift $ G.stream (withW p ys)
sz = smaller (sSize xs') (sSize ys')
in proxyW <$> Prelude.fmap G.unstream (Bundle.unsafeFromList sz <$> Stream.toList (Stream.zipWithM f (sElems xs') (sElems ys')))
<*> pure p
#else
zipWithM f xs ys = phony $ \p ->
proxyW <$>
unstreamM (Stream.zipWithM f (G.stream (withW p xs)) (G.stream (withW p ys))) <*>
return p
where
unstreamM s = do
zs <- MStream.toList s
return $ G.unstream $ Stream.unsafeFromList (MStream.size s) zs
#endif
zipWithM_ :: (Monad m, VECTOR s tya a, VECTOR s tyb b)
=> (a -> b -> m c)
-> Vector s tya a
-> Vector s tyb b
-> m ()
{-# INLINE zipWithM_ #-}
#if MIN_VERSION_vector(0,11,0)
zipWithM_ f xs ys = phony $ \p ->
let xs' = lift $ G.stream (withW p xs)
ys' = lift $ G.stream (withW p ys)
in Stream.zipWithM_ f (sElems xs') (sElems ys')
#else
zipWithM_ f xs ys = phony $ \p ->
Stream.zipWithM_ f (G.stream (withW p xs)) (G.stream (withW p ys))
#endif
filter :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Vector s ty a
{-# INLINE filter #-}
filter f v = phony $ unW . proxyFW (G.filter f) v
ifilter :: VECTOR s ty a => (Int -> a -> Bool) -> Vector s ty a -> Vector s ty a
{-# INLINE ifilter #-}
ifilter f v = phony $ unW . proxyFW (G.ifilter f) v
filterM :: (Monad m, VECTOR s ty a) => (a -> m Bool) -> Vector s ty a -> m (Vector s ty a)
{-# INLINE filterM #-}
filterM f v = phony $ \p -> unW <$> proxyFW (G.filterM f) v p
takeWhile :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Vector s ty a
{-# INLINE takeWhile #-}
takeWhile f v = phony $ unW . proxyFW (G.takeWhile f) v
dropWhile :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Vector s ty a
{-# INLINE dropWhile #-}
dropWhile f v = phony $ unW . proxyFW (G.dropWhile f) v
partition :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> (Vector s ty a, Vector s ty a)
{-# INLINE partition #-}
partition f v = phony $ (\(a,b) -> (unW a, unW b)) . proxyFW (G.partition f) v
unstablePartition :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> (Vector s ty a, Vector s ty a)
{-# INLINE unstablePartition #-}
unstablePartition f v = phony $ (\(a,b) -> (unW a, unW b)) . proxyFW (G.unstablePartition f) v
span :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> (Vector s ty a, Vector s ty a)
{-# INLINE span #-}
span f v = phony $ (\(a,b) -> (unW a, unW b)) . proxyFW (G.span f) v
break :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> (Vector s ty a, Vector s ty a)
{-# INLINE break #-}
break f v = phony $ (\(a,b) -> (unW a, unW b)) . proxyFW (G.break f) v
infix 4 `elem`
elem :: (VECTOR s ty a, Eq a) => a -> Vector s ty a -> Bool
{-# INLINE elem #-}
elem a v = phony $ proxyFW (G.elem a) v
infix 4 `notElem`
notElem :: (VECTOR s ty a, Eq a) => a -> Vector s ty a -> Bool
{-# INLINE notElem #-}
notElem a v = phony $ proxyFW (G.notElem a) v
find :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Maybe a
{-# INLINE find #-}
find f v = phony $ proxyFW (G.find f) v
findIndex :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Maybe Int
{-# INLINE findIndex #-}
findIndex f v = phony $ proxyFW (G.findIndex f) v
elemIndex :: (VECTOR s ty a, Eq a) => a -> Vector s ty a -> Maybe Int
{-# INLINE elemIndex #-}
elemIndex a v = phony $ proxyFW (G.elemIndex a) v
foldl :: VECTOR s ty b => (a -> b -> a) -> a -> Vector s ty b -> a
{-# INLINE foldl #-}
foldl f s v = phony $ proxyFW (G.foldl f s) v
foldl1 :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> a
{-# INLINE foldl1 #-}
foldl1 f v = phony $ proxyFW (G.foldl1 f) v
foldl' :: VECTOR s ty b => (a -> b -> a) -> a -> Vector s ty b -> a
{-# INLINE foldl' #-}
foldl' f s v = phony $ proxyFW (G.foldl' f s) v
foldl1' :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> a
{-# INLINE foldl1' #-}
foldl1' f v = phony $ proxyFW (G.foldl1' f) v
foldr :: VECTOR s ty a => (a -> b -> b) -> b -> Vector s ty a -> b
{-# INLINE foldr #-}
foldr f s v = phony $ proxyFW (G.foldr f s) v
foldr1 :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> a
{-# INLINE foldr1 #-}
foldr1 f v = phony $ proxyFW (G.foldr1 f) v
foldr' :: VECTOR s ty a => (a -> b -> b) -> b -> Vector s ty a -> b
{-# INLINE foldr' #-}
foldr' f s v = phony $ proxyFW (G.foldr' f s) v
foldr1' :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> a
{-# INLINE foldr1' #-}
foldr1' f v = phony $ proxyFW (G.foldr1' f) v
ifoldl :: VECTOR s ty b => (a -> Int -> b -> a) -> a -> Vector s ty b -> a
{-# INLINE ifoldl #-}
ifoldl f s v = phony $ proxyFW (G.ifoldl f s) v
ifoldl' :: VECTOR s ty b => (a -> Int -> b -> a) -> a -> Vector s ty b -> a
{-# INLINE ifoldl' #-}
ifoldl' f s v = phony $ proxyFW (G.ifoldl' f s) v
ifoldr :: VECTOR s ty a => (Int -> a -> b -> b) -> b -> Vector s ty a -> b
{-# INLINE ifoldr #-}
ifoldr f s v = phony $ proxyFW (G.ifoldr f s) v
ifoldr' :: VECTOR s ty a => (Int -> a -> b -> b) -> b -> Vector s ty a -> b
{-# INLINE ifoldr' #-}
ifoldr' f s v = phony $ proxyFW (G.ifoldr' f s) v
all :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Bool
{-# INLINE all #-}
all f v = phony $ \p -> G.all f (withW p v)
any :: VECTOR s ty a => (a -> Bool) -> Vector s ty a -> Bool
{-# INLINE any #-}
any f v = phony $ \p -> G.any f (withW p v)
sum :: (VECTOR s ty a, Num a) => Vector s ty a -> a
{-# INLINE sum #-}
sum v = phony $ proxyFW G.sum v
product :: (VECTOR s ty a, Num a) => Vector s ty a -> a
{-# INLINE product #-}
product v = phony $ proxyFW G.product v
maximum :: (VECTOR s ty a, Ord a) => Vector s ty a -> a
{-# INLINE maximum #-}
maximum v = phony $ proxyFW G.maximum v
maximumBy :: VECTOR s ty a => (a -> a -> Ordering) -> Vector s ty a -> a
{-# INLINE maximumBy #-}
maximumBy f v = phony $ proxyFW (G.maximumBy f) v
minimum :: (VECTOR s ty a, Ord a) => Vector s ty a -> a
{-# INLINE minimum #-}
minimum v = phony $ proxyFW G.minimum v
minimumBy :: VECTOR s ty a => (a -> a -> Ordering) -> Vector s ty a -> a
{-# INLINE minimumBy #-}
minimumBy f v = phony $ proxyFW (G.minimumBy f) v
maxIndex :: (VECTOR s ty a, Ord a) => Vector s ty a -> Int
{-# INLINE maxIndex #-}
maxIndex v = phony $ proxyFW G.maxIndex v
maxIndexBy :: VECTOR s ty a => (a -> a -> Ordering) -> Vector s ty a -> Int
{-# INLINE maxIndexBy #-}
maxIndexBy f v = phony $ proxyFW (G.maxIndexBy f) v
minIndex :: (VECTOR s ty a, Ord a) => Vector s ty a -> Int
{-# INLINE minIndex #-}
minIndex v = phony $ proxyFW G.minIndex v
minIndexBy :: VECTOR s ty a => (a -> a -> Ordering) -> Vector s ty a -> Int
{-# INLINE minIndexBy #-}
minIndexBy f v = phony $ proxyFW (G.minIndexBy f) v
foldM :: (Monad m, VECTOR s ty b) => (a -> b -> m a) -> a -> Vector s ty b -> m a
{-# INLINE foldM #-}
foldM f s v = phony $ proxyFW (G.foldM f s) v
fold1M :: (Monad m, VECTOR s ty a) => (a -> a -> m a) -> Vector s ty a -> m a
{-# INLINE fold1M #-}
fold1M f v = phony $ proxyFW (G.fold1M f) v
foldM' :: (Monad m, VECTOR s ty b) => (a -> b -> m a) -> a -> Vector s ty b -> m a
{-# INLINE foldM' #-}
foldM' f s v = phony $ proxyFW (G.foldM' f s) v
fold1M' :: (Monad m, VECTOR s ty a) => (a -> a -> m a) -> Vector s ty a -> m a
{-# INLINE fold1M' #-}
fold1M' f v = phony $ proxyFW (G.fold1M' f) v
foldM_ :: (Monad m, VECTOR s ty b) => (a -> b -> m a) -> a -> Vector s ty b -> m ()
{-# INLINE foldM_ #-}
foldM_ f s v = phony $ proxyFW (G.foldM_ f s) v
fold1M_ :: (Monad m, VECTOR s ty a) => (a -> a -> m a) -> Vector s ty a -> m ()
{-# INLINE fold1M_ #-}
fold1M_ f v = phony $ proxyFW (G.fold1M_ f) v
foldM'_ :: (Monad m, VECTOR s ty b) => (a -> b -> m a) -> a -> Vector s ty b -> m ()
{-# INLINE foldM'_ #-}
foldM'_ f s v = phony $ proxyFW (G.foldM'_ f s) v
fold1M'_ :: (Monad m, VECTOR s ty a) => (a -> a -> m a) -> Vector s ty a -> m ()
{-# INLINE fold1M'_ #-}
fold1M'_ f v = phony $ proxyFW (G.fold1M'_ f) v
prescanl :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE prescanl #-}
prescanl f s v = phony $ unW . proxyFW (G.prescanl f s) v
prescanl' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE prescanl' #-}
prescanl' f s v = phony $ unW . proxyFW (G.prescanl' f s) v
postscanl :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE postscanl #-}
postscanl f s v = phony $ unW . proxyFW (G.postscanl f s) v
postscanl' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE postscanl' #-}
postscanl' f s v = phony $ unW . proxyFW (G.postscanl' f s) v
scanl :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE scanl #-}
scanl f s v = phony $ unW . proxyFW (G.scanl f s) v
scanl' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> a) -> a -> Vector s ty b -> Vector s ty a
{-# INLINE scanl' #-}
scanl' f s v = phony $ unW . proxyFW (G.scanl' f s) v
scanl1 :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> Vector s ty a
{-# INLINE scanl1 #-}
scanl1 f v = phony $ unW . proxyFW (G.scanl1 f) v
scanl1' :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> Vector s ty a
{-# INLINE scanl1' #-}
scanl1' f v = phony $ unW . proxyFW (G.scanl1' f) v
prescanr :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE prescanr #-}
prescanr f s v = phony $ unW . proxyFW (G.prescanr f s) v
prescanr' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE prescanr' #-}
prescanr' f s v = phony $ unW . proxyFW (G.prescanr' f s) v
postscanr :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE postscanr #-}
postscanr f s v = phony $ unW . proxyFW (G.postscanr f s) v
postscanr' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE postscanr' #-}
postscanr' f s v = phony $ unW . proxyFW (G.postscanr' f s) v
scanr :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE scanr #-}
scanr f s v = phony $ unW . proxyFW (G.scanr f s) v
scanr' :: (VECTOR s ty a, VECTOR s ty b) => (a -> b -> b) -> b -> Vector s ty a -> Vector s ty b
{-# INLINE scanr' #-}
scanr' f s v = phony $ unW . proxyFW (G.scanr' f s) v
scanr1 :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> Vector s ty a
{-# INLINE scanr1 #-}
scanr1 f v = phony $ unW . proxyFW (G.scanr1 f) v
scanr1' :: VECTOR s ty a => (a -> a -> a) -> Vector s ty a -> Vector s ty a
{-# INLINE scanr1' #-}
scanr1' f v = phony $ unW . proxyFW (G.scanr1' f) v
toList :: VECTOR s ty a => Vector s ty a -> [a]
{-# INLINE toList #-}
toList v = phony $ proxyFW G.toList v
fromList :: forall s ty a . VECTOR s ty a => [a] -> Vector s ty a
{-# INLINE fromList #-}
fromList xs = phony $ proxyW (G.fromListN (Prelude.length xs) xs)
fromListN :: forall s ty a . VECTOR s ty a => Int -> [a] -> Vector s ty a
{-# INLINE fromListN #-}
fromListN i l = phony $ proxyW (G.fromListN i l)
unsafeFreeze :: (VECTOR (Region m) ty a, MonadR m)
=> MVector (Region m) ty a -> m (Vector (Region m) ty a)
{-# INLINE unsafeFreeze #-}
unsafeFreeze m = withAcquire $ \p -> unW <$> G.unsafeFreeze (Mutable.withW p m)
unsafeThaw :: (MonadR m, VECTOR (Region m) ty a)
=> Vector (Region m) ty a -> m (MVector (Region m) ty a)
{-# INLINE unsafeThaw #-}
unsafeThaw v = withAcquire $ \p -> Mutable.unW <$> G.unsafeThaw (withW p v)
thaw :: (MonadR m, VECTOR (Region m) ty a)
=> Vector (Region m) ty a -> m (MVector (Region m) ty a)
{-# INLINE thaw #-}
thaw v1 = withAcquire $ \p -> Mutable.unW <$> G.thaw (withW p v1)
freeze :: (MonadR m, VECTOR (Region m) ty a)
=> MVector (Region m) ty a -> m (Vector (Region m) ty a)
{-# INLINE freeze #-}
freeze m1 = withAcquire $ \p -> unW <$> G.freeze (Mutable.withW p m1)
unsafeCopy
:: (MonadR m, VECTOR (Region m) ty a)
=> MVector (Region m) ty a -> Vector (Region m) ty a -> m ()
{-# INLINE unsafeCopy #-}
unsafeCopy m1 v2 = withAcquire $ \p -> G.unsafeCopy (Mutable.withW p m1) (withW p v2)
copy :: (MonadR m, VECTOR (Region m) ty a)
=> MVector (Region m) ty a -> Vector (Region m) ty a -> m ()
{-# INLINE copy #-}
copy m1 v2 = withAcquire $ \p -> G.copy (Mutable.withW p m1) (withW p v2)
phony :: (forall t . Reifies t (AcquireIO s) => Proxy t -> r) -> r
phony f = reify (AcquireIO acquireIO) $ \p -> f p
where
acquireIO :: SEXP V ty -> IO (SEXP g ty)
acquireIO x = do
R.preserveObject x
return $ R.unsafeRelease x