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

Safe HaskellNone

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 whereSource

Type class for handling n-ary functions.

Methods

arity :: n -> IntSource

Arity of function.

Instances

Arity Z 
Arity n => Arity (S n) 

type family Mutable v :: * -> * -> *Source

Mutable counterpart of fixed-length vector.

type family DimM v :: *Source

Dimension for mutable vector.

class Arity (DimM v) => MVector v a whereSource

Type class for mutable vectors.

Methods

overlaps :: v s a -> v s a -> BoolSource

Checks whether vectors' buffers overlaps

copySource

Arguments

:: PrimMonad m 
=> v (PrimState m) a

Target

-> v (PrimState m) a

Source

-> m () 

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

moveSource

Arguments

:: PrimMonad m 
=> v (PrimState m) a

Target

-> v (PrimState m) a

Source

-> m () 

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 aSource

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 
(Arity n, Prim a) => MVector (MVec n) a 
Arity n => MVector (MVec n) Double 
Arity n => MVector (MVec n) Float 
Arity n => MVector (MVec n) Char 
Arity n => MVector (MVec n) Word64 
Arity n => MVector (MVec n) Word32 
Arity n => MVector (MVec n) Word16 
Arity n => MVector (MVec n) Word8 
Arity n => MVector (MVec n) Word 
Arity n => MVector (MVec n) Int64 
Arity n => MVector (MVec n) Int32 
Arity n => MVector (MVec n) Int16 
Arity n => MVector (MVec n) Int8 
Arity n => MVector (MVec n) Int 
Arity n => MVector (MVec n) Bool 
Arity n => MVector (MVec n) () 
(Arity n, Storable a) => MVector (MVec n) a 
(Arity n, MVector (MVec n) a) => MVector (MVec n) (Complex a) 
(Arity n, MVector (MVec n) a, MVector (MVec n) b) => MVector (MVec n) (a, b) 
(Arity n, MVector (MVec n) a, MVector (MVec n) b, MVector (MVec n) c) => MVector (MVec n) (a, b, c) 

lengthM :: forall v s a. Arity (DimM v) => v s a -> IntSource

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

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

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 whereSource

Type class for immutable vectors

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 -> aSource

Get element at specified index without bounds check.

Instances

Arity n => IVector (Vec n) a 
(Arity n, Prim a) => IVector (Vec n) a 
Arity n => IVector (Vec n) Double 
Arity n => IVector (Vec n) Float 
Arity n => IVector (Vec n) Char 
Arity n => IVector (Vec n) Word64 
Arity n => IVector (Vec n) Word32 
Arity n => IVector (Vec n) Word16 
Arity n => IVector (Vec n) Word8 
Arity n => IVector (Vec n) Word 
Arity n => IVector (Vec n) Int64 
Arity n => IVector (Vec n) Int32 
Arity n => IVector (Vec n) Int16 
Arity n => IVector (Vec n) Int8 
Arity n => IVector (Vec n) Int 
Arity n => IVector (Vec n) Bool 
Arity n => IVector (Vec n) () 
(Arity n, Storable a) => IVector (Vec n) a 
(Arity n, IVector (Vec n) a) => IVector (Vec n) (Complex a) 
(Arity n, IVector (Vec n) a, IVector (Vec n) b) => IVector (Vec n) (a, b) 
(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) 

index :: IVector v a => v a -> Int -> aSource

lengthI :: IVector v a => v a -> IntSource

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 -> bSource

Generic inspect implementation for array-based vectors.