repa-array-4.0.0.2: Bulk array representations and operators.

Safe HaskellNone
LanguageHaskell98

Data.Repa.Array.Material

Contents

Synopsis

Boxed arrays

data B Source

Layout an array as flat vector of boxed elements.

UNSAFE: Indexing into raw material arrays is not bounds checked. You may want to wrap this with a Checked layout as well.

Constructors

Boxed 

Fields

boxedLength :: !Int
 

Instances

Eq B 
Show B 
Layout B

Boxed arrays.

Bulk B a

Boxed arrays.

Windowable B a

Boxed windows.

Target B a

Boxed buffers.

Eq (Name B) 
Show (Name B) 
Show a => Show (Array B a) 
Unpack (Buffer s B a) (MVector s a) 
data Name B = B 
type Index B = Int 
data Array B = BArray !(Vector a) 
data Buffer s B a = BBuffer !(MVector s a) 

fromBoxed :: Vector a -> Array B a Source

O(1). Wrap a boxed vector as an array.

toBoxed :: Array B a -> Vector a Source

O(1). Unwrap a boxed vector from an array.

decimate :: (a -> a -> Bool) -> Array B a -> Array B a Source

Scan through an array from front to back. For pairs of successive elements, drop the second one when the given predicate returns true.

This function can be used to remove duplicates from a sorted array.

TODO: generalise to other array types.

Unboxed arrays

data U Source

Layout an array as a flat vector of unboxed elements.

This is the most efficient representation for numerical data.

The implementation uses Data.Vector.Unboxed which picks an efficient, specialised representation for every element type. In particular, unboxed vectors of pairs are represented as pairs of unboxed vectors.

UNSAFE: Indexing into raw material arrays is not bounds checked. You may want to wrap this with a Checked layout as well.

Constructors

Unboxed 

Fields

unboxedLength :: !Int
 

Instances

Eq U 
Show U 
Layout U

Unboxed arrays.

Unbox a => Bulk U a

Unboxed arrays.

Unbox a => Windowable U a

Windowing Unboxed arrays.

Unbox a => Target U a

Unboxed buffers.

Eq (Name U) 
Show (Name U) 
(Show a, Unbox a) => Show (Array U a) 
Unpack (Array U a) (Vector a) 
Unpack (Buffer s U a) (MVector s a) 
data Name U = U 
type Index U = Int 
data Array U = UArray !(Vector a) 
data Buffer s U a = UBuffer !(MVector s a) 

class (Vector Vector a, MVector MVector a) => Unbox a

Instances

