rio-0.1.9.1: A standard library for Haskell

Safe HaskellNone
LanguageHaskell2010

RIO.Vector.Unsafe

Contents

Synopsis

Immutable vectors

class MVector (Mutable v) a => Vector (v :: Type -> Type) a where #

Class of immutable vectors. Every immutable vector is associated with its mutable version through the Mutable type family. Methods of this class should not be used directly. Instead, Data.Vector.Generic and other Data.Vector modules provide safe and fusible wrappers.

Minimum complete implementation:

Methods

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

Assumed complexity: O(1)

Unsafely convert a mutable vector to its immutable version without copying. The mutable vector may not be used after this operation.

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

Assumed complexity: O(1)

Unsafely convert an immutable vector to its mutable version without copying. The immutable vector may not be used after this operation.

basicLength :: v a -> Int #

Assumed complexity: O(1)

Yield the length of the vector.

basicUnsafeSlice #

Arguments

:: Int

starting index

-> Int

length

-> v a 
-> v a 

Assumed complexity: O(1)

Yield a slice of the vector without copying it. No range checks are performed.

basicUnsafeIndexM :: Monad m => v a -> Int -> m a #

Assumed complexity: O(1)

Yield the element at the given position in a monad. No range checks are performed.

The monad allows us to be strict in the vector if we want. Suppose we had

unsafeIndex :: v a -> Int -> a

instead. Now, if we wanted to copy a vector, we'd do something like

copy mv v ... = ... unsafeWrite mv i (unsafeIndex v i) ...

For lazy vectors, the indexing would not be evaluated which means that we would retain a reference to the original vector in each element we write. This is not what we want!

With basicUnsafeIndexM, we can do

copy mv v ... = ... case basicUnsafeIndexM v i of
                      Box x -> unsafeWrite mv i x ...

which does not have this problem because indexing (but not the returned element!) is evaluated immediately.

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

Assumed complexity: O(n)

Copy an immutable vector into a mutable one. The two vectors must have the same length but this is not checked.

Instances of Vector should redefine this method if they wish to support an efficient block copy operation.

Default definition: copying basic on basicUnsafeIndexM and basicUnsafeWrite.

elemseq :: v a -> a -> b -> b #

Evaluate a as far as storing it in a vector would and yield b. The v a argument only fixes the type and is not touched. The method is only used for optimisation purposes. Thus, it is safe for instances of Vector to evaluate a less than it would be when stored in a vector although this might result in suboptimal code.

elemseq v x y = (singleton x `asTypeOf` v) `seq` y

Default defintion: a is not evaluated at all

Instances
Vector Vector Bool 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Char 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Double 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Float 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Int 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Int8 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Int16 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Int32 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Int64 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Word 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Word8 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Word16 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Word32 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector Word64 
Instance details

Defined in Data.Vector.Unboxed.Base

Vector Vector () 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) () -> m (Vector ()) #

basicUnsafeThaw :: PrimMonad m => Vector () -> m (Mutable Vector (PrimState m) ()) #

basicLength :: Vector () -> Int #

basicUnsafeSlice :: Int -> Int -> Vector () -> Vector () #

basicUnsafeIndexM :: Monad m => Vector () -> Int -> m () #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) () -> Vector () -> m () #

elemseq :: Vector () -> () -> b -> b #

Storable a => Vector Vector a 
Instance details

Defined in Data.Vector.Storable

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) a -> m (Vector a) #

basicUnsafeThaw :: PrimMonad m => Vector a -> m (Mutable Vector (PrimState m) a) #

basicLength :: Vector a -> Int #

basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a #

basicUnsafeIndexM :: Monad m => Vector a -> Int -> m a #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) a -> Vector a -> m () #

elemseq :: Vector a -> a -> b -> b #

Prim a => Vector Vector a 
Instance details

Defined in Data.Vector.Primitive

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) a -> m (Vector a) #

basicUnsafeThaw :: PrimMonad m => Vector a -> m (Mutable Vector (PrimState m) a) #

basicLength :: Vector a -> Int #

basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a #

basicUnsafeIndexM :: Monad m => Vector a -> Int -> m a #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) a -> Vector a -> m () #

elemseq :: Vector a -> a -> b -> b #

Vector Vector a 
Instance details

Defined in Data.Vector

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) a -> m (Vector a) #

basicUnsafeThaw :: PrimMonad m => Vector a -> m (Mutable Vector (PrimState m) a) #

basicLength :: Vector a -> Int #

basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a #

basicUnsafeIndexM :: Monad m => Vector a -> Int -> m a #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) a -> Vector a -> m () #

elemseq :: Vector a -> a -> b -> b #

Unbox a => Vector Vector (Complex a) 
Instance details

Defined in Data.Vector.Unboxed.Base

(Unbox a, Unbox b) => Vector Vector (a, b) 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (a, b) -> m (Vector (a, b)) #

basicUnsafeThaw :: PrimMonad m => Vector (a, b) -> m (Mutable Vector (PrimState m) (a, b)) #

basicLength :: Vector (a, b) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (a, b) -> Vector (a, b) #

basicUnsafeIndexM :: Monad m => Vector (a, b) -> Int -> m (a, b) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (a, b) -> Vector (a, b) -> m () #

elemseq :: Vector (a, b) -> (a, b) -> b0 -> b0 #

(Unbox a, Unbox b, Unbox c) => Vector Vector (a, b, c) 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c) -> m (Vector (a, b, c)) #

