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

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) Source #

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) Source #

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

Assumed complexity: O(1)

Yield the length of the vector.

basicUnsafeSlice Source #

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

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 () Source #

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

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) Source #

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

basicLength :: Vector a -> Int Source #

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

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

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

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

Prim a => Vector Vector a |

Instance details

Defined in Data.Vector.Primitive

Methods

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

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

basicLength :: Vector a -> Int Source #

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

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

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

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

Storable a => Vector Vector a |

Instance details

Defined in Data.Vector.Storable

Methods

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

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

basicLength :: Vector a -> Int Source #

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

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

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

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

Vector Vector All |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector All -> Int Source #

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

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

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

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

Vector Vector Any |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Any -> Int Source #

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

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

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

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

Vector Vector Int16 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Int16 -> Int Source #

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

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

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

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

Vector Vector Int32 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Int32 -> Int Source #

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

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

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

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

Vector Vector Int64 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Int64 -> Int Source #

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

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

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

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

Vector Vector Int8 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Int8 -> Int Source #

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

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

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

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

Vector Vector Word16 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Word16 -> Int Source #

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

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

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

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

Vector Vector Word32 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Word32 -> Int Source #

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

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

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

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

Vector Vector Word64 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Word64 -> Int Source #

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

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

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

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

Vector Vector Word8 |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Word8 -> Int Source #

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

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

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

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

Vector Vector () |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector () -> Int Source #

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

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

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

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

Vector Vector Bool |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Bool -> Int Source #

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

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

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

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

Vector Vector Char |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Char -> Int Source #

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

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

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

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

Vector Vector Double |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Double -> Int Source #

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

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

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

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

Vector Vector Float |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Float -> Int Source #

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

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

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

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

Vector Vector Int |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Int -> Int Source #

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

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

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

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

Vector Vector Word |

Instance details

Defined in Data.Vector.Unboxed.Base

Methods

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

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

basicLength :: Vector Word -> Int Source #

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

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

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

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

(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)) Source #

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

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

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

basicUnsafeIndexM :: Vector (a, b, c, d, e, f) -> Int -> Box (a, b, c, d, e, f) Source #

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

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

# Accessors

## Indexing

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

O(1) Unsafe indexing without bounds checking.

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

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

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

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

## Monadic indexing

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

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

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

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

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

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

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

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

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

Same as (`//`), but without bounds checking.

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

Same as `update`, but without bounds checking.

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

Same as `update_`, but without bounds checking.

## Accumulations

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

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

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

Same as `accumulate_`, but without bounds checking.

## Permutations

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

Same as `backpermute`, but without bounds checking.

# Conversions

## Mutable vectors

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

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) Source #

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 () Source #

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