Unbox Bool 
Unbox Char 
Unbox Double 
Unbox Float 
Unbox Int 
Unbox Int8 
Unbox Int16 
Unbox Int32 
Unbox Int64 
Unbox Word 
Unbox Word8 
Unbox Word16 
Unbox Word32 
Unbox Word64 
Unbox () 
(RealFloat a, Unbox a) => Unbox (Complex a) 
(Unbox a, Unbox b) => Unbox (a, b) 
(Unbox a, Unbox b, Unbox c) => Unbox (a, b, c) 
(Unbox a, Unbox b, Unbox c, Unbox d) => Unbox (a, b, c, d) 
(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Unbox (a, b, c, d, e) 
(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Unbox (a, b, c, d, e, f) 

fromUnboxed :: Unbox a => Vector a -> Array U a Source

O(1). Wrap an unboxed vector as an array.

toUnboxed :: Unbox a => Array U a -> Vector a Source

O(1). Unwrap an unboxed vector from an array.

Foreign arrays

data F Source

Layout for Foreign arrays.

UNSAFE: Indexing into raw material arrays is not bounds checked. You may want to wrap this with a Checked layout as well.

Constructors

Foreign 

Fields

foreignLength :: Int
 

Instances

Eq F 
Show F 
Layout F

Foreign arrays.

Storable a => Bulk F a

Foreign arrays.

Storable a => Windowable F a

Windowing Foreign arrays.

Storable a => Target F a

Foreign buffers

Eq (Name F) 
Show (Name F) 
(Eq a, Storable a) => Eq (Array F a) 
(Storable a, Show a) => Show (Array F a) 
Unpack (Array F a) (Vector a) 
Unpack (Buffer s F a) (MVector s a)

Unpack Foreign buffers

data Name F = F 
type Index F = Int 
data Array F = FArray !(Vector a) 
data Buffer s F a = FBuffer !(MVector s a) 

fromForeignPtr :: Storable a => Int -> ForeignPtr a -> Array F a Source

O(1). Wrap a ForeignPtr as an array.

fromByteString :: ByteString -> Array F Word8 Source

O(1). Convert a ByteString to an foreign Array.

toByteString :: Array F Word8 -> ByteString Source

O(1). Convert a foreign Vector to a ByteString.

fromStorableVector :: Vector a -> Array F a Source

O(1). Convert a storable Vector to a foreign Array

toStorableVector :: Array F a -> Vector a Source

O(1). Convert a foreign array to a storable Vector.

Nested arrays

data N Source

Nested array represented as a flat array of elements, and a segment descriptor that describes how the elements are partitioned into the sub-arrays. Using this representation for multidimentional arrays is significantly more efficient than using a boxed array of arrays, as there is no need to allocate the sub-arrays individually in the heap.

With a nested type like: Array N (Array N (Array U Int)), the concrete representation consists of five flat unboxed vectors: two for each of the segment descriptors associated with each level of nesting, and one unboxed vector to hold all the integer elements.

UNSAFE: Indexing into raw material arrays is not bounds checked. You may want to wrap this with a Checked layout as well.

Constructors

Nested 

Fields

nestedLength :: !Int
 

Instances

Eq N 
Show N 
Layout N

Nested arrays.

(BulkI l a, Windowable l a) => Bulk N (Array l a)

Nested arrays.

(BulkI l a, Windowable l a) => Windowable N (Array l a)

Windowing Nested arrays.

Eq (Name N) 
Show (Name N) 
Show (Array l a) => Show (Array N (Array l a)) 
data Name N = N 
type Index N = Int 
data Array N (Array l a) = NArray !(Vector Int) !(Vector Int) !(Array l a) 

Conversion

fromLists :: TargetI l a => Name l -> [[a]] -> Array N (Array l a) Source

O(size src) Convert some lists to a nested array.

fromListss :: TargetI l a => Name l -> [[[a]]] -> Array N (Array N (Array l a)) Source

O(size src) Convert a triply nested list to a triply nested array.

Mapping

mapElems :: (Array l1 a -> Array l2 b) -> Array N (Array l1 a) -> Array N (Array l2 b) Source

Apply a function to all the elements of a doubly nested array, preserving the nesting structure.

Slicing

slices Source

Arguments

:: Array U Int

Segment starting positions.

-> Array U Int

Segment lengths.

-> Array l a

Array elements.

-> Array N (Array l a) 

O(1). Produce a nested array by taking slices from some array of elements.

This is a constant time operation, as the representation for nested vectors just wraps the starts, lengths and elements vectors.

Concatenation

concats :: Array N (Array N (Array l a)) -> Array N (Array l a) Source

Segmented concatenation. Concatenate triply nested vector, producing a doubly nested vector.

  • Unlike the plain concat function, this operation is performed entirely on the segment descriptors of the nested arrays, and does not require the inner array elements to be copied.
> import Data.Repa.Nice
> nice $ concats $ fromListss U [["red", "green", "blue"], ["grey", "white"], [], ["black"]]
["red","green","blue","grey","white","black"]

Splitting

segment Source

Arguments

:: (BulkI l a, Unbox a) 
=> (a -> Bool)

Detect the start of a segment.

-> (a -> Bool)

Detect the end of a segment.

-> Array l a

Vector to segment.

-> Array N (Array l a) 

O(len src). Given predicates which detect the start and end of a segment, split an vector into the indicated segments.

segmentOn Source

Arguments

:: (BulkI l a, Eq a, Unbox a) 
=> (a -> Bool)

Detect the end of a segment.

-> Array l a

Vector to segment.

-> Array N (Array l a) 

O(len src). Given a terminating value, split an vector into segments.

The result segments do not include the terminator.

> import Data.Repa.Nice
> nice $ segmentOn (== ' ') (fromList U "fresh   fried fish  ") 
["fresh "," "," ","fried ","fish "," "]

dice Source

Arguments

:: (BulkI l a, Windowable l a, Unbox a) 
=> (a -> Bool)

Detect the start of an inner segment.

-> (a -> Bool)

Detect the end of an inner segment.

-> (a -> Bool)

Detect the start of an outer segment.

-> (a -> Bool)

Detect the end of an outer segment.

-> Array l a

Array to dice.

-> Array N (Array N (Array l a)) 

O(len src). Like segment, but cut the source array twice.

diceSep Source

Arguments

:: (BulkI l a, Windowable l a, Unbox a, Eq a) 
=> a

Terminating element for inner segments.

-> a

Terminating element for outer segments.

-> Array l a

Vector to dice.

-> Array N (Array N (Array l a)) 

O(len src). Given field and row terminating values, split an array into rows and fields.

Trimming

trims :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a) Source

For each segment of a nested vector, trim elements off the start and end of the segment that match the given predicate.

trimEnds :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a) Source

For each segment of a nested vector, trim elements off the end of the segment that match the given predicate.

trimStarts :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a) Source

For each segment of a nested vector, trim elements off the start of the segment that match the given predicate.

Transpose

ragspose3 :: Array N (Array N (Array l a)) -> Array N (Array N (Array l a)) Source

Ragged transpose of a triply nested array.

  • This operation is performed entirely on the segment descriptors of the nested arrays, and does not require the inner array elements to be copied.