Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class PrimBytes t => PrimArray t a | a -> t where
- broadcast :: t -> a
- ix# :: Int# -> a -> t
- gen# :: CumulDims -> (s -> (#s, t#)) -> s -> (#s, a#)
- upd# :: CumulDims -> Int# -> t -> a -> a
- arrayContent# :: a -> (#t | (#CumulDims, Int#, ByteArray##)#)
- offsetElems :: a -> Int#
- uniqueOrCumulDims :: a -> Either t CumulDims
- fromElems :: CumulDims -> Int# -> ByteArray# -> a
- newtype CumulDims = CumulDims {
- unCumulDims :: [Word]
- cumulDims :: Dims (ns :: [k]) -> CumulDims
- cdTotalDim :: CumulDims -> Word
- cdTotalDim# :: CumulDims -> Int#
- cdIx :: CumulDims -> Idxs ns -> Int
- ixOff :: PrimArray t a => Int -> a -> t
- unsafeFromFlatList :: PrimArray t a => Dims ns -> t -> [t] -> a
- getSteps :: PrimArray t a => Dims (ns :: [k]) -> a -> CumulDims
- fromSteps :: CumulDims -> SomeDims
Documentation
class PrimBytes t => PrimArray t a | a -> t where Source #
Broadcast element into array
ix# :: Int# -> a -> t Source #
Index an array given an offset
:: CumulDims | Dimensionality of the result array;
Be careful! |
-> (s -> (#s, t#)) | |
-> s | |
-> (#s, a#) |
Generate an array using an accumulator funtion
:: CumulDims | Dimensionality of the result array;
Be careful! |
-> Int# | |
-> t | |
-> a | |
-> a |
update a single element in an array given an offset
arrayContent# :: a -> (#t | (#CumulDims, Int#, ByteArray##)#) Source #
If the array represented as a single broadcasted value,
return this value.
Otherwise, return full array content:
CumulDims
, array offset (elements), byte array with the content.
offsetElems :: a -> Int# Source #
Offset of an array as a number of elements
uniqueOrCumulDims :: a -> Either t CumulDims Source #
Normally, this returns a cumulative totalDim
s.
However, if a particular implementation does not have the dimensionality
information, it cannot return CumulDims
;
In this case, it is a sign that all elements of an array are same.
Thus, it is possible to return the single element value instead.
Note, this function returns the only unique element only if it is a such by construction (there is no equality checks involved).
fromElems :: CumulDims -> Int# -> ByteArray# -> a Source #
Get array by its offset and cumulative dims in a ByteArray. Both offset and dims are given in element number (not in bytes).
It is better to use this function instead of fromBytes
to avoid
recalculating CumulDims
for implementations that require it.
Instances
Given Dims ns
, CumulativeDims
is a list of length Length ns + 1
;
which cumulative totalDim
accumulated on the right.
In particular, its first element is totalDim ds
,
its last element is always is always 1
.
CumulDims | |
|
cdTotalDim :: CumulDims -> Word Source #
Get the total number of elements
cdTotalDim# :: CumulDims -> Int# Source #
cdIx :: CumulDims -> Idxs ns -> Int Source #
Calculate offset of an Idxs
Note, you can take offset of subspace with CumulDims of larger space - very convenient!
unsafeFromFlatList :: PrimArray t a => Dims ns -> t -> [t] -> a Source #
Construct an array from a flat list and Dims
;
Be careful! ns
depends on a
, but this is not reflected in
types and is not checked at runtime.