dph-prim-seq-0.6.1.1: Data Parallel Haskell segmented arrays. (sequential implementation)

Safe HaskellSafe-Infered

Data.Array.Parallel.Unlifted.Sequential.USegd

Contents

Description

Segment Descriptors.

See Data.Array.Parallel.Unlifted for how this works.

Synopsis

Types

data USegd Source

Segment descriptor.

Constructors

USegd 

Fields

usegd_lengths :: !(Vector Int)

Length of each segment.

usegd_indices :: !(Vector Int)

Starting index of each segment.

usegd_elements :: !Int

Total number of elements in the flat array.

Constructors

mkUSegdSource

Arguments

:: Vector Int

Length of each segment.

-> Vector Int

Starting index of each segment.

-> Int

Total number of elements in the flat array.

-> USegd 

O(1). Construct a new segment descriptor.

valid :: USegd -> BoolSource

O(1). Check the internal consistency of a segment descriptor.

As the indices and elemens field can be generated based on the segment lengths, we check the consistency by rebuilding these fields and comparing the rebuilt ones against the originals.

empty :: USegdSource

O(1). Construct an empty segment descriptor, with no elements or segments.

singleton :: Int -> USegdSource

O(1). Construct a singleton segment descriptor. The single segment covers the given number of elements.

fromLengths :: Vector Int -> USegdSource

O(segs). Convert an array of segment lengths into a segment descriptor.

The array contains the length of each segment, and we compute the indices from that.

Projections

length :: USegd -> IntSource

O(1). Yield the overall number of segments.

takeLengths :: USegd -> Vector IntSource

O(1). Yield the lengths of the individual segments.

takeIndices :: USegd -> Vector IntSource

O(1). Yield the segment indices of a segment descriptor.

takeElements :: USegd -> IntSource

O(1). Yield the number of data elements.

getSeg :: USegd -> Int -> (Int, Int)Source

O(1). Get the length and segment index of a segment

Operations

append :: USegd -> USegd -> USegdSource

O(segs). Produce a segment descriptor that describes the result of appending two arrays.

sliceSource

Arguments

:: USegd

Source segment descriptor.

-> Int

Index of first segment.

-> Int

Number of segments to slice out.

-> USegd 

O(segs) Extract a slice of a segment descriptor, avoiding copying where possible.

We can share the segment lengths with the original segment descriptor, but still need to recompute the starting indices of each. Hence runtime is O(segs) in the number of segments sliced out.

extractSource

Arguments

:: USegd

Source segment desciptor.

-> Int

Undex of the first segment.

-> Int

Number of segments to extract out.

-> USegd 

Extract a slice of a segment descriptor, copying everything.

In contrast to slice, this function copies the array of segment lengths as well as recomputing the starting indices of each.