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
- withArrayContent# :: forall (rep :: RuntimeRep) (r :: TYPE rep). (t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
- 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
- cdIxSub :: CumulDims -> Idxs (ns +: idxN) -> Dim subN -> Int
- getOffAndSteps :: Int -> CumulDims -> Idxs ns -> (Int, CumulDims)
- getOffAndStepsSub :: Int -> CumulDims -> Idxs (ns +: idxN) -> Dim subN -> (Int, CumulDims)
- cdIxM :: CumulDims -> Idxs ns -> Maybe Int
- getOffAndStepsM :: Int -> CumulDims -> Idxs ns -> Maybe (Int, CumulDims)
- getOffAndStepsSubM :: Int -> CumulDims -> Idxs (ns +: idxN) -> Dim subN -> Maybe (Int, CumulDims)
- 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
- withArrayContent :: forall (t :: Type) (a :: Type) (rep :: RuntimeRep) (r :: TYPE rep). PrimArray t a => (t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r
- fromElems :: forall (t :: Type) (a :: Type). PrimArray t a => CumulDims -> Int# -> ByteArray# -> a
- broadcast :: forall (t :: Type) (a :: Type). PrimArray t a => t -> a
Documentation
class PrimBytes t => PrimArray t a | a -> t where Source #
broadcast# :: t -> a Source #
Broadcast element into array
Warning: do not use this function at the call site; use broadcast
instead. Otherwise you will miss some rewrite rules.
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
withArrayContent# :: forall (rep :: RuntimeRep) (r :: TYPE rep). (t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r Source #
Warning: Please, use withArrayContent instead.
If the array is represented as a single broadcasted value, return this
this value. Otherwise, return the full array content:
CumulDims
, array offset (elements), byte array with the content.
Warning: never use this function directly. Use withArrayContent
instead.
There is a bug in GHC 8.6, such that certain optimizations
(probably, instance specialization/rewrite rules) break the code,
which is only observable at runtime. The effect is that the
content of a ByteArray#
becomes a garbage. The workaround is
to use a non-inlinable wrapper to disable these optimizations.
In addition, the wrapper function has some rewrite rules, which
can potentially improve performance with other GHC versions.
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 #
Warning: Please, use fromElems instead.
Define an array by its offset and cumulative dims in a ByteArray. Both offset and dims are given in element number (not in bytes).
Warning: never use this function directly. Use fromElems
instead.
There is a bug in GHC 8.6, such that certain optimizations
(probably, instance specialization/rewrite rules) break the code,
which is only observable at runtime. The effect is that the
content of a ByteArray#
becomes a garbage. The workaround is
to use a non-inlinable wrapper to disable these optimizations.
In addition, the wrapper function has some rewrite rules, which
can potentially improve performance with other GHC versions.
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!
If any of the dims in ns
is unknown (n ~ XN m
),
then this function is unsafe and can throw an OutOfDimBounds
exception.
Otherwise, its safety is guaranteed by the type system.
cdIxSub :: CumulDims -> Idxs (ns +: idxN) -> Dim subN -> Int Source #
Calculate offset of an Idxs.
Also check if the last index plus dimVal of subN is not bigger than the
corresponding dim inside CumulDims; throw an OutOfDimBounds
otherwise.
If any of the dims in ns
is unknown (n ~ XN m
),
then this function is unsafe and can throw an OutOfDimBounds
exception.
Otherwise, its safety is guaranteed by the type system.
Calculate offset of an Idxs and return remaining CumulDims.
If any of the dims in ns
is unknown (n ~ XN m
),
then this function is unsafe and can throw an OutOfDimBounds
exception.
Otherwise, its safety is guaranteed by the type system.
Calculate offset of an Idxs and return remaining CumulDims.
Also check if the last index plus dimVal of subN is not bigger than the
corresponding dim inside CumulDims; throw an OutOfDimBounds
otherwise.
If any of the dims in ns
is unknown (n ~ XN m
),
then this function is unsafe and can throw an OutOfDimBounds
exception.
Otherwise, its safety is guaranteed by the type system.
cdIxM :: CumulDims -> Idxs ns -> Maybe Int Source #
Same as cdIx
, but safe; returns Nothing
if out of bounds.
Same as getOffAndSteps
, but safe; returns Nothing
if out of bounds.
Trims the first (slicing) dimension of the returned CumulDims to fit
the original dataframe if necessary.
Same as getOffAndStepsSub
, but safe; returns Nothing
if out of bounds.
Trims the first (slicing) dimension of the returned CumulDims to fit
the original dataframe if necessary.
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.
getSteps :: PrimArray t a => Dims (ns :: [k]) -> a -> CumulDims Source #
Try to get CumulDims
from an array,
and create it using Dims
if failed.
withArrayContent :: forall (t :: Type) (a :: Type) (rep :: RuntimeRep) (r :: TYPE rep). PrimArray t a => (t -> r) -> (CumulDims -> Int# -> ByteArray# -> r) -> a -> r Source #
If the array is represented as a single broadcasted value, return this
this value. Otherwise, return the full array content:
CumulDims
, array offset (elements), byte array with the content.
fromElems :: forall (t :: Type) (a :: Type). PrimArray t a => CumulDims -> Int# -> ByteArray# -> a Source #
Define an 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.