fixed-vector-0.9.0.0: Generic vectors with statically known size.

Safe HaskellNone
LanguageHaskell98

Data.Vector.Fixed.Mutable

Contents

Description

Type classes for vectors which are implemented on top of the arrays and support in-place mutation. API is similar to one used in the vector package.

Synopsis

Mutable vectors

class Arity n where Source #

Type class for handling n-ary functions.

Minimal complete definition

accum, applyFun, applyFunM, arity, reverseF, uncurryMany, gunfoldF

Methods

arity :: n -> Int Source #

Arity of function.

Instances

Arity Z Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t Z -> Fun Z a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t Z -> Fn Z a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t Z -> m (ContVec Z a, t Z) Source #

arity :: Z -> Int Source #

reverseF :: Fun Z a b -> Fun Z a b Source #

uncurryMany :: Fun (Add Z k) a b -> Fun Z a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a Z -> c r Source #

Arity n => Arity (S n) Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t (S n) -> Fun (S n) a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t (S n) -> Fn (S n) a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t (S n) -> m (ContVec (S n) a, t Z) Source #

arity :: S n -> Int Source #

reverseF :: Fun (S n) a b -> Fun (S n) a b Source #

uncurryMany :: Fun (Add (S n) k) a b -> Fun (S n) a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a (S n) -> c r Source #

arity :: Arity n => n -> Int Source #

Arity of function.

type family Mutable (v :: * -> *) :: * -> * -> * Source #

Mutable counterpart of fixed-length vector.

Instances

type Mutable (Vec n) Source # 
type Mutable (Vec n) = MVec n
type Mutable (Vec n) Source # 
type Mutable (Vec n) = MVec n
type Mutable (Vec n) Source # 
type Mutable (Vec n) = MVec n
type Mutable (Vec n) Source # 
type Mutable (Vec n) = MVec n

type family DimM (v :: * -> * -> *) :: * Source #

Dimension for mutable vector.

Instances

type DimM (MVec n) Source # 
type DimM (MVec n) = n
type DimM (MVec n) Source # 
type DimM (MVec n) = n
type DimM (MVec n) Source # 
type DimM (MVec n) = n
type DimM (MVec n) Source # 
type DimM (MVec n) = n

class Arity (DimM v) => MVector v a where Source #

Type class for mutable vectors.

Minimal complete definition

overlaps, copy, move, new, unsafeRead, unsafeWrite

Methods

overlaps :: v s a -> v s a -> Bool Source #

Checks whether vectors' buffers overlaps

copy :: PrimMonad m => v (PrimState m) a -> v (PrimState m) a -> m () Source #

Copy vector. The two vectors may not overlap. Since vectors' length is encoded in the type there is no need in runtime checks.

move :: PrimMonad m => v (PrimState m) a -> v (PrimState m) a -> m () Source #

Copy vector. The two vectors may overlap. Since vectors' length is encoded in the type there is no need in runtime checks.

new :: PrimMonad m => m (v (PrimState m) a) Source #

Allocate new vector

unsafeRead :: PrimMonad m => v (PrimState m) a -> Int -> m a Source #

Read value at index without bound checks.

unsafeWrite :: PrimMonad m => v (PrimState m) a -> Int -> a -> m () Source #

Write value at index without bound checks.

Instances

Arity n => MVector (MVec n) a Source # 

Methods

overlaps :: MVec n s a -> MVec n s a -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) a) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) a -> Int -> m a Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) a -> Int -> a -> m () Source #

(Arity n, Prim a) => MVector (MVec n) a Source # 

Methods

overlaps :: MVec n s a -> MVec n s a -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) a) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) a -> Int -> m a Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) a -> Int -> a -> m () Source #

(Arity n, Storable a) => MVector (MVec n) a Source # 

Methods

overlaps :: MVec n s a -> MVec n s a -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) a -> MVec n (PrimState m) a -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) a) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) a -> Int -> m a Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) a -> Int -> a -> m () Source #

Arity n => MVector (MVec n) Double Source # 
Arity n => MVector (MVec n) Float Source # 

Methods

overlaps :: MVec n s Float -> MVec n s Float -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Float -> MVec n (PrimState m) Float -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Float -> MVec n (PrimState m) Float -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Float) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Float -> Int -> m Float Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Float -> Int -> Float -> m () Source #

Arity n => MVector (MVec n) Char Source # 

Methods

overlaps :: MVec n s Char -> MVec n s Char -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Char -> MVec n (PrimState m) Char -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Char -> MVec n (PrimState m) Char -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Char) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Char -> Int -> m Char Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Char -> Int -> Char -> m () Source #

Arity n => MVector (MVec n) Word64 Source # 
Arity n => MVector (MVec n) Word32 Source # 
Arity n => MVector (MVec n) Word16 Source # 
Arity n => MVector (MVec n) Word8 Source # 

Methods