basicUnsafeThaw :: PrimMonad m => Vector (a, b, c) -> m (Mutable Vector (PrimState m) (a, b, c)) #

basicLength :: Vector (a, b, c) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (a, b, c) -> Vector (a, b, c) #

basicUnsafeIndexM :: Monad m => Vector (a, b, c) -> Int -> m (a, b, c) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c) -> Vector (a, b, c) -> m () #

elemseq :: Vector (a, b, c) -> (a, b, c) -> b0 -> b0 #

(Unbox a, Unbox b, Unbox c, Unbox d) => Vector Vector (a, b, c, d) 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d) -> m (Vector (a, b, c, d)) #

basicUnsafeThaw :: PrimMonad m => Vector (a, b, c, d) -> m (Mutable Vector (PrimState m) (a, b, c, d)) #

basicLength :: Vector (a, b, c, d) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (a, b, c, d) -> Vector (a, b, c, d) #

basicUnsafeIndexM :: Monad m => Vector (a, b, c, d) -> Int -> m (a, b, c, d) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d) -> Vector (a, b, c, d) -> m () #

elemseq :: Vector (a, b, c, d) -> (a, b, c, d) -> b0 -> b0 #

(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Vector Vector (a, b, c, d, e) 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d, e) -> m (Vector (a, b, c, d, e)) #

basicUnsafeThaw :: PrimMonad m => Vector (a, b, c, d, e) -> m (Mutable Vector (PrimState m) (a, b, c, d, e)) #

basicLength :: Vector (a, b, c, d, e) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (a, b, c, d, e) -> Vector (a, b, c, d, e) #

basicUnsafeIndexM :: Monad m => Vector (a, b, c, d, e) -> Int -> m (a, b, c, d, e) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d, e) -> Vector (a, b, c, d, e) -> m () #

elemseq :: Vector (a, b, c, d, e) -> (a, b, c, d, e) -> b0 -> b0 #

(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Vector Vector (a, b, c, d, e, f) 
Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d, e, f) -> m (Vector (a, b, c, d, e, f)) #

basicUnsafeThaw :: PrimMonad m => Vector (a, b, c, d, e, f) -> m (Mutable Vector (PrimState m) (a, b, c, d, e, f)) #

basicLength :: Vector (a, b, c, d, e, f) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (a, b, c, d, e, f) -> Vector (a, b, c, d, e, f) #

basicUnsafeIndexM :: Monad m => Vector (a, b, c, d, e, f) -> Int -> m (a, b, c, d, e, f) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (a, b, c, d, e, f) -> Vector (a, b, c, d, e, f) -> m () #

elemseq :: Vector (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> b0 -> b0 #

Accessors

Indexing

unsafeIndex :: Vector v a => v a -> Int -> a #

O(1) Unsafe indexing without bounds checking

unsafeHead :: Vector v a => v a -> a #

O(1) First element without checking if the vector is empty

unsafeLast :: Vector v a => v a -> a #

O(1) Last element without checking if the vector is empty

Monadic indexing

unsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a #

O(1) Indexing in a monad without bounds checks. See indexM for an explanation of why this is useful.

unsafeHeadM :: (Vector v a, Monad m) => v a -> m a #

O(1) First element in a monad without checking for empty vectors. See indexM for an explanation of why this is useful.

unsafeLastM :: (Vector v a, Monad m) => v a -> m a #

O(1) Last element in a monad without checking for empty vectors. See indexM for an explanation of why this is useful.

Extracting subvectors

unsafeSlice #

Arguments

:: Vector v a 
=> Int

i starting index

-> Int

n length

-> v a 
-> v a 

O(1) Yield a slice of the vector without copying. The vector must contain at least i+n elements but this is not checked.

unsafeInit :: Vector v a => v a -> v a #

O(1) Yield all but the last element without copying. The vector may not be empty but this is not checked.

unsafeTail :: Vector v a => v a -> v a #

O(1) Yield all but the first element without copying. The vector may not be empty but this is not checked.

unsafeTake :: Vector v a => Int -> v a -> v a #

O(1) Yield the first n elements without copying. The vector must contain at least n elements but this is not checked.

unsafeDrop :: Vector v a => Int -> v a -> v a #

O(1) Yield all but the first n elements without copying. The vector must contain at least n elements but this is not checked.

Modifying vectors

Bulk updates

unsafeUpd :: Vector v a => v a -> [(Int, a)] -> v a #

Same as (//) but without bounds checking.

unsafeUpdate :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a #

Same as update but without bounds checking.

unsafeUpdate_ :: (Vector v a, Vector v Int) => v a -> v Int -> v a -> v a #

Same as update_ but without bounds checking.

Accumulations

unsafeAccum :: Vector v a => (a -> b -> a) -> v a -> [(Int, b)] -> v a #

Same as accum but without bounds checking.

unsafeAccumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> v a -> v (Int, b) -> v a #

Same as accumulate but without bounds checking.

unsafeAccumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> v a -> v Int -> v b -> v a #

Same as accumulate_ but without bounds checking.

Permutations

unsafeBackpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a #

Same as backpermute but without bounds checking.

Conversions

Mutable vectors

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

O(1) Unsafe convert a mutable vector to an immutable one without copying. The mutable vector may not be used after this operation.

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

O(1) Unsafely convert an immutable vector to a mutable one without copying. The immutable vector may not be used after this operation.

unsafeCopy :: (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> v a -> m () #

O(n) Copy an immutable vector into a mutable one. The two vectors must have the same length. This is not checked.