{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE CPP #-}
#if MIN_VERSION_base(4,12,0)
{-# LANGUAGE NoStarIsType #-}
#endif
module Data.Vector.Generic.Sized
( Vector
, MVector
, length
, length'
, knownLength
, knownLength'
, index
, index'
, unsafeIndex
, head
, last
, indexM
, indexM'
, unsafeIndexM
, headM
, lastM
, slice
, slice'
, init
, tail
, take
, take'
, drop
, drop'
, splitAt
, splitAt'
, empty
, singleton
, fromTuple
, replicate
, replicate'
, generate
, generate'
, iterateN
, iterateN'
, replicateM
, replicateM'
, generateM
, generateM'
, unfoldrN
, unfoldrN'
, enumFromN
, enumFromN'
, enumFromStepN
, enumFromStepN'
, cons
, snoc
, (++)
, force
, (//)
, update
, update_
, unsafeUpd
, unsafeUpdate
, unsafeUpdate_
, accum
, accumulate
, accumulate_
, unsafeAccum
, unsafeAccumulate
, unsafeAccumulate_
, reverse
, backpermute
, unsafeBackpermute
, ix
, _head
, _last
, indexed
, map
, imap
, concatMap
, mapM
, imapM
, mapM_
, imapM_
, forM
, forM_
, zipWith
, zipWith3
, zipWith4
, zipWith5
, zipWith6
, izipWith
, izipWith3
, izipWith4
, izipWith5
, izipWith6
, zip
, zip3
, zip4
, zip5
, zip6
, zipWithM
, izipWithM
, zipWithM_
, izipWithM_
, unzip
, unzip3
, unzip4
, unzip5
, unzip6
, elem
, notElem
, find
, findIndex
, elemIndex
, foldl
, foldl1
, foldl'
, foldl1'
, foldr
, foldr1
, foldr'
, foldr1'
, ifoldl
, ifoldl'
, ifoldr
, ifoldr'
, all
, any
, and
, or
, sum
, product
, maximum
, maximumBy
, minimum
, minimumBy
, maxIndex
, maxIndexBy
, minIndex
, minIndexBy
, foldM
, ifoldM
, fold1M
, foldM'
, ifoldM'
, fold1M'
, foldM_
, ifoldM_
, fold1M_
, foldM'_
, ifoldM'_
, fold1M'_
, sequence
, sequence_
, prescanl
, prescanl'
, postscanl
, postscanl'
, scanl
, scanl'
, scanl1
, scanl1'
, prescanr
, prescanr'
, postscanr
, postscanr'
, scanr
, scanr'
, scanr1
, scanr1'
, toList
, fromList
, fromListN
, fromListN'
, withSizedList
, convert
, freeze
, thaw
, copy
, unsafeFreeze
, unsafeThaw
, toSized
, withSized
, fromSized
, withVectorUnsafe
) where
import Data.Vector.Generic.Sized.Internal
import qualified Data.Vector.Generic as VG
import qualified Data.Vector as Boxed
import qualified Data.Vector.Generic.Mutable.Sized as SVGM
import Data.Vector.Generic.Mutable.Sized.Internal
import GHC.Generics (Generic)
import GHC.TypeLits
import Data.Bifunctor
import Data.Finite
import Data.Finite.Internal
import Data.Proxy
import Control.DeepSeq (NFData)
import Control.Monad.Primitive
import Foreign.Storable
import Data.Data
import Data.Functor.Classes
import Control.Comonad
import Foreign.Ptr (castPtr)
import Data.Semigroup
import Text.Read.Lex
import Text.ParserCombinators.ReadPrec
import GHC.Read
import Data.Type.Equality
import Unsafe.Coerce
import qualified Data.Functor.Rep as Rep
import Data.Distributive
import Prelude
hiding (length, replicate, (++), head, last, init, tail, take,
drop, splitAt, reverse, map, concatMap, zipWith, zipWith3, zip,
zip3, unzip, unzip3, elem, notElem, foldl, foldl1, foldr, foldr1,
all, any, and, or, sum, product, maximum, minimum, scanl, scanl1,
scanr, scanr1, mapM, mapM_, sequence, sequence_)
import Data.IndexedListLiterals hiding (toList, fromList)
import qualified Data.IndexedListLiterals as ILL
instance (KnownNat n, VG.Vector v a, Read (v a)) => Read (Vector v n a) where
readPrec = parens $ prec 10 $ do
expectP (Ident "Vector")
vec <- readPrec
if VG.length vec == (fromIntegral $ natVal (Proxy :: Proxy n)) then return $ Vector vec else pfail
type instance VG.Mutable (Vector v n) = MVector (VG.Mutable v) n
instance (KnownNat n, Storable a, VG.Vector v a)
=> Storable (Vector v n a) where
sizeOf _ = sizeOf (undefined :: a) * fromIntegral (natVal (Proxy :: Proxy n))
alignment _ = alignment (undefined :: a)
peek ptr = generateM (peekElemOff (castPtr ptr) . fromIntegral)
poke ptr = imapM_ (pokeElemOff (castPtr ptr) . fromIntegral)
instance KnownNat n => Applicative (Vector Boxed.Vector n) where
pure = replicate
(<*>) = zipWith ($)
(*>) = seq
(<*) = flip seq
instance KnownNat n => Monad (Vector Boxed.Vector n) where
return = replicate
xs >>= f = imap (\i x -> f x `index` i) xs
(>>) = seq
instance (KnownNat n, n ~ (1 + m)) => Comonad (Vector Boxed.Vector n) where
extract = head
extend f r@(Vector v) = Vector $ VG.generate len (\i -> f (Vector (VG.slice i len v')))
where
v' = v VG.++ VG.init v
len = length r
instance (KnownNat n, n ~ (1 + m)) => ComonadApply (Vector Boxed.Vector n) where
(<@>) = (<*>)
(<@) = (<*)
(@>) = (*>)
instance (Semigroup g, VG.Vector v g) => Semigroup (Vector v n g) where
(<>) = zipWith (<>)
stimes = map . stimes
instance (Monoid m, VG.Vector v m, KnownNat n) => Monoid (Vector v n m) where
mempty = replicate mempty
mappend = zipWith mappend
mconcat vs = generate $ mconcat . flip fmap vs . flip index
instance KnownNat n => Distributive (Vector Boxed.Vector n) where
distribute = Rep.distributeRep
{-# inline distribute #-}
instance KnownNat n => Rep.Representable (Vector Boxed.Vector n) where
type Rep (Vector Boxed.Vector n) = Finite n
tabulate = generate
{-# inline tabulate #-}
index = Data.Vector.Generic.Sized.index
{-# inline index #-}
length :: forall v n a. KnownNat n
=> Vector v n a -> Int
length _ = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline length #-}
length' :: forall v n a.
Vector v n a -> Proxy n
length' _ = Proxy
{-# inline length' #-}
knownLength :: forall v n a r. VG.Vector v a
=> Vector v n a
-> (KnownNat n => r)
-> r
knownLength v x = knownLength' v $ const x
knownLength' :: forall v n a r. VG.Vector v a
=> Vector v n a
-> (KnownNat n => Proxy n -> r)
-> r
knownLength' (Vector v) x = case someNatVal (fromIntegral (VG.length v)) of
Just (SomeNat (Proxy :: Proxy n')) -> case unsafeCoerce Refl :: n' :~: n of Refl -> x Proxy
Nothing -> error "impossible: Vector has negative length"
index :: forall v n a. VG.Vector v a
=> Vector v n a -> Finite n -> a
index (Vector v) (Finite i) = v `VG.unsafeIndex` fromIntegral i
{-# inline index #-}
index' :: forall v n m a p. (KnownNat n, VG.Vector v a)
=> Vector v (n+m+1) a -> p n -> a
index' (Vector v) p = v `VG.unsafeIndex` i
where i = fromIntegral (natVal p)
{-# inline index' #-}
unsafeIndex :: forall v n a. VG.Vector v a
=> Vector v n a -> Int -> a
unsafeIndex (Vector v) i = v `VG.unsafeIndex` i
{-# inline unsafeIndex #-}
head :: forall v n a. VG.Vector v a
=> Vector v (1+n) a -> a
head (Vector v) = VG.unsafeHead v
{-# inline head #-}
last :: forall v n a. (VG.Vector v a)
=> Vector v (n+1) a -> a
last (Vector v) = VG.unsafeLast v
{-# inline last #-}
ix :: forall v n a f. (VG.Vector v a, Functor f)
=> Finite n -> (a -> f a) -> Vector v n a -> f (Vector v n a)
ix n f vector = (\x -> vector // [(n, x)]) <$> f (index vector n)
{-# inline ix #-}
_head :: forall v n a f. (VG.Vector v a, Functor f)
=> (a -> f a) -> Vector v (1+n) a -> f (Vector v (1+n) a)
_head f vector = (\x -> cons x $ tail vector) <$> f (head vector)
{-# inline _head #-}
_last :: forall v n a f. (VG.Vector v a, Functor f)
=> (a -> f a) -> Vector v (n+1) a -> f (Vector v (n+1) a)
_last f vector = (\x -> snoc (init vector) x) <$> f (last vector)
{-# inline _last #-}
indexM :: forall v n a m. (VG.Vector v a, Monad m)
=> Vector v n a -> Finite n -> m a
indexM (Vector v) (Finite i) = v `VG.indexM` fromIntegral i
{-# inline indexM #-}
indexM' :: forall v n k a m p. (KnownNat n, VG.Vector v a, Monad m)
=> Vector v (n+k) a -> p n -> m a
indexM' (Vector v) p = v `VG.indexM` i
where i = fromIntegral (natVal p)
{-# inline indexM' #-}
unsafeIndexM :: forall v n a m. (VG.Vector v a, Monad m)
=> Vector v n a -> Int -> m a
unsafeIndexM (Vector v) i = v `VG.unsafeIndexM` i
{-# inline unsafeIndexM #-}
headM :: forall v n a m. (VG.Vector v a, Monad m)
=> Vector v (1+n) a -> m a
headM (Vector v) = VG.unsafeHeadM v
{-# inline headM #-}
lastM :: forall v n a m. (VG.Vector v a, Monad m)
=> Vector v (n+1) a -> m a
lastM (Vector v) = VG.unsafeLastM v
{-# inline lastM #-}
slice :: forall v i n m a p. (KnownNat i, KnownNat n, VG.Vector v a)
=> p i
-> Vector v (i+n+m) a
-> Vector v n a
slice start (Vector v) = Vector (VG.unsafeSlice i n v)
where i = fromIntegral (natVal start)
n = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline slice #-}
slice' :: forall v i n m a p
. (KnownNat i, KnownNat n, VG.Vector v a)
=> p i
-> p n
-> Vector v (i+n+m) a
-> Vector v n a
slice' start _ = slice start
{-# inline slice' #-}
init :: forall v n a. (VG.Vector v a)
=> Vector v (n+1) a -> Vector v n a
init (Vector v) = Vector (VG.unsafeInit v)
{-# inline init #-}
tail :: forall v n a. (VG.Vector v a)
=> Vector v (1+n) a -> Vector v n a
tail (Vector v) = Vector (VG.unsafeTail v)
{-# inline tail #-}
take :: forall v n m a. (KnownNat n, VG.Vector v a)
=> Vector v (n+m) a -> Vector v n a
take (Vector v) = Vector (VG.unsafeTake i v)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline take #-}
take' :: forall v n m a p. (KnownNat n, VG.Vector v a)
=> p n -> Vector v (n+m) a -> Vector v n a
take' _ = take
{-# inline take' #-}
drop :: forall v n m a. (KnownNat n, VG.Vector v a)
=> Vector v (n+m) a -> Vector v m a
drop (Vector v) = Vector (VG.unsafeDrop i v)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline drop #-}
drop' :: forall v n m a p. (KnownNat n, VG.Vector v a)
=> p n -> Vector v (n+m) a -> Vector v m a
drop' _ = drop
{-# inline drop' #-}
splitAt :: forall v n m a. (KnownNat n, VG.Vector v a)
=> Vector v (n+m) a -> (Vector v n a, Vector v m a)
splitAt (Vector v) = (Vector a, Vector b)
where i = fromIntegral (natVal (Proxy :: Proxy n))
(a, b) = VG.splitAt i v
{-# inline splitAt #-}
splitAt' :: forall v n m a p. (KnownNat n, VG.Vector v a)
=> p n -> Vector v (n+m) a -> (Vector v n a, Vector v m a)
splitAt' _ = splitAt
{-# inline splitAt' #-}
empty :: forall v a. (VG.Vector v a)
=> Vector v 0 a
empty = Vector VG.empty
{-# inline empty #-}
singleton :: forall v a. (VG.Vector v a)
=> a -> Vector v 1 a
singleton a = Vector (VG.singleton a)
{-# inline singleton #-}
fromTuple :: forall v a input length.
(VG.Vector v a, IndexedListLiterals input length a, KnownNat length)
=> input -> Vector v length a
fromTuple = Vector . VG.fromListN (fromIntegral $ natVal $ Proxy @length) . ILL.toList
replicate :: forall v n a. (KnownNat n, VG.Vector v a)
=> a -> Vector v n a
replicate a = Vector (VG.replicate i a)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline replicate #-}
replicate' :: forall v n a p. (KnownNat n, VG.Vector v a)
=> p n -> a -> Vector v n a
replicate' _ = replicate
{-# inline replicate' #-}
generate :: forall v n a. (KnownNat n, VG.Vector v a)
=> (Finite n -> a) -> Vector v n a
generate f = Vector (VG.generate i (f . Finite . fromIntegral))
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline generate #-}
generate' :: forall v n a p. (KnownNat n, VG.Vector v a)
=> p n -> (Finite n -> a) -> Vector v n a
generate' _ = generate
{-# inline generate' #-}
iterateN :: forall v n a. (KnownNat n, VG.Vector v a)
=> (a -> a) -> a -> Vector v n a
iterateN f z = Vector (VG.iterateN i f z)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline iterateN #-}
iterateN' :: forall v n a p. (KnownNat n, VG.Vector v a)
=> p n -> (a -> a) -> a -> Vector v n a
iterateN' _ = iterateN
{-# inline iterateN' #-}
replicateM :: forall v n m a. (KnownNat n, VG.Vector v a, Monad m)
=> m a -> m (Vector v n a)
replicateM a = Vector <$> VG.replicateM i a
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline replicateM #-}
replicateM' :: forall v n m a p. (KnownNat n, VG.Vector v a, Monad m)
=> p n -> m a -> m (Vector v n a)
replicateM' _ = replicateM
{-# inline replicateM' #-}
generateM :: forall v n m a. (KnownNat n, VG.Vector v a, Monad m)
=> (Finite n -> m a) -> m (Vector v n a)
generateM f = Vector <$> VG.generateM i (f . Finite . fromIntegral)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline generateM #-}
generateM' :: forall v n m a p. (KnownNat n, VG.Vector v a, Monad m)
=> p n -> (Finite n -> m a) -> m (Vector v n a)
generateM' _ = generateM
{-# inline generateM' #-}
unfoldrN :: forall v n a b. (KnownNat n, VG.Vector v a)
=> (b -> (a, b)) -> b -> Vector v n a
unfoldrN f z = Vector (VG.unfoldrN i (Just . f) z)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline unfoldrN #-}
unfoldrN' :: forall v n a b p. (KnownNat n, VG.Vector v a)
=> p n -> (b -> (a, b)) -> b -> Vector v n a
unfoldrN' _ = unfoldrN
{-# inline unfoldrN' #-}
enumFromN :: forall v n a. (KnownNat n, VG.Vector v a, Num a)
=> a -> Vector v n a
enumFromN a = Vector (VG.enumFromN a i)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline enumFromN #-}
enumFromN' :: forall v n a p. (KnownNat n, VG.Vector v a, Num a)
=> a -> p n -> Vector v n a
enumFromN' a _ = enumFromN a
{-# inline enumFromN' #-}
enumFromStepN :: forall v n a. (KnownNat n, VG.Vector v a, Num a)
=> a -> a -> Vector v n a
enumFromStepN a a' = Vector (VG.enumFromStepN a a' i)
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline enumFromStepN #-}
enumFromStepN' :: forall v n a p. (KnownNat n, VG.Vector v a, Num a)
=> a -> a -> p n -> Vector v n a
enumFromStepN' a a' _ = enumFromStepN a a'
{-# inline enumFromStepN' #-}
cons :: forall v n a. VG.Vector v a
=> a -> Vector v n a -> Vector v (1+n) a
cons x (Vector xs) = Vector (VG.cons x xs)
{-# inline cons #-}
snoc :: forall v n a. VG.Vector v a
=> Vector v n a -> a -> Vector v (n+1) a
snoc (Vector xs) x = Vector (VG.snoc xs x)
{-# inline snoc #-}
(++) :: forall v n m a. VG.Vector v a
=> Vector v n a -> Vector v m a -> Vector v (n+m) a
Vector vn ++ Vector vm = Vector (vn VG.++ vm)
{-# inline (++) #-}
force :: VG.Vector v a => Vector v n a -> Vector v n a
force (Vector v) = Vector (VG.force v)
{-# inline force #-}
(//) :: VG.Vector v a
=> Vector v m a
-> [(Finite m, a)]
-> Vector v m a
Vector v // us = Vector (v VG.// (fmap . first) (fromIntegral . getFinite) us)
{-# inline (//) #-}
update :: (VG.Vector v a, VG.Vector v (Int, a))
=> Vector v m a
-> Vector v n (Int, a)
-> Vector v m a
update (Vector v) (Vector w) = Vector (VG.update v w)
{-# inline update #-}
update_ :: (VG.Vector v a, VG.Vector v Int)
=> Vector v m a
-> Vector v n Int
-> Vector v n a
-> Vector v m a
update_ (Vector v) (Vector is) (Vector w) = Vector (VG.update_ v is w)
{-# inline update_ #-}
unsafeUpd :: (VG.Vector v a)
=> Vector v m a
-> [(Int, a)]
-> Vector v m a
unsafeUpd (Vector v) us = Vector (VG.unsafeUpd v us)
{-# inline unsafeUpd #-}
unsafeUpdate :: (VG.Vector v a, VG.Vector v (Int, a))
=> Vector v m a
-> Vector v n (Int, a)
-> Vector v m a
unsafeUpdate (Vector v) (Vector w) = Vector (VG.unsafeUpdate v w)
{-# inline unsafeUpdate #-}
unsafeUpdate_ :: (VG.Vector v a, VG.Vector v Int)
=> Vector v m a
-> Vector v n Int
-> Vector v n a
-> Vector v m a
unsafeUpdate_ (Vector v) (Vector is) (Vector w) =
Vector (VG.unsafeUpdate_ v is w)
{-# inline unsafeUpdate_ #-}
accum :: VG.Vector v a
=> (a -> b -> a)
-> Vector v m a
-> [(Int,b)]
-> Vector v m a
accum f (Vector v) us = Vector (VG.accum f v us)
{-# inline accum #-}
accumulate :: (VG.Vector v a, VG.Vector v (Int, b))
=> (a -> b -> a)
-> Vector v m a
-> Vector v n (Int,b)
-> Vector v m a
accumulate f (Vector v) (Vector us) = Vector (VG.accumulate f v us)
{-# inline accumulate #-}
accumulate_ :: (VG.Vector v a, VG.Vector v Int, VG.Vector v b)
=> (a -> b -> a)
-> Vector v m a
-> Vector v n Int
-> Vector v n b
-> Vector v m a
accumulate_ f (Vector v) (Vector is) (Vector xs) = Vector (VG.accumulate_ f v is xs)
{-# inline accumulate_ #-}
unsafeAccum :: VG.Vector v a
=> (a -> b -> a)
-> Vector v m a
-> [(Int,b)]
-> Vector v m a
unsafeAccum f (Vector v) us = Vector (VG.unsafeAccum f v us)
{-# inline unsafeAccum #-}
unsafeAccumulate :: (VG.Vector v a, VG.Vector v (Int, b))
=> (a -> b -> a)
-> Vector v m a
-> Vector v n (Int,b)
-> Vector v m a
unsafeAccumulate f (Vector v) (Vector us) = Vector (VG.unsafeAccumulate f v us)
{-# inline unsafeAccumulate #-}
unsafeAccumulate_ :: (VG.Vector v a, VG.Vector v Int, VG.Vector v b)
=> (a -> b -> a)
-> Vector v m a
-> Vector v n Int
-> Vector v n b
-> Vector v m a
unsafeAccumulate_ f (Vector v) (Vector is) (Vector xs) = Vector (VG.unsafeAccumulate_ f v is xs)
{-# inline unsafeAccumulate_ #-}
reverse :: (VG.Vector v a) => Vector v n a -> Vector v n a
reverse (Vector v) = Vector (VG.reverse v)
{-# inline reverse #-}
backpermute :: (VG.Vector v a, VG.Vector v Int)
=> Vector v m a
-> Vector v n Int
-> Vector v n a
backpermute (Vector v) (Vector is) = Vector (VG.backpermute v is)
{-# inline backpermute #-}
unsafeBackpermute :: (VG.Vector v a, VG.Vector v Int)
=> Vector v m a
-> Vector v n Int
-> Vector v n a
unsafeBackpermute (Vector v) (Vector is) = Vector (VG.unsafeBackpermute v is)
{-# inline unsafeBackpermute #-}
indexed :: (VG.Vector v a, VG.Vector v (Int, a), VG.Vector v (Finite n,a))
=> Vector v n a -> Vector v n (Finite n,a)
indexed (Vector v) = Vector ((VG.map . first) (Finite . fromIntegral) $ VG.indexed v)
{-# inline indexed #-}
map :: (VG.Vector v a, VG.Vector v b)
=> (a -> b) -> Vector v n a -> Vector v n b
map f (Vector v) = Vector (VG.map f v)
{-# inline map #-}
imap :: (VG.Vector v a, VG.Vector v b)
=> (Finite n -> a -> b) -> Vector v n a -> Vector v n b
imap f (Vector v) = Vector (VG.imap (f . Finite . fromIntegral) v)
{-# inline imap #-}
concatMap :: (VG.Vector v a, VG.Vector v b)
=> (a -> Vector v m b) -> Vector v n a -> Vector v (n*m) b
concatMap f (Vector v) = Vector (VG.concatMap (fromSized . f) v)
{-# inline concatMap #-}
mapM :: (Monad m, VG.Vector v a, VG.Vector v b)
=> (a -> m b) -> Vector v n a -> m (Vector v n b)
mapM f (Vector v) = Vector <$> VG.mapM f v
{-# inline mapM #-}
imapM :: (Monad m, VG.Vector v a, VG.Vector v b)
=> (Finite n -> a -> m b) -> Vector v n a -> m (Vector v n b)
imapM f (Vector v) = Vector <$> (VG.imapM (f . Finite . fromIntegral) v)
{-# inline imapM #-}
mapM_ :: (Monad m, VG.Vector v a) => (a -> m b) -> Vector v n a -> m ()
mapM_ f (Vector v) = VG.mapM_ f v
{-# inline mapM_ #-}
imapM_ :: (Monad m, VG.Vector v a) => (Finite n -> a -> m b) -> Vector v n a -> m ()
imapM_ f (Vector v) = VG.imapM_ (f . Finite . fromIntegral) v
{-# inline imapM_ #-}
forM :: (Monad m, VG.Vector v a, VG.Vector v b)
=> Vector v n a -> (a -> m b) -> m (Vector v n b)
forM (Vector v) f = Vector <$> VG.forM v f
{-# inline forM #-}
forM_ :: (Monad m, VG.Vector v a) => Vector v n a -> (a -> m b) -> m ()
forM_ (Vector v) = VG.forM_ v
{-# inline forM_ #-}
zipWith :: (VG.Vector v a, VG.Vector v b, VG.Vector v c)
=> (a -> b -> c) -> Vector v n a -> Vector v n b -> Vector v n c
zipWith f (Vector as) (Vector bs) = Vector (VG.zipWith f as bs)
{-# inline zipWith #-}
zipWith3 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v d)
=> (a -> b -> c -> d) -> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n d
zipWith3 f (Vector as) (Vector bs) (Vector cs) = Vector (VG.zipWith3 f as bs cs)
{-# inline zipWith3 #-}
zipWith4 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e)
=> (a -> b -> c -> d -> e)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
zipWith4 f (Vector as) (Vector bs) (Vector cs) (Vector ds)
= Vector (VG.zipWith4 f as bs cs ds)
{-# inline zipWith4 #-}
zipWith5 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v f)
=> (a -> b -> c -> d -> e -> f)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n f
zipWith5 f (Vector as) (Vector bs) (Vector cs) (Vector ds) (Vector es)
= Vector (VG.zipWith5 f as bs cs ds es)
{-# inline zipWith5 #-}
zipWith6 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v f,VG.Vector v g)
=> (a -> b -> c -> d -> e -> f -> g)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n f
-> Vector v n g
zipWith6 f (Vector as) (Vector bs) (Vector cs) (Vector ds) (Vector es) (Vector fs)
= Vector (VG.zipWith6 f as bs cs ds es fs)
{-# inline zipWith6 #-}
izipWith :: (VG.Vector v a,VG.Vector v b,VG.Vector v c)
=> (Finite n -> a -> b -> c)
-> Vector v n a
-> Vector v n b
-> Vector v n c
izipWith f (Vector xs) (Vector ys)
= Vector (VG.izipWith (f . Finite . fromIntegral) xs ys)
{-# inline izipWith #-}
izipWith3 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d)
=> (Finite n -> a -> b -> c -> d)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
izipWith3 f (Vector as) (Vector bs) (Vector cs)
= Vector (VG.izipWith3 (f . Finite . fromIntegral) as bs cs)
{-# inline izipWith3 #-}
izipWith4 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e)
=> (Finite n -> a -> b -> c -> d -> e)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
izipWith4 f (Vector as) (Vector bs) (Vector cs) (Vector ds)
= Vector (VG.izipWith4 (f . Finite . fromIntegral) as bs cs ds)
{-# inline izipWith4 #-}
izipWith5 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v f)
=> (Finite n -> a -> b -> c -> d -> e -> f)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n f
izipWith5 f (Vector as) (Vector bs) (Vector cs) (Vector ds) (Vector es)
= Vector (VG.izipWith5 (f . Finite . fromIntegral) as bs cs ds es)
{-# inline izipWith5 #-}
izipWith6 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v f,VG.Vector v g)
=> (Finite n -> a -> b -> c -> d -> e -> f -> g)
-> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n f
-> Vector v n g
izipWith6 f (Vector as) (Vector bs) (Vector cs) (Vector ds) (Vector es) (Vector fs)
= Vector (VG.izipWith6 (f . Finite . fromIntegral) as bs cs ds es fs)
{-# inline izipWith6 #-}
zip :: (VG.Vector v a, VG.Vector v b, VG.Vector v (a,b))
=> Vector v n a -> Vector v n b -> Vector v n (a, b)
zip = zipWith (,)
{-# inline zip #-}
zip3 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v (a, b, c))
=> Vector v n a -> Vector v n b -> Vector v n c -> Vector v n (a, b, c)
zip3 = zipWith3 (,,)
{-# inline zip3 #-}
zip4 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v (a,b,c,d))
=> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n (a,b,c,d)
zip4 = zipWith4 (,,,)
{-# inline zip4 #-}
zip5 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v (a,b,c,d,e))
=> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n (a,b,c,d,e)
zip5 = zipWith5 (,,,,)
{-# inline zip5 #-}
zip6 :: (VG.Vector v a,VG.Vector v b,VG.Vector v c,VG.Vector v d,VG.Vector v e,VG.Vector v f,VG.Vector v (a,b,c,d,e,f))
=> Vector v n a
-> Vector v n b
-> Vector v n c
-> Vector v n d
-> Vector v n e
-> Vector v n f
-> Vector v n (a,b,c,d,e,f)
zip6 = zipWith6 (,,,,,)
{-# inline zip6 #-}
zipWithM :: (Monad m, VG.Vector v a, VG.Vector v b, VG.Vector v c)
=> (a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c)
zipWithM f (Vector as) (Vector bs) = Vector <$> VG.zipWithM f as bs
{-# inline zipWithM #-}
izipWithM :: (Monad m, VG.Vector v a, VG.Vector v b, VG.Vector v c)
=> (Finite n -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m (Vector v n c)
izipWithM m (Vector as) (Vector bs) = Vector <$> VG.izipWithM (m . Finite . fromIntegral) as bs
{-# inline izipWithM #-}
zipWithM_ :: (Monad m, VG.Vector v a, VG.Vector v b)
=> (a -> b -> m c) -> Vector v n a -> Vector v n b -> m ()
zipWithM_ f (Vector as) (Vector bs) = VG.zipWithM_ f as bs
{-# inline zipWithM_ #-}
izipWithM_ :: (Monad m, VG.Vector v a, VG.Vector v b)
=> (Finite n -> a -> b -> m c) -> Vector v n a -> Vector v n b -> m ()
izipWithM_ m (Vector as) (Vector bs) = VG.izipWithM_ (m . Finite . fromIntegral) as bs
{-# inline izipWithM_ #-}
unzip :: (VG.Vector v a, VG.Vector v b, VG.Vector v (a,b))
=> Vector v n (a, b) -> (Vector v n a, Vector v n b)
unzip xs = (map fst xs, map snd xs)
{-# inline unzip #-}
unzip3 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v (a, b, c))
=> Vector v n (a, b, c) -> (Vector v n a, Vector v n b, Vector v n c)
unzip3 xs = (map (\(a, _, _) -> a) xs,
map (\(_, b, _) -> b) xs,
map (\(_, _, c) -> c) xs)
{-# inline unzip3 #-}
unzip4 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v d,
VG.Vector v (a, b, c, d))
=> Vector v n (a, b, c, d) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d)
unzip4 xs = (map (\(a, _, _, _) -> a) xs,
map (\(_, b, _, _) -> b) xs,
map (\(_, _, c, _) -> c) xs,
map (\(_, _, _, d) -> d) xs)
{-# inline unzip4 #-}
unzip5 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v d, VG.Vector v e,
VG.Vector v (a, b, c, d, e))
=> Vector v n (a, b, c, d, e) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e)
unzip5 xs = (map (\(a, _, _, _, _) -> a) xs,
map (\(_, b, _, _, _) -> b) xs,
map (\(_, _, c, _, _) -> c) xs,
map (\(_, _, _, d, _) -> d) xs,
map (\(_, _, _, _, e) -> e) xs)
{-# inline unzip5 #-}
unzip6 :: (VG.Vector v a, VG.Vector v b, VG.Vector v c, VG.Vector v d, VG.Vector v e,
VG.Vector v f, VG.Vector v (a, b, c, d, e, f))
=> Vector v n (a, b, c, d, e, f) -> (Vector v n a, Vector v n b, Vector v n c, Vector v n d, Vector v n e, Vector v n f)
unzip6 xs = (map (\(a, _, _, _, _, _) -> a) xs,
map (\(_, b, _, _, _, _) -> b) xs,
map (\(_, _, c, _, _, _) -> c) xs,
map (\(_, _, _, d, _, _) -> d) xs,
map (\(_, _, _, _, e, _) -> e) xs,
map (\(_, _, _, _, _, f) -> f) xs)
{-# inline unzip6 #-}
infix 4 `elem`
elem :: (VG.Vector v a, Eq a) => a -> Vector v n a -> Bool
elem x (Vector v) = VG.elem x v
{-# inline elem #-}
infix 4 `notElem`
notElem :: (VG.Vector v a, Eq a) => a -> Vector v n a -> Bool
notElem x (Vector v) = VG.notElem x v
{-# inline notElem #-}
find :: VG.Vector v a => (a -> Bool) -> Vector v n a -> Maybe a
find f (Vector v) = VG.find f v
{-# inline find #-}
findIndex :: VG.Vector v a => (a -> Bool) -> Vector v n a -> Maybe (Finite n)
findIndex f (Vector v) = Finite . fromIntegral <$> VG.findIndex f v
{-# inline findIndex #-}
elemIndex :: (VG.Vector v a, Eq a) => a -> Vector v n a -> Maybe (Finite n)
elemIndex x (Vector v) = Finite . fromIntegral <$> VG.elemIndex x v
{-# inline elemIndex #-}
foldl :: VG.Vector v b => (a -> b -> a) -> a -> Vector v n b -> a
foldl f z = VG.foldl f z . fromSized
{-# inline foldl #-}
foldl1 :: VG.Vector v a => (a -> a -> a) -> Vector v (1+n) a -> a
foldl1 f = VG.foldl1 f . fromSized
{-# inline foldl1 #-}
foldl' :: VG.Vector v b => (a -> b -> a) -> a -> Vector v n b -> a
foldl' f z = VG.foldl' f z . fromSized
{-# inline foldl' #-}
foldl1' :: VG.Vector v a => (a -> a -> a) -> Vector v (1+n) a -> a
foldl1' f = VG.foldl1' f . fromSized
{-# inline foldl1' #-}
foldr :: VG.Vector v a => (a -> b -> b) -> b -> Vector v n a -> b
foldr f z = VG.foldr f z . fromSized
{-# inline foldr #-}
foldr1 :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> a
foldr1 f = VG.foldr1 f . fromSized
{-# inline foldr1 #-}
foldr' :: VG.Vector v a => (a -> b -> b) -> b -> Vector v n a -> b
foldr' f z = VG.foldr' f z . fromSized
{-# inline foldr' #-}
foldr1' :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> a
foldr1' f = VG.foldr1' f . fromSized
{-# inline foldr1' #-}
ifoldl :: VG.Vector v b => (a -> Finite n -> b -> a) -> a -> Vector v n b -> a
ifoldl f z = VG.ifoldl (\x -> f x . Finite . fromIntegral) z . fromSized
{-# inline ifoldl #-}
ifoldl' :: VG.Vector v b => (a -> Finite n -> b -> a) -> a -> Vector v n b -> a
ifoldl' f z = VG.ifoldl' (\x -> f x . Finite . fromIntegral) z . fromSized
{-# inline ifoldl' #-}
ifoldr :: VG.Vector v a => (Finite n -> a -> b -> b) -> b -> Vector v n a -> b
ifoldr f z = VG.ifoldr (f . Finite . fromIntegral) z . fromSized
{-# inline ifoldr #-}
ifoldr' :: VG.Vector v a => (Finite n -> a -> b -> b) -> b -> Vector v n a -> b
ifoldr' f z = VG.ifoldr' (f . Finite . fromIntegral) z . fromSized
{-# inline ifoldr' #-}
all :: VG.Vector v a => (a -> Bool) -> Vector v n a -> Bool
all f = VG.all f . fromSized
{-# inline all #-}
any :: VG.Vector v a => (a -> Bool) -> Vector v n a -> Bool
any f = VG.any f . fromSized
{-# inline any #-}
and :: VG.Vector v Bool => Vector v n Bool -> Bool
and = VG.and . fromSized
{-# inline and #-}
or :: VG.Vector v Bool => Vector v n Bool -> Bool
or = VG.or . fromSized
{-# inline or #-}
sum :: (VG.Vector v a, Num a) => Vector v n a -> a
sum = VG.sum . fromSized
{-# inline sum #-}
product :: (VG.Vector v a, Num a) => Vector v n a -> a
product = VG.product . fromSized
{-# inline product #-}
maximum :: (VG.Vector v a, Ord a) => Vector v (n+1) a -> a
maximum = VG.maximum . fromSized
{-# inline maximum #-}
maximumBy :: VG.Vector v a
=> (a -> a -> Ordering) -> Vector v (n+1) a -> a
maximumBy cmpr = VG.maximumBy cmpr . fromSized
{-# inline maximumBy #-}
minimum :: (VG.Vector v a, Ord a) => Vector v (n+1) a -> a
minimum = VG.minimum . fromSized
{-# inline minimum #-}
minimumBy :: VG.Vector v a
=> (a -> a -> Ordering) -> Vector v (n+1) a -> a
minimumBy cmpr = VG.minimumBy cmpr . fromSized
{-# inline minimumBy #-}
maxIndex :: (VG.Vector v a, Ord a) => Vector v (n+1) a -> Finite (n+1)
maxIndex = Finite . fromIntegral . VG.maxIndex . fromSized
{-# inline maxIndex #-}
maxIndexBy :: VG.Vector v a
=> (a -> a -> Ordering) -> Vector v (n+1) a -> Finite (n + 1)
maxIndexBy cmpr = Finite . fromIntegral . VG.maxIndexBy cmpr . fromSized
{-# inline maxIndexBy #-}
minIndex :: (VG.Vector v a, Ord a) => Vector v (n+1) a -> Finite (n+1)
minIndex = Finite . fromIntegral . VG.minIndex . fromSized
{-# inline minIndex #-}
minIndexBy :: VG.Vector v a
=> (a -> a -> Ordering) -> Vector v (n+1) a -> Finite (n + 1)
minIndexBy cmpr = Finite . fromIntegral . VG.minIndexBy cmpr . fromSized
{-# inline minIndexBy #-}
foldM :: (Monad m, VG.Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a
foldM m z = VG.foldM m z . fromSized
{-# inline foldM #-}
ifoldM :: (Monad m, VG.Vector v b) => (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m a
ifoldM m z = VG.ifoldM (\x -> m x . Finite . fromIntegral) z . fromSized
{-# inline ifoldM #-}
fold1M :: (Monad m, VG.Vector v a)
=> (a -> a -> m a) -> Vector v (1+n) a -> m a
fold1M m = VG.fold1M m . fromSized
{-# inline fold1M #-}
foldM' :: (Monad m, VG.Vector v b) => (a -> b -> m a) -> a -> Vector v n b -> m a
foldM' m z = VG.foldM' m z . fromSized
{-# inline foldM' #-}
ifoldM' :: (Monad m, VG.Vector v b)
=> (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m a
ifoldM' m z = VG.ifoldM' (\x -> m x . Finite . fromIntegral) z . fromSized
{-# inline ifoldM' #-}
fold1M' :: (Monad m, VG.Vector v a)
=> (a -> a -> m a) -> Vector v (n+1) a -> m a
fold1M' m = VG.fold1M' m . fromSized
{-# inline fold1M' #-}
foldM_ :: (Monad m, VG.Vector v b)
=> (a -> b -> m a) -> a -> Vector v n b -> m ()
foldM_ m z = VG.foldM_ m z . fromSized
{-# inline foldM_ #-}
ifoldM_ :: (Monad m, VG.Vector v b)
=> (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m ()
ifoldM_ m z = VG.ifoldM_ (\x -> m x . Finite . fromIntegral) z . fromSized
{-# inline ifoldM_ #-}
fold1M_ :: (Monad m, VG.Vector v a)
=> (a -> a -> m a) -> Vector v (n+1) a -> m ()
fold1M_ m = VG.fold1M_ m . fromSized
{-# inline fold1M_ #-}
foldM'_ :: (Monad m, VG.Vector v b)
=> (a -> b -> m a) -> a -> Vector v n b -> m ()
foldM'_ m z = VG.foldM'_ m z . fromSized
{-# inline foldM'_ #-}
ifoldM'_ :: (Monad m, VG.Vector v b)
=> (a -> Finite n -> b -> m a) -> a -> Vector v n b -> m ()
ifoldM'_ m z = VG.ifoldM'_ (\x -> m x . Finite . fromIntegral) z . fromSized
{-# inline ifoldM'_ #-}
fold1M'_ :: (Monad m, VG.Vector v a)
=> (a -> a -> m a) -> Vector v (n+1) a -> m ()
fold1M'_ m = VG.fold1M'_ m . fromSized
{-# inline fold1M'_ #-}
sequence :: (Monad m, VG.Vector v a, VG.Vector v (m a))
=> Vector v n (m a) -> m (Vector v n a)
sequence (Vector v) = Vector <$> VG.sequence v
{-# inline sequence #-}
sequence_ :: (Monad m, VG.Vector v (m a)) => Vector v n (m a) -> m ()
sequence_ (Vector v) = VG.sequence_ v
{-# inline sequence_ #-}
prescanl :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
prescanl f z = withVectorUnsafe (VG.prescanl f z )
{-# inline prescanl #-}
prescanl' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
prescanl' f z = withVectorUnsafe (VG.prescanl' f z )
{-# inline prescanl' #-}
postscanl :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
postscanl f z = withVectorUnsafe (VG.postscanl f z )
{-# inline postscanl #-}
postscanl' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
postscanl' f z = withVectorUnsafe (VG.postscanl' f z )
{-# inline postscanl' #-}
scanl :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
scanl f z = withVectorUnsafe (VG.scanl f z )
{-# inline scanl #-}
scanl' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> a) -> a -> Vector v n b -> Vector v n a
scanl' f z = withVectorUnsafe (VG.scanl' f z )
{-# inline scanl' #-}
scanl1 :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> Vector v (n+1) a
scanl1 f = withVectorUnsafe (VG.scanl1 f )
{-# inline scanl1 #-}
scanl1' :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> Vector v (n+1) a
scanl1' f = withVectorUnsafe (VG.scanl1' f )
{-# inline scanl1' #-}
prescanr :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
prescanr f z = withVectorUnsafe (VG.prescanr f z )
{-# inline prescanr #-}
prescanr' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
prescanr' f z = withVectorUnsafe (VG.prescanr' f z )
{-# inline prescanr' #-}
postscanr :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
postscanr f z = withVectorUnsafe (VG.postscanr f z )
{-# inline postscanr #-}
postscanr' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
postscanr' f z = withVectorUnsafe (VG.postscanr' f z )
{-# inline postscanr' #-}
scanr :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
scanr f z = withVectorUnsafe (VG.scanr f z )
{-# inline scanr #-}
scanr' :: (VG.Vector v a, VG.Vector v b) => (a -> b -> b) -> b -> Vector v n a -> Vector v n b
scanr' f z = withVectorUnsafe (VG.scanr' f z )
{-# inline scanr' #-}
scanr1 :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> Vector v (n+1) a
scanr1 f = withVectorUnsafe (VG.scanr1 f )
{-# inline scanr1 #-}
scanr1' :: VG.Vector v a => (a -> a -> a) -> Vector v (n+1) a -> Vector v (n+1) a
scanr1' f = withVectorUnsafe (VG.scanr1' f )
{-# inline scanr1' #-}
toList :: VG.Vector v a => Vector v n a -> [a]
toList = VG.toList . fromSized
{-# inline toList #-}
fromList :: (VG.Vector v a, KnownNat n) => [a] -> Maybe (Vector v n a)
fromList = toSized . VG.fromList
{-# inline fromList #-}
fromListN :: forall v n a. (VG.Vector v a, KnownNat n)
=> [a] -> Maybe (Vector v n a)
fromListN = toSized . VG.fromListN i
where i = fromIntegral (natVal (Proxy :: Proxy n))
{-# inline fromListN #-}
fromListN' :: forall v n a p. (VG.Vector v a, KnownNat n)
=> p n -> [a] -> Maybe (Vector v n a)
fromListN' _ = fromListN
{-# inline fromListN' #-}
withSizedList :: forall v a r. VG.Vector v a
=> [a] -> (forall n. KnownNat n => Vector v n a -> r) -> r
withSizedList xs = withSized (VG.fromList xs)
convert :: (VG.Vector v a, VG.Vector w a) => Vector v n a -> Vector w n a
convert = withVectorUnsafe VG.convert
{-# inline convert #-}
freeze :: (PrimMonad m, VG.Vector v a)
=> SVGM.MVector (VG.Mutable v) n (PrimState m) a
-> m (Vector v n a)
freeze (MVector v) = Vector <$> VG.freeze v
unsafeFreeze :: (PrimMonad m, VG.Vector v a)
=> SVGM.MVector (VG.Mutable v) n (PrimState m) a
-> m (Vector v n a)
unsafeFreeze (MVector v) = Vector <$> VG.unsafeFreeze v
thaw :: (PrimMonad m, VG.Vector v a)
=> Vector v n a
-> m (SVGM.MVector (VG.Mutable v) n (PrimState m) a)
thaw (Vector v) = MVector <$> VG.thaw v
unsafeThaw :: (PrimMonad m, VG.Vector v a)
=> Vector v n a
-> m (SVGM.MVector (VG.Mutable v) n (PrimState m) a)
unsafeThaw (Vector v) = MVector <$> VG.unsafeThaw v
copy :: (PrimMonad m, VG.Vector v a)
=> SVGM.MVector (VG.Mutable v) n (PrimState m) a
-> Vector v n a
-> m ()
copy (MVector v) (Vector u) = VG.unsafeCopy v u
toSized :: forall v n a. (VG.Vector v a, KnownNat n)
=> v a -> Maybe (Vector v n a)
toSized v
| n' == fromIntegral (VG.length v) = Just (Vector v)
| otherwise = Nothing
where n' = natVal (Proxy :: Proxy n)
{-# inline toSized #-}
withSized :: forall v a r. VG.Vector v a
=> v a
-> (forall n. KnownNat n => Vector v n a -> r) -> r
withSized v f = case someNatVal (fromIntegral (VG.length v)) of
Just (SomeNat (Proxy :: Proxy n)) -> f (Vector v :: Vector v n a)
Nothing -> error "impossible: Vector has negative length"
fromSized :: Vector v n a -> v a
fromSized (Vector v) = v
{-# inline fromSized #-}
withVectorUnsafe :: (v a -> w b) -> Vector v n a -> Vector w n b
withVectorUnsafe f (Vector v) = Vector (f v)
{-# inline withVectorUnsafe #-}
instance (VG.Vector v a, Num a, KnownNat n) => Num (Vector v n a) where
(+) = zipWith (+)
(-) = zipWith (-)
(*) = zipWith (*)
negate = map negate
abs = map abs
signum = map signum
fromInteger = replicate . fromInteger
instance (VG.Vector v a, Fractional a, KnownNat n) => Fractional (Vector v n a) where
(/) = zipWith (/)
recip = map recip
fromRational = replicate . fromRational
instance (VG.Vector v a, Floating a, KnownNat n) => Floating (Vector v n a) where
pi = replicate pi
exp = map exp
log = map log
sqrt = map sqrt
(**) = zipWith (**)
logBase = zipWith logBase
sin = map sin
cos = map cos
tan = map tan
asin = map asin
acos = map acos
atan = map atan
sinh = map sinh
cosh = map cosh
tanh = map tanh
asinh = map asinh
acosh = map acosh
atanh = map atanh