overlaps :: MVec n s Word8 -> MVec n s Word8 -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Word8 -> MVec n (PrimState m) Word8 -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Word8 -> MVec n (PrimState m) Word8 -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Word8) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Word8 -> Int -> m Word8 Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Word8 -> Int -> Word8 -> m () Source #

Arity n => MVector (MVec n) Word Source # 

Methods

overlaps :: MVec n s Word -> MVec n s Word -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Word -> MVec n (PrimState m) Word -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Word -> MVec n (PrimState m) Word -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Word) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Word -> Int -> m Word Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Word -> Int -> Word -> m () Source #

Arity n => MVector (MVec n) Int64 Source # 

Methods

overlaps :: MVec n s Int64 -> MVec n s Int64 -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Int64 -> MVec n (PrimState m) Int64 -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Int64 -> MVec n (PrimState m) Int64 -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Int64) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Int64 -> Int -> m Int64 Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Int64 -> Int -> Int64 -> m () Source #

Arity n => MVector (MVec n) Int32 Source # 

Methods

overlaps :: MVec n s Int32 -> MVec n s Int32 -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Int32 -> MVec n (PrimState m) Int32 -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Int32 -> MVec n (PrimState m) Int32 -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Int32) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Int32 -> Int -> m Int32 Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Int32 -> Int -> Int32 -> m () Source #

Arity n => MVector (MVec n) Int16 Source # 

Methods

overlaps :: MVec n s Int16 -> MVec n s Int16 -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Int16 -> MVec n (PrimState m) Int16 -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Int16 -> MVec n (PrimState m) Int16 -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Int16) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Int16 -> Int -> m Int16 Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Int16 -> Int -> Int16 -> m () Source #

Arity n => MVector (MVec n) Int8 Source # 

Methods

overlaps :: MVec n s Int8 -> MVec n s Int8 -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Int8 -> MVec n (PrimState m) Int8 -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Int8 -> MVec n (PrimState m) Int8 -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Int8) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Int8 -> Int -> m Int8 Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Int8 -> Int -> Int8 -> m () Source #

Arity n => MVector (MVec n) Int Source # 

Methods

overlaps :: MVec n s Int -> MVec n s Int -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Int -> MVec n (PrimState m) Int -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Int -> MVec n (PrimState m) Int -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Int) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Int -> Int -> m Int Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Int -> Int -> Int -> m () Source #

Arity n => MVector (MVec n) Bool Source # 

Methods

overlaps :: MVec n s Bool -> MVec n s Bool -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) Bool -> MVec n (PrimState m) Bool -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) Bool -> MVec n (PrimState m) Bool -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) Bool) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) Bool -> Int -> m Bool Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) Bool -> Int -> Bool -> m () Source #

Arity n => MVector (MVec n) () Source # 

Methods

overlaps :: MVec n s () -> MVec n s () -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) () -> MVec n (PrimState m) () -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) () -> MVec n (PrimState m) () -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) ()) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) () -> Int -> m () Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) () -> Int -> () -> m () Source #

(Arity n, MVector (MVec n) a) => MVector (MVec n) (Complex a) Source # 

Methods

overlaps :: MVec n s (Complex a) -> MVec n s (Complex a) -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) (Complex a) -> MVec n (PrimState m) (Complex a) -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) (Complex a) -> MVec n (PrimState m) (Complex a) -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) (Complex a)) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) (Complex a) -> Int -> m (Complex a) Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) (Complex a) -> Int -> Complex a -> m () Source #

(Arity n, MVector (MVec n) a, MVector (MVec n) b) => MVector (MVec n) (a, b) Source # 

Methods

overlaps :: MVec n s (a, b) -> MVec n s (a, b) -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) (a, b) -> MVec n (PrimState m) (a, b) -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) (a, b) -> MVec n (PrimState m) (a, b) -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) (a, b)) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) (a, b) -> Int -> m (a, b) Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) (a, b) -> Int -> (a, b) -> m () Source #

(Arity n, MVector (MVec n) a, MVector (MVec n) b, MVector (MVec n) c) => MVector (MVec n) (a, b, c) Source # 

Methods

overlaps :: MVec n s (a, b, c) -> MVec n s (a, b, c) -> Bool Source #

copy :: PrimMonad m => MVec n (PrimState m) (a, b, c) -> MVec n (PrimState m) (a, b, c) -> m () Source #

move :: PrimMonad m => MVec n (PrimState m) (a, b, c) -> MVec n (PrimState m) (a, b, c) -> m () Source #

new :: PrimMonad m => m (MVec n (PrimState m) (a, b, c)) Source #

unsafeRead :: PrimMonad m => MVec n (PrimState m) (a, b, c) -> Int -> m (a, b, c) Source #

unsafeWrite :: PrimMonad m => MVec n (PrimState m) (a, b, c) -> Int -> (a, b, c) -> m () Source #

lengthM :: forall v s a. Arity (DimM v) => v s a -> Int Source #

Length of mutable vector. Function doesn't evaluate its argument.

read :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m a Source #

Read value at index with bound checks.

write :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () Source #

Write value at index with bound checks.

