Copyright | (c) Alexey Kuleshevich 2018-2021 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class Source r e => Manifest r e
- data B = B
- data BL = BL
- data BN = BN
- type N = BN
- pattern N :: N
- data Uninitialized = Uninitialized
- findIndex :: (Index ix, Manifest r e) => (e -> Bool) -> Array r ix e -> Maybe ix
- toLazyArray :: Array B ix e -> Array BL ix e
- evalLazyArray :: Index ix => Array BL ix e -> Array B ix e
- forceLazyArray :: (NFData e, Index ix) => Array BL ix e -> Array N ix e
- unwrapNormalForm :: Array N ix e -> Array B ix e
- evalNormalForm :: (Index ix, NFData e) => Array B ix e -> Array N ix e
- unwrapLazyArray :: Array BL ix e -> Array e
- wrapLazyArray :: Array e -> Vector BL e
- unwrapArray :: Array B ix e -> Array e
- evalArray :: Comp -> Array e -> Vector B e
- unwrapMutableArray :: MArray s B ix e -> MutableArray s e
- unwrapMutableLazyArray :: MArray s BL ix e -> MutableArray s e
- evalMutableArray :: PrimMonad m => MutableArray (PrimState m) e -> m (MArray (PrimState m) B Ix1 e)
- unwrapNormalFormArray :: Array N ix e -> Array e
- evalNormalFormArray :: NFData e => Comp -> Array e -> Array N Ix1 e
- unwrapNormalFormMutableArray :: MArray s N ix e -> MutableArray s e
- evalNormalFormMutableArray :: (PrimMonad m, NFData e) => MutableArray (PrimState m) e -> m (MArray (PrimState m) N Ix1 e)
- toBoxedVector :: Index ix => Array BL ix a -> Vector a
- toBoxedMVector :: Index ix => MArray s BL ix a -> MVector s a
- fromBoxedVector :: Vector a -> Vector BL a
- fromBoxedMVector :: MVector s a -> MArray s BL Ix1 a
- evalBoxedVector :: Comp -> Vector a -> Array B Ix1 a
- evalBoxedMVector :: PrimMonad m => MVector (PrimState m) a -> m (MArray (PrimState m) B Ix1 a)
- data P = P
- class Prim a
- toByteArray :: (Index ix, Prim e) => Array P ix e -> ByteArray
- toByteArrayM :: (Prim e, Index ix, MonadThrow m) => Array P ix e -> m ByteArray
- unwrapByteArray :: Array P ix e -> ByteArray
- unwrapByteArrayOffset :: Array P ix e -> Int
- fromByteArray :: forall e. Prim e => Comp -> ByteArray -> Array P Ix1 e
- fromByteArrayM :: (MonadThrow m, Index ix, Prim e) => Comp -> Sz ix -> ByteArray -> m (Array P ix e)
- fromByteArrayOffsetM :: (MonadThrow m, Index ix, Prim e) => Comp -> Sz ix -> Int -> ByteArray -> m (Array P ix e)
- toMutableByteArray :: forall ix e m. (Prim e, Index ix, PrimMonad m) => MArray (PrimState m) P ix e -> m (Bool, MutableByteArray (PrimState m))
- unwrapMutableByteArray :: MArray s P ix e -> MutableByteArray s
- unwrapMutableByteArrayOffset :: MArray s P ix e -> Int
- fromMutableByteArray :: forall e s. Prim e => MutableByteArray s -> MArray s P Ix1 e
- fromMutableByteArrayM :: (MonadThrow m, Index ix, Prim e) => Sz ix -> MutableByteArray s -> m (MArray s P ix e)
- fromMutableByteArrayOffsetM :: (MonadThrow m, Index ix, Prim e) => Sz ix -> Ix1 -> MutableByteArray s -> m (MArray s P ix e)
- toPrimitiveVector :: Index ix => Array P ix e -> Vector e
- toPrimitiveMVector :: Index ix => MArray s P ix e -> MVector s e
- fromPrimitiveVector :: Vector e -> Array P Ix1 e
- fromPrimitiveMVector :: MVector s e -> MArray s P Ix1 e
- data S = S
- class Storable a
- mallocCompute :: forall r ix e. (Size r, Load r ix e, Storable e) => Array r ix e -> IO (Array S ix e)
- mallocCopy :: forall ix e. (Index ix, Storable e) => Array S ix e -> IO (Array S ix e)
- toStorableVector :: Index ix => Array S ix e -> Vector e
- toStorableMVector :: Index ix => MArray s S ix e -> MVector s e
- fromStorableVector :: Comp -> Vector e -> Vector S e
- fromStorableMVector :: MVector s e -> MVector s S e
- withPtr :: MonadUnliftIO m => MArray RealWorld S ix e -> (Ptr e -> m b) -> m b
- data U = U
- class (Vector Vector a, MVector MVector a) => Unbox a
- toUnboxedVector :: Array U ix e -> Vector e
- toUnboxedMVector :: MArray s U ix e -> MVector s e
- fromUnboxedVector :: Unbox e => Comp -> Vector e -> Vector U e
- fromUnboxedMVector :: Unbox e => MVector s e -> MVector s U e
- fromByteString :: Load r Ix1 Word8 => Comp -> ByteString -> Vector r Word8
- castFromByteString :: Comp -> ByteString -> Vector S Word8
- toByteString :: Load r ix Word8 => Array r ix Word8 -> ByteString
- castToByteString :: Index ix => Array S ix Word8 -> ByteString
- toBuilder :: (Index ix, Source r e) => (e -> Builder) -> Array r ix e -> Builder
- castToBuilder :: Index ix => Array S ix Word8 -> Builder
Manifest
class Source r e => Manifest r e Source #
Manifest arrays are backed by actual memory and values are looked up versus
computed as it is with delayed arrays. Because manifest arrays are located in
memory their contents can be mutated once thawed into MArray
. The process
of changed a mutable MArray
back into an immutable Array
is called
freezing.
unsafeLinearIndexM, sizeOfMArray, unsafeResizeMArray, unsafeLinearSliceMArray, unsafeThaw, unsafeFreeze, unsafeNew, unsafeLinearRead, unsafeLinearWrite, initialize
Instances
Boxed
Array representation for Boxed elements. This structure is element and spine strict, but elements are strict to Weak Head Normal Form (WHNF) only.
Instances
Array representation for Boxed elements. This data structure is lazy with respect to its elements, but is strict with respect to the spine.
Instances
Array representation for Boxed elements. This structure is element and
spine strict, and elements are always in Normal Form (NF), therefore NFData
instance is required.
Instances
data Uninitialized Source #
An error that gets thrown when an unitialized element of a boxed array gets accessed. Can only
happen when array was constructed with unsafeNew
.
Instances
Show Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception showsPrec :: Int -> Uninitialized -> ShowS # show :: Uninitialized -> String # showList :: [Uninitialized] -> ShowS # | |
Exception Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception |
Access
findIndex :: (Index ix, Manifest r e) => (e -> Bool) -> Array r ix e -> Maybe ix Source #
O(n) - Perform a row-major search starting at 0
for an element. Returns the index
of the first occurance of an element or Nothing
if a predicate could not be satisifed
after it was applyied to all elements of the array.
Since: 0.5.5
Conversion
Important part of all conversions in this section is that the actual boxed
Array
, which holds the pointers to values isn't copied around, it is always
kept as the same array. Conversion to Massiv boxed array will undergo evaluation during which
computation strategies will be respected.
toLazyArray :: Array B ix e -> Array BL ix e Source #
O(1) - Cast a strict boxed array into a lazy boxed array.
Since: 0.6.0
evalLazyArray :: Index ix => Array BL ix e -> Array B ix e Source #
O(n) - Evaluate all elements of a boxed lazy array to weak head normal form
Since: 0.6.0
forceLazyArray :: (NFData e, Index ix) => Array BL ix e -> Array N ix e Source #
O(n) - Evaluate all elements of a boxed lazy array to normal form
Since: 0.6.0
evalNormalForm :: (Index ix, NFData e) => Array B ix e -> Array N ix e Source #
O(n) - Compute all elements of a boxed array to NF (normal form)
Since: 0.5.0
Primitive Boxed Array
unwrapLazyArray :: Array BL ix e -> Array e Source #
O(1) - Unwrap boxed array. This will discard any possible slicing that has been applied to the array.
Since: 0.6.0
unwrapArray :: Array B ix e -> Array e Source #
O(1) - Unwrap boxed array. This will discard any possible slicing that has been applied to the array.
Since: 0.2.1
O(n) - Wrap a boxed array and evaluate all elements to a WHNF.
Since: 0.2.1
unwrapMutableArray :: MArray s B ix e -> MutableArray s e Source #
O(1) - Unwrap mutable boxed array. This will discard any possible slicing that has been applied to the array.
Since: 0.2.1
unwrapMutableLazyArray :: MArray s BL ix e -> MutableArray s e Source #
O(1) - Unwrap mutable boxed lazy array. This will discard any possible slicing that has been applied to the array.
Since: 0.6.0
:: PrimMonad m | |
=> MutableArray (PrimState m) e | Mutable array that will get wrapped |
-> m (MArray (PrimState m) B Ix1 e) |
O(n) - Wrap mutable boxed array and evaluate all elements to WHNF.
Since: 0.2.1
unwrapNormalFormArray :: Array N ix e -> Array e Source #
O(1) - Unwrap a fully evaluated boxed array. This will discard any possible slicing that has been applied to the array.
Since: 0.2.1
O(n) - Wrap a boxed array and evaluate all elements to a Normal Form (NF).
Since: 0.2.1
unwrapNormalFormMutableArray :: MArray s N ix e -> MutableArray s e Source #
O(1) - Unwrap a fully evaluated mutable boxed array. This will discard any possible slicing that has been applied to the array.
Since: 0.2.1
evalNormalFormMutableArray :: (PrimMonad m, NFData e) => MutableArray (PrimState m) e -> m (MArray (PrimState m) N Ix1 e) Source #
O(n) - Wrap mutable boxed array and evaluate all elements to NF.
Since: 0.2.1
Boxed Vector
fromBoxedVector :: Vector a -> Vector BL a Source #
O(1) - Cast a boxed vector without touching any elements.
Since: 0.6.0
fromBoxedMVector :: MVector s a -> MArray s BL Ix1 a Source #
O(1) - Convert mutable boxed vector to a lazy mutable boxed array. Both keep pointing to the same memory
Since: 0.6.0
evalBoxedVector :: Comp -> Vector a -> Array B Ix1 a Source #
O(n) - Convert a boxed vector and evaluate all elements to WHNF. Computation strategy will be respected during evaluation
Since: 0.5.0
evalBoxedMVector :: PrimMonad m => MVector (PrimState m) a -> m (MArray (PrimState m) B Ix1 a) Source #
O(n) - Convert mutable boxed vector and evaluate all elements to WHNF sequentially. Both keep pointing to the same memory
Since: 0.5.0
Primitive
Representation for Prim
itive elements
Instances
Class of types supporting primitive array operations. This includes
interfacing with GC-managed memory (functions suffixed with ByteArray#
)
and interfacing with unmanaged memory (functions suffixed with Addr#
).
Endianness is platform-dependent.
sizeOf#, alignment#, indexByteArray#, readByteArray#, writeByteArray#, setByteArray#, indexOffAddr#, readOffAddr#, writeOffAddr#, setOffAddr#
Instances
Conversion
Primitive ByteArray
toByteArrayM :: (Prim e, Index ix, MonadThrow m) => Array P ix e -> m ByteArray Source #
O(1) - Unwrap Ensure that the size matches the internal ByteArray
.
Since: 0.5.0
unwrapByteArray :: Array P ix e -> ByteArray Source #
O(1) - Extract the internal ByteArray
. This will ignore any possible slicing that
has been applied to the array. Use toByteArray
in order to preserve slicing or
unwrapByteArrayOffset
to get ahold of the offset
Since: 0.5.0
unwrapByteArrayOffset :: Array P ix e -> Int Source #
O(1) - Extract potential linear offset into the underlying ByteArray
, which can
also be extracted with unwrapByteArray
.
Since: 0.5.9
fromByteArray :: forall e. Prim e => Comp -> ByteArray -> Array P Ix1 e Source #
O(1) - Construct a flat Array from ByteArray
Since: 0.4.0
fromByteArrayM :: (MonadThrow m, Index ix, Prim e) => Comp -> Sz ix -> ByteArray -> m (Array P ix e) Source #
fromByteArrayOffsetM :: (MonadThrow m, Index ix, Prim e) => Comp -> Sz ix -> Int -> ByteArray -> m (Array P ix e) Source #
toMutableByteArray :: forall ix e m. (Prim e, Index ix, PrimMonad m) => MArray (PrimState m) P ix e -> m (Bool, MutableByteArray (PrimState m)) Source #
O(n) - Try to cast a mutable array to MutableByteArray
, if sizes do not match make
a copy. Returns True
if an array was converted without a copy, in which case it means
that the source at the resulting array are still pointing to the same location in memory.
Since: 0.5.0
unwrapMutableByteArray :: MArray s P ix e -> MutableByteArray s Source #
O(1) - Extract the internal MutableByteArray
. This will discard any possible
slicing that has been applied to the array.
Since: 0.5.0
unwrapMutableByteArrayOffset :: MArray s P ix e -> Int Source #
O(1) - Extract the linear offset into underlying MutableByteArray
, which can aslo
be extracted with unwrapMutableByteArray
.
Since: 0.5.9
fromMutableByteArray :: forall e s. Prim e => MutableByteArray s -> MArray s P Ix1 e Source #
O(1) - Construct a flat Array from MutableByteArray
Since: 0.4.0
fromMutableByteArrayM :: (MonadThrow m, Index ix, Prim e) => Sz ix -> MutableByteArray s -> m (MArray s P ix e) Source #
O(1) - Construct a primitive mutable array from the MutableByteArray
. Will throw
SizeElementsMismatchException
if number of elements doesn't match.
Since: 0.3.0
fromMutableByteArrayOffsetM :: (MonadThrow m, Index ix, Prim e) => Sz ix -> Ix1 -> MutableByteArray s -> m (MArray s P ix e) Source #
O(1) - Construct a primitive mutable array from the MutableByteArray
. Will throw
SizeElementsMismatchException
if number of elements doesn't match.
Since: 0.5.9
Primitive Vector
toPrimitiveVector :: Index ix => Array P ix e -> Vector e Source #
O(1) - Cast a primitive array to a primitive vector.
Since: 0.5.0
toPrimitiveMVector :: Index ix => MArray s P ix e -> MVector s e Source #
O(1) - Cast a mutable primitive array to a mutable primitive vector.
Since: 0.5.0
fromPrimitiveVector :: Vector e -> Array P Ix1 e Source #
O(1) - Cast a primitive vector to a primitive array.
Since: 0.5.0
fromPrimitiveMVector :: MVector s e -> MArray s P Ix1 e Source #
O(1) - Cast a mutable primitive vector to a mutable primitive array.
Since: 0.5.0
Storable
Representation for Storable
elements
Instances
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type
, for some
Ptr
aa
which is an instance of class Storable
. The type argument to
Ptr
helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable
facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int
types (Int8
, Int16
,
Int32
, Int64
), the fixed size Word
types (Word8
, Word16
,
Word32
, Word64
), StablePtr
, all types from Foreign.C.Types,
as well as Ptr
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)