rio-0.1.22.0: A standard library for Haskell

Safe Haskell | Safe-Inferred
Language | Haskell2010

RIO.Vector.Unsafe

Contents

- Immutable vectors
- Accessors
  - Indexing
  - Monadic indexing
  - Extracting subvectors
- Modifying vectors
  - Bulk updates
  - Accumulations
  - Permutations
- Conversions
  - Mutable vectors

Description

Generic `Vector` interface unsafe functions. These perform no bounds checking, and may cause segmentation faults etc.! Import as:

    import qualified RIO.Vector.Unsafe as V'

Synopsis

- class MVector (Mutable v) a => Vector (v :: Type -> Type) a where
  - basicUnsafeFreeze :: Mutable v s a -> ST s (v a)
  - basicUnsafeThaw :: v a -> ST s (Mutable v s a)
  - basicLength :: v a -> Int
  - basicUnsafeSlice :: Int -> Int -> v a -> v a
  - basicUnsafeIndexM :: v a -> Int -> Box a
  - basicUnsafeCopy :: Mutable v s a -> v a -> ST s ()
  - elemseq :: v a -> a -> b -> b
- unsafeIndex :: Vector v a => v a -> Int -> a
- unsafeHead :: Vector v a => v a -> a
- unsafeLast :: Vector v a => v a -> a
- unsafeIndexM :: (Vector v a, Monad m) => v a -> Int -> m a
- unsafeHeadM :: (Vector v a, Monad m) => v a -> m a
- unsafeLastM :: (Vector v a, Monad m) => v a -> m a
- unsafeSlice :: Vector v a => Int -> Int -> v a -> v a
- unsafeInit :: Vector v a => v a -> v a
- unsafeTail :: Vector v a => v a -> v a
- unsafeTake :: Vector v a => Int -> v a -> v a
- unsafeDrop :: Vector v a => Int -> v a -> v a
- unsafeUpd :: Vector v a => v a -> [(Int, a)] -> v a
- unsafeUpdate :: (Vector v a, Vector v (Int, a)) => v a -> v (Int, a) -> v a
- unsafeUpdate_ :: (Vector v a, Vector v Int) => v a -> v Int -> v a -> v a
- unsafeAccum :: Vector v a => (a -> b -> a) -> v a -> [(Int, b)] -> v a
- unsafeAccumulate :: (Vector v a, Vector v (Int, b)) => (a -> b -> a) -> v a -> v (Int, b) -> v a
- unsafeAccumulate_ :: (Vector v a, Vector v Int, Vector v b) => (a -> b -> a) -> v a -> v Int -> v b -> v a
- unsafeBackpermute :: (Vector v a, Vector v Int) => v a -> v Int -> v a
- unsafeFreeze :: (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> m (v a)
- unsafeThaw :: (PrimMonad m, Vector v a) => v a -> m (Mutable v (PrimState m) a)
- unsafeCopy :: (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> v a -> m ()

# 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:

- `basicUnsafeFreeze`
- `basicUnsafeThaw`
- `basicLength`
- `basicUnsafeSlice`
- `basicUnsafeIndexM`

Minimal complete definition

basicUnsafeFreeze, basicUnsafeThaw, basicLength, basicUnsafeSlice, basicUnsafeIndexM

Methods

basicUnsafeFreeze :: Mutable v s a -> ST s (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 :: v a -> ST s (Mutable v s 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 :: v a -> Int -> Box 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 :: Mutable v s a -> v a -> ST s () #

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 based 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. This 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

Instances details

Vector Vector a |

Instance details

Defined in Data.Vector

Methods

basicUnsafeFreeze :: Mutable Vector s a -> ST s (Vector a) #

basicUnsafeThaw :: Vector a -> ST s (Mutable Vector s a) #

basicLength :: Vector a -> Int #

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

basicUnsafeIndexM :: Vector a -> Int -> Box a #

basicUnsafeCopy :: Mutable Vector s a -> Vector a -> ST s () #

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

Prim a => Vector Vector a |

Instance details

Defined in Data.Vector.Primitive

Methods

basicUnsafeFreeze :: Mutable Vector s a -> ST s (Vector a) #

basicUnsafeThaw :: Vector a -> ST s (Mutable Vector s a) #

basicLength :: Vector a -> Int #

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

basicUnsafeIndexM :: Vector a -> Int -> Box a #

basicUnsafeCopy :: Mutable Vector s a -> Vector a -> ST s () #

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

Storable a => Vector Vector a |

Instance details

Defined in Data.Vector.Storable

Methods

basicUnsafeFreeze :: Mutable Vector s a -> ST s (Vector a) #

basicUnsafeThaw :: Vector a -> ST s (Mutable Vector s a) #

basicLength :: Vector a -> Int #

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

basicUnsafeIndexM :: Vector a -> Int -> Box a #

basicUnsafeCopy :: Mutable Vector s a -> Vector a -> ST s () #

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

Vector Vector All |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s All -> ST s (Vector All) #

basicUnsafeThaw :: Vector All -> ST s (Mutable Vector s All) #

basicLength :: Vector All -> Int #

basicUnsafeSlice :: Int -> Int -> Vector All -> Vector All #

basicUnsafeIndexM :: Vector All -> Int -> Box All #

basicUnsafeCopy :: Mutable Vector s All -> Vector All -> ST s () #

elemseq :: Vector All -> All -> b -> b #

Vector Vector Any |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Any -> ST s (Vector Any) #

basicUnsafeThaw :: Vector Any -> ST s (Mutable Vector s Any) #

basicLength :: Vector Any -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Any -> Vector Any #

basicUnsafeIndexM :: Vector Any -> Int -> Box Any #

basicUnsafeCopy :: Mutable Vector s Any -> Vector Any -> ST s () #

elemseq :: Vector Any -> Any -> b -> b #

Vector Vector Int16 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Int16 -> ST s (Vector Int16) #

basicUnsafeThaw :: Vector Int16 -> ST s (Mutable Vector s Int16) #

basicLength :: Vector Int16 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Int16 -> Vector Int16 #

basicUnsafeIndexM :: Vector Int16 -> Int -> Box Int16 #

basicUnsafeCopy :: Mutable Vector s Int16 -> Vector Int16 -> ST s () #

elemseq :: Vector Int16 -> Int16 -> b -> b #

Vector Vector Int32 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Int32 -> ST s (Vector Int32) #

basicUnsafeThaw :: Vector Int32 -> ST s (Mutable Vector s Int32) #

basicLength :: Vector Int32 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Int32 -> Vector Int32 #

basicUnsafeIndexM :: Vector Int32 -> Int -> Box Int32 #

basicUnsafeCopy :: Mutable Vector s Int32 -> Vector Int32 -> ST s () #

elemseq :: Vector Int32 -> Int32 -> b -> b #

Vector Vector Int64 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Int64 -> ST s (Vector Int64) #

basicUnsafeThaw :: Vector Int64 -> ST s (Mutable Vector s Int64) #

basicLength :: Vector Int64 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Int64 -> Vector Int64 #

basicUnsafeIndexM :: Vector Int64 -> Int -> Box Int64 #

basicUnsafeCopy :: Mutable Vector s Int64 -> Vector Int64 -> ST s () #

elemseq :: Vector Int64 -> Int64 -> b -> b #

Vector Vector Int8 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Int8 -> ST s (Vector Int8) #

basicUnsafeThaw :: Vector Int8 -> ST s (Mutable Vector s Int8) #

basicLength :: Vector Int8 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Int8 -> Vector Int8 #

basicUnsafeIndexM :: Vector Int8 -> Int -> Box Int8 #

basicUnsafeCopy :: Mutable Vector s Int8 -> Vector Int8 -> ST s () #

elemseq :: Vector Int8 -> Int8 -> b -> b #

Vector Vector Word16 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Word16 -> ST s (Vector Word16) #

basicUnsafeThaw :: Vector Word16 -> ST s (Mutable Vector s Word16) #

basicLength :: Vector Word16 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Word16 -> Vector Word16 #

basicUnsafeIndexM :: Vector Word16 -> Int -> Box Word16 #

basicUnsafeCopy :: Mutable Vector s Word16 -> Vector Word16 -> ST s () #

elemseq :: Vector Word16 -> Word16 -> b -> b #

Vector Vector Word32 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Word32 -> ST s (Vector Word32) #

basicUnsafeThaw :: Vector Word32 -> ST s (Mutable Vector s Word32) #

basicLength :: Vector Word32 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Word32 -> Vector Word32 #

basicUnsafeIndexM :: Vector Word32 -> Int -> Box Word32 #

basicUnsafeCopy :: Mutable Vector s Word32 -> Vector Word32 -> ST s () #

elemseq :: Vector Word32 -> Word32 -> b -> b #

Vector Vector Word64 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Word64 -> ST s (Vector Word64) #

basicUnsafeThaw :: Vector Word64 -> ST s (Mutable Vector s Word64) #

basicLength :: Vector Word64 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Word64 -> Vector Word64 #

basicUnsafeIndexM :: Vector Word64 -> Int -> Box Word64 #

basicUnsafeCopy :: Mutable Vector s Word64 -> Vector Word64 -> ST s () #

elemseq :: Vector Word64 -> Word64 -> b -> b #

Vector Vector Word8 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Word8 -> ST s (Vector Word8) #

basicUnsafeThaw :: Vector Word8 -> ST s (Mutable Vector s Word8) #

basicLength :: Vector Word8 -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Word8 -> Vector Word8 #

basicUnsafeIndexM :: Vector Word8 -> Int -> Box Word8 #

basicUnsafeCopy :: Mutable Vector s Word8 -> Vector Word8 -> ST s () #

elemseq :: Vector Word8 -> Word8 -> b -> b #

Vector Vector () |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s () -> ST s (Vector ()) #

basicUnsafeThaw :: Vector () -> ST s (Mutable Vector s ()) #

basicLength :: Vector () -> Int #

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

basicUnsafeIndexM :: Vector () -> Int -> Box () #

basicUnsafeCopy :: Mutable Vector s () -> Vector () -> ST s () #

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

Vector Vector Bool |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Bool -> ST s (Vector Bool) #

basicUnsafeThaw :: Vector Bool -> ST s (Mutable Vector s Bool) #

basicLength :: Vector Bool -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Bool -> Vector Bool #

basicUnsafeIndexM :: Vector Bool -> Int -> Box Bool #

basicUnsafeCopy :: Mutable Vector s Bool -> Vector Bool -> ST s () #

elemseq :: Vector Bool -> Bool -> b -> b #

Vector Vector Char |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Char -> ST s (Vector Char) #

basicUnsafeThaw :: Vector Char -> ST s (Mutable Vector s Char) #

basicLength :: Vector Char -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Char -> Vector Char #

basicUnsafeIndexM :: Vector Char -> Int -> Box Char #

basicUnsafeCopy :: Mutable Vector s Char -> Vector Char -> ST s () #

elemseq :: Vector Char -> Char -> b -> b #

Vector Vector Double |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Double -> ST s (Vector Double) #

basicUnsafeThaw :: Vector Double -> ST s (Mutable Vector s Double) #

basicLength :: Vector Double -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Double -> Vector Double #

basicUnsafeIndexM :: Vector Double -> Int -> Box Double #

basicUnsafeCopy :: Mutable Vector s Double -> Vector Double -> ST s () #

elemseq :: Vector Double -> Double -> b -> b #

Vector Vector Float |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Float -> ST s (Vector Float) #

basicUnsafeThaw :: Vector Float -> ST s (Mutable Vector s Float) #

basicLength :: Vector Float -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Float -> Vector Float #

basicUnsafeIndexM :: Vector Float -> Int -> Box Float #

basicUnsafeCopy :: Mutable Vector s Float -> Vector Float -> ST s () #

elemseq :: Vector Float -> Float -> b -> b #

Vector Vector Int |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Int -> ST s (Vector Int) #

basicUnsafeThaw :: Vector Int -> ST s (Mutable Vector s Int) #

basicLength :: Vector Int -> Int #

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

basicUnsafeIndexM :: Vector Int -> Int -> Box Int #

basicUnsafeCopy :: Mutable Vector s Int -> Vector Int -> ST s () #

elemseq :: Vector Int -> Int -> b -> b #

Vector Vector Word |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s Word -> ST s (Vector Word) #

basicUnsafeThaw :: Vector Word -> ST s (Mutable Vector s Word) #

basicLength :: Vector Word -> Int #

basicUnsafeSlice :: Int -> Int -> Vector Word -> Vector Word #

basicUnsafeIndexM :: Vector Word -> Int -> Box Word #

basicUnsafeCopy :: Mutable Vector s Word -> Vector Word -> ST s () #

elemseq :: Vector Word -> Word -> b -> b #

Unbox a => Vector Vector (Complex a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Complex a) -> ST s (Vector (Complex a)) #

basicUnsafeThaw :: Vector (Complex a) -> ST s (Mutable Vector s (Complex a)) #

basicLength :: Vector (Complex a) -> Int #

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

basicUnsafeIndexM :: Vector (Complex a) -> Int -> Box (Complex a) #

basicUnsafeCopy :: Mutable Vector s (Complex a) -> Vector (Complex a) -> ST s () #

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

Unbox a => Vector Vector (Identity a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Identity a) -> ST s (Vector (Identity a)) #

basicUnsafeThaw :: Vector (Identity a) -> ST s (Mutable Vector s (Identity a)) #

basicLength :: Vector (Identity a) -> Int #

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

basicUnsafeIndexM :: Vector (Identity a) -> Int -> Box (Identity a) #

basicUnsafeCopy :: Mutable Vector s (Identity a) -> Vector (Identity a) -> ST s () #

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

Unbox a => Vector Vector (Down a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Down a) -> ST s (Vector (Down a)) #

basicUnsafeThaw :: Vector (Down a) -> ST s (Mutable Vector s (Down a)) #

basicLength :: Vector (Down a) -> Int #

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

basicUnsafeIndexM :: Vector (Down a) -> Int -> Box (Down a) #

basicUnsafeCopy :: Mutable Vector s (Down a) -> Vector (Down a) -> ST s () #

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

Unbox a => Vector Vector (First a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (First a) -> ST s (Vector (First a)) #

basicUnsafeThaw :: Vector (First a) -> ST s (Mutable Vector s (First a)) #

basicLength :: Vector (First a) -> Int #

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

basicUnsafeIndexM :: Vector (First a) -> Int -> Box (First a) #

basicUnsafeCopy :: Mutable Vector s (First a) -> Vector (First a) -> ST s () #

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

Unbox a => Vector Vector (Last a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Last a) -> ST s (Vector (Last a)) #

basicUnsafeThaw :: Vector (Last a) -> ST s (Mutable Vector s (Last a)) #

basicLength :: Vector (Last a) -> Int #

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

basicUnsafeIndexM :: Vector (Last a) -> Int -> Box (Last a) #

basicUnsafeCopy :: Mutable Vector s (Last a) -> Vector (Last a) -> ST s () #

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

Unbox a => Vector Vector (Max a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Max a) -> ST s (Vector (Max a)) #

basicUnsafeThaw :: Vector (Max a) -> ST s (Mutable Vector s (Max a)) #

basicLength :: Vector (Max a) -> Int #

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

basicUnsafeIndexM :: Vector (Max a) -> Int -> Box (Max a) #

basicUnsafeCopy :: Mutable Vector s (Max a) -> Vector (Max a) -> ST s () #

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

Unbox a => Vector Vector (Min a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Min a) -> ST s (Vector (Min a)) #

basicUnsafeThaw :: Vector (Min a) -> ST s (Mutable Vector s (Min a)) #

basicLength :: Vector (Min a) -> Int #

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

basicUnsafeIndexM :: Vector (Min a) -> Int -> Box (Min a) #

basicUnsafeCopy :: Mutable Vector s (Min a) -> Vector (Min a) -> ST s () #

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

Unbox a => Vector Vector (WrappedMonoid a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (WrappedMonoid a) -> ST s (Vector (WrappedMonoid a)) #

basicUnsafeThaw :: Vector (WrappedMonoid a) -> ST s (Mutable Vector s (WrappedMonoid a)) #

basicLength :: Vector (WrappedMonoid a) -> Int #

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

basicUnsafeIndexM :: Vector (WrappedMonoid a) -> Int -> Box (WrappedMonoid a) #

basicUnsafeCopy :: Mutable Vector s (WrappedMonoid a) -> Vector (WrappedMonoid a) -> ST s () #

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

Unbox a => Vector Vector (Dual a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Dual a) -> ST s (Vector (Dual a)) #

basicUnsafeThaw :: Vector (Dual a) -> ST s (Mutable Vector s (Dual a)) #

basicLength :: Vector (Dual a) -> Int #

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

basicUnsafeIndexM :: Vector (Dual a) -> Int -> Box (Dual a) #

basicUnsafeCopy :: Mutable Vector s (Dual a) -> Vector (Dual a) -> ST s () #

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

Unbox a => Vector Vector (Product a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Product a) -> ST s (Vector (Product a)) #

basicUnsafeThaw :: Vector (Product a) -> ST s (Mutable Vector s (Product a)) #

basicLength :: Vector (Product a) -> Int #

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

basicUnsafeIndexM :: Vector (Product a) -> Int -> Box (Product a) #

basicUnsafeCopy :: Mutable Vector s (Product a) -> Vector (Product a) -> ST s () #

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

Unbox a => Vector Vector (Sum a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Sum a) -> ST s (Vector (Sum a)) #

basicUnsafeThaw :: Vector (Sum a) -> ST s (Mutable Vector s (Sum a)) #

basicLength :: Vector (Sum a) -> Int #

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

basicUnsafeIndexM :: Vector (Sum a) -> Int -> Box (Sum a) #

basicUnsafeCopy :: Mutable Vector s (Sum a) -> Vector (Sum a) -> ST s () #

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

Prim a => Vector Vector (UnboxViaPrim a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (UnboxViaPrim a) -> ST s (Vector (UnboxViaPrim a)) #

basicUnsafeThaw :: Vector (UnboxViaPrim a) -> ST s (Mutable Vector s (UnboxViaPrim a)) #

basicLength :: Vector (UnboxViaPrim a) -> Int #

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

basicUnsafeIndexM :: Vector (UnboxViaPrim a) -> Int -> Box (UnboxViaPrim a) #

basicUnsafeCopy :: Mutable Vector s (UnboxViaPrim a) -> Vector (UnboxViaPrim a) -> ST s () #

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

(Unbox a, Unbox b) => Vector Vector (Arg a b) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Arg a b) -> ST s (Vector (Arg a b)) #

basicUnsafeThaw :: Vector (Arg a b) -> ST s (Mutable Vector s (Arg a b)) #

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

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

basicUnsafeIndexM :: Vector (Arg a b) -> Int -> Box (Arg a b) #

basicUnsafeCopy :: Mutable Vector s (Arg a b) -> Vector (Arg a b) -> ST s () #

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

(IsoUnbox a b, Unbox b) => Vector Vector (As a b) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (As a b) -> ST s (Vector (As a b)) #

basicUnsafeThaw :: Vector (As a b) -> ST s (Mutable Vector s (As a b)) #

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

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

basicUnsafeIndexM :: Vector (As a b) -> Int -> Box (As a b) #

basicUnsafeCopy :: Mutable Vector s (As a b) -> Vector (As a b) -> ST s () #

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

(Unbox a, Unbox b) => Vector Vector (a, b) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (a, b) -> ST s (Vector (a, b)) #

basicUnsafeThaw :: Vector (a, b) -> ST s (Mutable Vector s (a, b)) #

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

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

basicUnsafeIndexM :: Vector (a, b) -> Int -> Box (a, b) #

basicUnsafeCopy :: Mutable Vector s (a, b) -> Vector (a, b) -> ST s () #

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

Unbox a => Vector Vector (Const a b) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Const a b) -> ST s (Vector (Const a b)) #

basicUnsafeThaw :: Vector (Const a b) -> ST s (Mutable Vector s (Const a b)) #

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

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

basicUnsafeIndexM :: Vector (Const a b) -> Int -> Box (Const a b) #

basicUnsafeCopy :: Mutable Vector s (Const a b) -> Vector (Const a b) -> ST s () #

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

Unbox (f a) => Vector Vector (Alt f a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Alt f a) -> ST s (Vector (Alt f a)) #

basicUnsafeThaw :: Vector (Alt f a) -> ST s (Mutable Vector s (Alt f a)) #

basicLength :: Vector (Alt f a) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (Alt f a) -> Vector (Alt f a) #

basicUnsafeIndexM :: Vector (Alt f a) -> Int -> Box (Alt f a) #

basicUnsafeCopy :: Mutable Vector s (Alt f a) -> Vector (Alt f a) -> ST s () #

elemseq :: Vector (Alt f a) -> Alt f a -> b -> b #

(Unbox a, Unbox b, Unbox c) => Vector Vector (a, b, c) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (a, b, c) -> ST s (Vector (a, b, c)) #

basicUnsafeThaw :: Vector (a, b, c) -> ST s (Mutable Vector s (a, b, c)) #

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

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

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

basicUnsafeCopy :: Mutable Vector s (a, b, c) -> Vector (a, b, c) -> ST s () #

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 :: Mutable Vector s (a, b, c, d) -> ST s (Vector (a, b, c, d)) #

basicUnsafeThaw :: Vector (a, b, c, d) -> ST s (Mutable Vector s (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 :: Vector (a, b, c, d) -> Int -> Box (a, b, c, d) #

basicUnsafeCopy :: Mutable Vector s (a, b, c, d) -> Vector (a, b, c, d) -> ST s () #

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

Unbox (f (g a)) => Vector Vector (Compose f g a) |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

basicUnsafeFreeze :: Mutable Vector s (Compose f g a) -> ST s (Vector (Compose f g a)) #

basicUnsafeThaw :: Vector (Compose f g a) -> ST s (Mutable Vector s (Compose f g a)) #

basicLength :: Vector (Compose f g a) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (Compose f g a) -> Vector (Compose f g a) #

basicUnsafeIndexM :: Vector (Compose f g a) -> Int -> Box (Compose f g a) #

basicUnsafeCopy :: Mutable Vector s (Compose f g a) -> Vector (Compose f g a) -> ST s () #

elemseq :: Vector (Compose f g a) -> Compose f g a -> b -> b #

(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 :: Mutable Vector s (a, b, c, d, e) -> ST s (Vector (a, b, c, d, e)) #

basicUnsafeThaw :: Vector (a, b, c, d, e) -> ST s (Mutable Vector s (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 :: Vector (a, b, c, d, e) -> Int -> Box (a, b, c, d, e) #

basicUnsafeCopy :: Mutable Vector s (a, b, c, d, e) -> Vector (a, b, c, d, e) -> ST s () #

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 :: Mutable Vector s (a, b, c, d, e, f) -> ST s (Vector (a, b, c, d, e, f)) #

basicUnsafeThaw :: Vector (a, b, c, d, e, f) -> ST s (Mutable Vector s (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 :: Vector (a, b, c, d, e, f) -> Int -> Box (a, b, c, d, e, f) #

basicUnsafeCopy :: Mutable Vector s (a, b, c, d, e, f) -> Vector (a, b, c, d, e, f) -> ST s () #

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) Unsafely 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. Note that this is a very dangerous function and generally it's only safe to read from the resulting vector. In this case, the immutable vector could be used safely as well.

Problems with mutation happen because GHC has a lot of freedom to introduce sharing. As a result mutable vectors produced by `unsafeThaw` may or may not share the same underlying buffer. For example:

    foo = do
      let vec = V.generate 10 id
      mvec <- V.unsafeThaw vec
      do_something mvec

Here GHC could lift `vec` outside of foo which means that all calls to `do_something` will use same buffer with possibly disastrous results. Whether such aliasing happens or not depends on the program in question, optimization levels, and GHC flags.

All in all, attempts to modify a vector produced by `unsafeThaw` fall out of domain of software engineering and into realm of black magic, dark rituals, and unspeakable horrors. The only advice that could be given is: "Don't attempt to mutate a vector produced by `unsafeThaw` unless you know how to prevent GHC from aliasing buffers accidentally. We don't."

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.