Copyright | (c) Alexey Kuleshevich 2018-2019 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class (Load r ix e, Source r ix e) => Manifest r ix e
- toManifest :: Manifest r ix e => Array r ix e -> Array M ix e
- data M
- data B = B
- data N = N
- data Uninitialized = Uninitialized
- unwrapNormalForm :: Array N ix e -> Array B ix e
- evalNormalForm :: (Index ix, NFData e) => Array B ix e -> Array N ix e
- unwrapArray :: Array B ix e -> Array e
- evalArray :: Comp -> Array e -> Array B Ix1 e
- unwrapMutableArray :: MArray s B 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 B ix a -> Vector a
- toBoxedMVector :: Index ix => MArray s B ix a -> MVector s 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
- 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)
- 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
- 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)
- 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
- toStorableVector :: Array S ix e -> Vector e
- toStorableMVector :: MArray s S ix e -> MVector s e
- fromStorableVector :: Storable e => Comp -> Vector e -> Array S Ix1 e
- fromStorableMVector :: MVector s e -> MArray s S Ix1 e
- withPtr :: (MonadUnliftIO m, Storable a) => MArray RealWorld S ix a -> (Ptr a -> 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 => Vector e -> Array U Ix1 e
- fromUnboxedMVector :: Unbox e => MVector s e -> MArray s U Ix1 e
- fromByteString :: Comp -> ByteString -> Array M Ix1 Word8
- castFromByteString :: Comp -> ByteString -> Array S Ix1 Word8
- toByteString :: Load r ix Word8 => Array r ix Word8 -> ByteString
- castToByteString :: Array S ix Word8 -> ByteString
- toBuilder :: Source r ix e => (e -> Builder) -> Array r ix e -> Builder
- castToBuilder :: Array S ix Word8 -> Builder
Manifest
class (Load r ix e, Source r ix e) => Manifest r ix e Source #
Manifest arrays are backed by actual memory and values are looked up versus
computed as it is with delayed arrays. Because of this fact indexing functions
(
, !
)(
, etc. are constrained to manifest arrays only.!?
)
Instances
Index ix => Manifest M ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Internal | |
(Unbox e, Index ix) => Manifest U ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
(Index ix, Prim e) => Manifest P ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
(Index ix, Storable e) => Manifest S ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Storable | |
(Index ix, NFData e) => Manifest N ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => Manifest B ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed |
General Manifest representation
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 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 |
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.
unwrapNormalForm :: Array N ix e -> Array B ix e Source #
O(n) - Compute all elements of a boxed array to NF (normal form)
Since: 0.5.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
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
:: 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
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 discard any possible slicing that has been
applied to the array. Use toByteArray
in order to preserve slicing.
Since: 0.5.0
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 #
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
tha 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
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
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)
Instances
Conversion
Primitive Vector
toStorableVector :: Array S ix e -> Vector e Source #
O(1) - Unwrap storable array and pull out the underlying storable vector.
Since: 0.2.1
toStorableMVector :: MArray s S ix e -> MVector s e Source #
O(1) - Unwrap storable mutable array and pull out the underlying storable mutable vector.
Since: 0.2.1
fromStorableVector :: Storable e => Comp -> Vector e -> Array S Ix1 e Source #
O(1) - Cast a storable vector to a storable array.
Since: 0.5.0
fromStorableMVector :: MVector s e -> MArray s S Ix1 e Source #
O(1) - Cast a mutable storable vector to a mutable storable array.
Since: 0.5.0
Direct Pointer Access
withPtr :: (MonadUnliftIO m, Storable a) => MArray RealWorld S ix a -> (Ptr a -> m b) -> m b Source #
A pointer to the beginning of the mutable array.
Since: 0.1.3
Unboxed
Representation for Unbox
ed elements
Instances
class (Vector Vector a, MVector MVector a) => Unbox a #
Instances
Conversion
toUnboxedVector :: Array U ix e -> Vector e Source #
O(1) - Unwrap unboxed array and pull out the underlying unboxed vector.
Since: 0.2.1
toUnboxedMVector :: MArray s U ix e -> MVector s e Source #
O(1) - Unwrap unboxed mutable array and pull out the underlying unboxed mutable vector.
Since: 0.2.1
fromUnboxedVector :: Unbox e => Vector e -> Array U Ix1 e Source #
O(1) - Wrap an unboxed vector and produce an unboxed flat array.
Since: 0.5.0
fromUnboxedMVector :: Unbox e => MVector s e -> MArray s U Ix1 e Source #
O(1) - Wrap an unboxed mutable vector and produce a mutable unboxed flat array.
Since: 0.5.0
ByteString Conversion
O(1) - Convert a strict ByteString into a manifest array. Will return Nothing
if length
doesn't match the total number of elements of new array.
Since: 0.2.1
castFromByteString :: Comp -> ByteString -> Array S Ix1 Word8 Source #
O(1) - Cast a strict ByteString
into a S
torable array
Since: 0.3.0
:: Load r ix Word8 | |
=> Array r ix Word8 | Source array |
-> ByteString |
O(n) - Convert any source array into a strict ByteString
. In case when the source array is
actually storable, no memory copy will occur.
Since: 0.2.1
castToByteString :: Array S ix Word8 -> ByteString Source #
O(1) - Cast a S
torable array into a strict ByteString
Since: 0.3.0