Safe Haskell | None |
---|---|
Language | Haskell98 |
- data B = Boxed {
- boxedLength :: !Int
- fromBoxed :: Vector a -> Array B a
- toBoxed :: Array B a -> Vector a
- decimate :: (a -> a -> Bool) -> Array B a -> Array B a
- data U = Unboxed {
- unboxedLength :: !Int
- class (Vector Vector a, MVector MVector a) => Unbox a
- fromUnboxed :: Unbox a => Vector a -> Array U a
- toUnboxed :: Unbox a => Array U a -> Vector a
- data F = Foreign {
- foreignLength :: Int
- fromForeignPtr :: Storable a => Int -> ForeignPtr a -> Array F a
- toForeignPtr :: Storable a => Array F a -> (Int, Int, ForeignPtr a)
- fromByteString :: ByteString -> Array F Word8
- toByteString :: Array F Word8 -> ByteString
- fromStorableVector :: Vector a -> Array F a
- toStorableVector :: Array F a -> Vector a
- data N = Nested {
- nestedLength :: !Int
- fromLists :: TargetI l a => Name l -> [[a]] -> Array N (Array l a)
- fromListss :: TargetI l a => Name l -> [[[a]]] -> Array N (Array N (Array l a))
- mapElems :: (Array l1 a -> Array l2 b) -> Array N (Array l1 a) -> Array N (Array l2 b)
- slices :: Array U Int -> Array U Int -> Array l a -> Array N (Array l a)
- concats :: Array N (Array N (Array l a)) -> Array N (Array l a)
- segment :: (BulkI l a, Unbox a) => (a -> Bool) -> (a -> Bool) -> Array l a -> Array N (Array l a)
- segmentOn :: (BulkI l a, Eq a, Unbox a) => (a -> Bool) -> Array l a -> Array N (Array l a)
- dice :: (BulkI l a, Windowable l a, Unbox a) => (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Array l a -> Array N (Array N (Array l a))
- diceSep :: (BulkI l a, Windowable l a, Unbox a, Eq a) => a -> a -> Array l a -> Array N (Array N (Array l a))
- trims :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a)
- trimEnds :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a)
- trimStarts :: BulkI l a => (a -> Bool) -> Array N (Array l a) -> Array N (Array l a)
- ragspose3 :: Array N (Array N (Array l a)) -> Array N (Array N (Array l a))
Boxed arrays
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.
Boxed | |
|
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) |
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
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.
Unboxed | |
|
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
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) |
Foreign arrays
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.
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.
toForeignPtr :: Storable a => Array F a -> (Int, Int, ForeignPtr a) Source
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
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.
Nested | |
|
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
:: 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
:: (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.
:: (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 "," "]
:: (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.
:: (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.