dense-0.1.0.1: Mutable and immutable dense multidimensional arrays
Copyright(c) Christopher Chalmers
LicenseBSD3
MaintainerChristopher Chalmers
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Dense.Mutable

Description

This module provides generic functions over mutable multidimensional arrays.

Synopsis

Mutable array

data MArray v l s a Source #

A mutable array with a shape.

Constructors

MArray !(Layout l) !(v s a) 

Instances

Instances details
Shape f => HasLayout f (MArray v f s a) Source # 
Instance details

Defined in Data.Dense.Mutable

Methods

layout :: Lens' (MArray v f s a) (Layout f) Source #

(MVector v a, f ~ V1) => MVector (MArray v f) a Source # 
Instance details

Defined in Data.Dense.Mutable

Methods

basicLength :: MArray v f s a -> Int #

basicUnsafeSlice :: Int -> Int -> MArray v f s a -> MArray v f s a #

basicOverlaps :: MArray v f s a -> MArray v f s a -> Bool #

basicUnsafeNew :: PrimMonad m => Int -> m (MArray v f (PrimState m) a) #

basicInitialize :: PrimMonad m => MArray v f (PrimState m) a -> m () #

basicUnsafeReplicate :: PrimMonad m => Int -> a -> m (MArray v f (PrimState m) a) #

basicUnsafeRead :: PrimMonad m => MArray v f (PrimState m) a -> Int -> m a #

basicUnsafeWrite :: PrimMonad m => MArray v f (PrimState m) a -> Int -> a -> m () #

basicClear :: PrimMonad m => MArray v f (PrimState m) a -> m () #

basicSet :: PrimMonad m => MArray v f (PrimState m) a -> a -> m () #

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

basicUnsafeMove :: PrimMonad m => MArray v f (PrimState m) a -> MArray v f (PrimState m) a -> m () #

basicUnsafeGrow :: PrimMonad m => MArray v f (PrimState m) a -> Int -> m (MArray v f (PrimState m) a) #

type UMArray = MArray MVector Source #

Unboxed mutable array.

type SMArray = MArray MVector Source #

Storable mutable array.

type BMArray = MArray MVector Source #

Boxed mutable array.

type PMArray = MArray MVector Source #

Primitive mutable array.

Lenses

mlayout :: (Shape f, Shape f') => Lens (MArray v f s a) (MArray v f' s a) (Layout f) (Layout f') Source #

Lens onto the shape of the vector. The total size of the layout _must_ remain the same or an error is thrown.

mvector :: (MVector v a, MVector w b) => IndexedLens (Layout f) (MArray v f s a) (MArray w f t b) (v s a) (w t b) Source #

Indexed lens over the underlying vector of an array. The index is the extent of the array. You must not change the length of the vector, otherwise an error will be thrown.

Creation

new :: (PrimMonad m, Shape f, MVector v a) => Layout f -> m (MArray v f (PrimState m) a) Source #

New mutable array with shape l.

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

New mutable array with shape l filled with element a.

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

New mutable array with shape l filled with result of monadic action a.

clone :: (PrimMonad m, MVector v a) => MArray v f (PrimState m) a -> m (MArray v f (PrimState m) a) Source #

Clone a mutable array, making a new, separate mutable array.

Standard operations

Indexing

read :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> m a Source #

Read a mutable array at element l.

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

Read a mutable array at element i by indexing the internal vector.

unsafeRead :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> m a Source #

read without bounds checking.

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

linearRead without bounds checking.

Writing

write :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> a -> m () Source #

Write a mutable array at element l.

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

Write a mutable array at element i by indexing the internal vector.

unsafeWrite :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> a -> m () Source #

write without bounds checking.

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

linearWrite without bounds checking.

Modifying

modify :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> (a -> a) -> m () Source #

Modify a mutable array at element l by applying a function.

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

Modify a mutable array at element i by applying a function.

unsafeModify :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> (a -> a) -> m () Source #

modify without bounds checking.

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

linearModify without bounds checking.

Swap

swap :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> f Int -> m () Source #

Swap two elements in a mutable array.

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

Swap two elements in a mutable array by indexing the internal vector.

unsafeSwap :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> f Int -> m () Source #

swap without bounds checking.

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

linearSwap without bounds checking.

Exchange

exchange :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> a -> m a Source #

Replace the element at the give position and return the old element.

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

Replace the element at the give position and return the old element.

unsafeExchange :: (PrimMonad m, Shape f, MVector v a) => MArray v f (PrimState m) a -> f Int -> a -> m a Source #

Replace the element at the give position and return the old element.

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

Replace the element at the give position and return the old element.

Misc

set :: (PrimMonad m, MVector v a) => MArray v f (PrimState m) a -> a -> m () Source #

Set all elements in a mutable array to a constant value.

clear :: (PrimMonad m, MVector v a) => MArray v f (PrimState m) a -> m () Source #

Clear the elements of a mutable array. This is usually a no-op for unboxed arrays.

copy :: (PrimMonad m, MVector v a) => MArray v f (PrimState m) a -> MArray v f (PrimState m) a -> m () Source #

Copy all elements from one array into another.