PrimitiveArray-0.5.2.0: Efficient multidimensional arrays

Safe HaskellNone

Data.PrimitiveArray

Description

Vastly extended primitive arrays. Some basic ideas are now modeled after the vector package, especially the monadic mutable / pure immutable array system.

NOTE all operations in MPrimArrayOps and PrimArrayOps are highly unsafe. No bounds-checking is performed at all.

Synopsis

Documentation

data family MutArr m arr :: *Source

Mutable version of an array.

class (Shape sh, ExtShape sh) => MPrimArrayOps arr sh elm whereSource

The core set of operations for monadic arrays.

Methods

boundsM :: MutArr m (arr sh elm) -> (sh, sh)Source

Return the bounds of the array. All bounds are inclusive, as in [lb..ub]

fromListM :: PrimMonad m => sh -> sh -> [elm] -> m (MutArr m (arr sh elm))Source

Given lower and upper bounds and a list of all elements, produce a mutable array.

newM :: PrimMonad m => sh -> sh -> m (MutArr m (arr sh elm))Source

Creates a new array with the given bounds with each element within the array being in an undefined state.

newWithM :: PrimMonad m => sh -> sh -> elm -> m (MutArr m (arr sh elm))Source

Creates a new array with all elements being equal to elm.

readM :: PrimMonad m => MutArr m (arr sh elm) -> sh -> m elmSource

Reads a single element in the array.

writeM :: PrimMonad m => MutArr m (arr sh elm) -> sh -> elm -> m ()Source

Writes a single element in the array.

Instances

(Shape sh, ExtShape sh, Unbox elm) => MPrimArrayOps Boxed sh elm 
(Shape sh, ExtShape sh, Unbox elm) => MPrimArrayOps Unboxed sh elm 

class (Shape sh, ExtShape sh) => PrimArrayOps arr sh elm whereSource

The core set of functions on immutable arrays.

Methods

bounds :: arr sh elm -> (sh, sh)Source

Returns the bounds of an immutable array, again inclusive bounds: [lb..ub] .

freeze :: PrimMonad m => MutArr m (arr sh elm) -> m (arr sh elm)Source

Freezes a mutable array an returns its immutable version. This operation is O(1) and both arrays share the same memory. Do not use the mutable array afterwards.

index :: arr sh elm -> sh -> elmSource

Extract a single element from the array. Generally unsafe as not bounds-checking is performed.

Instances

(Shape sh, ExtShape sh, Unbox elm) => PrimArrayOps Boxed sh elm 
(Shape sh, ExtShape sh, Unbox elm) => PrimArrayOps Unboxed sh elm 

class (Shape sh, ExtShape sh) => PrimArrayMap arr sh e e' whereSource

Methods

map :: (e -> e') -> arr sh e -> arr sh e'Source

Map a function over each element, keeping the shape intact.

Instances

(Shape sh, ExtShape sh) => PrimArrayMap Boxed sh e e' 
(Shape sh, ExtShape sh, Unbox e, Unbox e') => PrimArrayMap Unboxed sh e e' 

(!) :: PrimArrayOps arr sh elm => arr sh elm -> sh -> elmSource

Infix index operator. Performs minimal bounds-checking using assert in non-optimized code.

inBoundsM :: (Monad m, MPrimArrayOps arr sh elm) => MutArr m (arr sh elm) -> sh -> BoolSource

Returns true if the index is valid for the array.

sliceEq :: (Eq elm, PrimArrayOps arr sh elm) => arr sh elm -> sh -> arr sh elm -> sh -> sh -> BoolSource

Given two arrays with the same dimensionality, their respective starting index, and how many steps to go in each dimension (in terms of a dimension again), determine if the multidimensional slices have the same value at all positions

TODO specialize for DIM1 (and maybe higher dim's) to use memcmp

fromAssocsM :: (PrimMonad m, MPrimArrayOps arr sh elm) => sh -> sh -> elm -> [(sh, elm)] -> m (MutArr m (arr sh elm))Source

Construct a mutable primitive array from a lower and an upper bound, a default element, and a list of associations.

assocs :: PrimArrayOps arr sh elm => arr sh elm -> [(sh, elm)]Source

Return all associations from an array.

fromList :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => sh -> sh -> [elm] -> arr sh elmSource

Creates an immutable array from lower and upper bounds and a complete list of elements.

fromAssocs :: (PrimArrayOps arr sh elm, MPrimArrayOps arr sh elm) => sh -> sh -> elm -> [(sh, elm)] -> arr sh elmSource

Creates an immutable array from lower and upper bounds, a default element, and a list of associations.

inBounds :: PrimArrayOps arr sh elm => arr sh elm -> sh -> BoolSource

Determines if an index is valid for a given immutable array.

toList :: PrimArrayOps arr sh elm => arr sh elm -> [elm]Source

Returns all elements of an immutable array as a list.