fixed-vector-1.2.1.0: Generic vectors with statically known size.
Safe HaskellNone
LanguageHaskell2010

Data.Vector.Fixed.Mutable

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

type Arity n = (ArityPeano (Peano n), KnownNat n, Peano (n + 1) ~ 'S (Peano n)) Source #

Type class for type level number for which we can defined operations over N-ary functions.

arity :: KnownNat n => proxy n -> Int Source #

Arity of function.

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

Mutable counterpart of fixed-length vector.

Instances

Instances details
type Mutable (Vec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Boxed

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

Defined in Data.Vector.Fixed.Primitive

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

Defined in Data.Vector.Fixed.Storable

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

Defined in Data.Vector.Fixed.Unboxed

type Mutable (Vec n) = MVec n

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

Dimension for mutable vector.

Instances

Instances details
type DimM (MVec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Boxed

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

Defined in Data.Vector.Fixed.Primitive

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

Defined in Data.Vector.Fixed.Storable

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

Defined in Data.Vector.Fixed.Unboxed

type DimM (MVec n) = n

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

Type class for mutable vectors.

Methods

copy Source #

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.

move Source #

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

Instances details
Arity n => MVector (MVec n) a Source # 
Instance details

Defined in Data.Vector.Fixed.Boxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Primitive

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Storable

Methods

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) All Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Any Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Double Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Float Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Word32 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Word16 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Arity n => MVector (MVec n) Word8 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 #

Unbox n a => MVector (MVec n) (Product a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Unbox n a => MVector (MVec n) (Sum a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Unbox n a => MVector (MVec n) (Dual a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Unbox n a => MVector (MVec n) (Down a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

Unbox n a => MVector (MVec n) (Identity a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

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

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

Defined in Data.Vector.Fixed.Unboxed

Methods

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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 #

Unbox n a => MVector (MVec n) (Const a b) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

unsafeWrite :: PrimMonad m => MVec n (PrimState m) (Const a b) -> Int -> Const 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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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.

Examples:

>>> import Control.Monad.ST (runST)
>>> import Data.Vector.Fixed (mk3)
>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> import qualified Data.Vector.Fixed.Mutable as M
>>> let x = runST (do { v <- M.replicate 100; v' <- clone v; M.write v' 0 2; M.unsafeFreeze v' }) :: Vec3 Int
>>> x
fromList [2,100,100]

Creation

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

Create new vector with all elements set to given value.

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

Create new vector with all elements are generated by provided monadic action.

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

Create new vector with using function from index to value.

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

Create new vector with using monadic function from index to value.

Loops

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

Loop which calls function for each index

Immutable vectors

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

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 #

O(1) Unsafely convert immutable vector to mutable 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 = F.generate 10 id
  mvec <- M.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."

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

Get element at specified index without bounds check.

Instances

Instances details
Arity n => IVector (Vec n) a Source # 
Instance details

Defined in Data.Vector.Fixed.Boxed

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 # 
Instance details

Defined in Data.Vector.Fixed.Primitive

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 # 
Instance details

Defined in Data.Vector.Fixed.Storable

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) All Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Any Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Double Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Float Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Char Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Word64 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Word32 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Word16 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Word8 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Word Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Int64 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Int32 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Int16 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Int8 Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Int Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) Bool Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Arity n => IVector (Vec n) () Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

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 #

Unbox n a => IVector (Vec n) (Product a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

Unbox n a => IVector (Vec n) (Sum a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

Unbox n a => IVector (Vec n) (Dual a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

Unbox n a => IVector (Vec n) (Down a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

Unbox n a => IVector (Vec n) (Identity a) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

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

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

Defined in Data.Vector.Fixed.Unboxed

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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

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 #

Unbox n a => IVector (Vec n) (Const a b) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

Methods

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

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

unsafeIndex :: Vec n (Const a b) -> Int -> Const 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 # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

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 #

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 (Peano (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 (Peano (Dim v)) a b -> b Source #

Generic inspect implementation for array-based vectors.