clone :: (PrimMonad m, MVector v a) => v (PrimState m) a -> m (v (PrimState m) a) Source #

Create copy of vector.

Immutable vectors

class (Dim v ~ DimM (Mutable v), MVector (Mutable v) a) => IVector v a where Source #

Type class for immutable vectors

Minimal complete definition

unsafeFreeze, unsafeThaw, unsafeIndex

Methods

unsafeFreeze :: PrimMonad m => Mutable v (PrimState m) a -> m (v a) Source #

Convert vector to immutable state. Mutable vector must not be modified afterwards.

unsafeThaw :: PrimMonad m => v a -> m (Mutable v (PrimState m) a) Source #

Convert immutable vector to mutable. Immutable vector must not be used afterwards.

unsafeIndex :: v a -> Int -> a Source #

Get element at specified index without bounds check.

Instances

Arity n => IVector (Vec n) a Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) a -> m (Vec n a) Source #

unsafeThaw :: PrimMonad m => Vec n a -> m (Mutable (Vec n) (PrimState m) a) Source #

unsafeIndex :: Vec n a -> Int -> a Source #

(Arity n, Prim a) => IVector (Vec n) a Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) a -> m (Vec n a) Source #

unsafeThaw :: PrimMonad m => Vec n a -> m (Mutable (Vec n) (PrimState m) a) Source #

unsafeIndex :: Vec n a -> Int -> a Source #

(Arity n, Storable a) => IVector (Vec n) a Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) a -> m (Vec n a) Source #

unsafeThaw :: PrimMonad m => Vec n a -> m (Mutable (Vec n) (PrimState m) a) Source #

unsafeIndex :: Vec n a -> Int -> a Source #

Arity n => IVector (Vec n) Double Source # 
Arity n => IVector (Vec n) Float Source # 
Arity n => IVector (Vec n) Char Source # 
Arity n => IVector (Vec n) Word64 Source # 
Arity n => IVector (Vec n) Word32 Source # 
Arity n => IVector (Vec n) Word16 Source # 
Arity n => IVector (Vec n) Word8 Source # 
Arity n => IVector (Vec n) Word Source # 
Arity n => IVector (Vec n) Int64 Source # 
Arity n => IVector (Vec n) Int32 Source # 
Arity n => IVector (Vec n) Int16 Source # 
Arity n => IVector (Vec n) Int8 Source # 
Arity n => IVector (Vec n) Int Source # 
Arity n => IVector (Vec n) Bool Source # 
Arity n => IVector (Vec n) () Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) () -> m (Vec n ()) Source #

unsafeThaw :: PrimMonad m => Vec n () -> m (Mutable (Vec n) (PrimState m) ()) Source #

unsafeIndex :: Vec n () -> Int -> () Source #

(Arity n, IVector (Vec n) a) => IVector (Vec n) (Complex a) Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) (Complex a) -> m (Vec n (Complex a)) Source #

unsafeThaw :: PrimMonad m => Vec n (Complex a) -> m (Mutable (Vec n) (PrimState m) (Complex a)) Source #

unsafeIndex :: Vec n (Complex a) -> Int -> Complex a Source #

(Arity n, IVector (Vec n) a, IVector (Vec n) b) => IVector (Vec n) (a, b) Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) (a, b) -> m (Vec n (a, b)) Source #

unsafeThaw :: PrimMonad m => Vec n (a, b) -> m (Mutable (Vec n) (PrimState m) (a, b)) Source #

unsafeIndex :: Vec n (a, b) -> Int -> (a, b) Source #

(Arity n, Vector (Vec n) a, Vector (Vec n) b, Vector (Vec n) c, IVector (Vec n) a, IVector (Vec n) b, IVector (Vec n) c) => IVector (Vec n) (a, b, c) Source # 

Methods

unsafeFreeze :: PrimMonad m => Mutable (Vec n) (PrimState m) (a, b, c) -> m (Vec n (a, b, c)) Source #

unsafeThaw :: PrimMonad m => Vec n (a, b, c) -> m (Mutable (Vec n) (PrimState m) (a, b, c)) Source #

unsafeIndex :: Vec n (a, b, c) -> Int -> (a, b, c) Source #

index :: IVector v a => v a -> Int -> a Source #

lengthI :: IVector v a => v a -> Int Source #

Length of immutable vector. Function doesn't evaluate its argument.

freeze :: (PrimMonad m, IVector v a) => Mutable v (PrimState m) a -> m (v a) Source #

Safely convert mutable vector to immutable.

thaw :: (PrimMonad m, IVector v a) => v a -> m (Mutable v (PrimState m) a) Source #

Safely convert immutable vector to mutable.

Vector API

constructVec :: forall v a. (Arity (Dim v), IVector v a) => Fun (Dim v) a (v a) Source #

Generic construct implementation for array-based vectors.

inspectVec :: forall v a b. (Arity (Dim v), IVector v a) => v a -> Fun (Dim v) a b -> b Source #

Generic inspect implementation for array-based vectors.