Copyright | (c) Alexey Kuleshevich 2018-2022 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- class Source r e => Manifest r e
- generateArray :: forall r ix e m. (MonadUnliftIO m, Manifest r e, Index ix) => Comp -> Sz ix -> (ix -> m e) -> m (Array r ix e)
- generateArrayLinear :: forall r ix e m. (MonadUnliftIO m, Manifest r e, Index ix) => Comp -> Sz ix -> (Ix1 -> m e) -> m (Array r ix e)
- generateArrayS :: forall r ix e m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (ix -> m e) -> m (Array r ix e)
- generateArrayLinearS :: forall r ix e m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (Int -> m e) -> m (Array r ix e)
- generateSplitSeedArray :: forall r ix e g it. (Iterator it, Manifest r e, Index ix) => it -> g -> (forall s. g -> ST s (g, g)) -> Comp -> Sz ix -> (forall s. Ix1 -> ix -> g -> ST s (e, g)) -> (g, [g], Array r ix e)
- generateArrayWS :: forall r ix e s m. (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (ix -> s -> m e) -> m (Array r ix e)
- generateArrayLinearWS :: forall r ix e s m. (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (Int -> s -> m e) -> m (Array r ix e)
- unfoldrPrimM_ :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> m (e, a)) -> a -> m (Array r ix e)
- iunfoldrPrimM_ :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> ix -> m (e, a)) -> a -> m (Array r ix e)
- unfoldrPrimM :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> m (e, a)) -> a -> m (a, Array r ix e)
- iunfoldrPrimM :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> ix -> m (e, a)) -> a -> m (a, Array r ix e)
- unfoldlPrimM_ :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> m (a, e)) -> a -> m (Array r ix e)
- iunfoldlPrimM_ :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> ix -> m (a, e)) -> a -> m (Array r ix e)
- unfoldlPrimM :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> m (a, e)) -> a -> m (a, Array r ix e)
- iunfoldlPrimM :: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) => Sz ix -> (a -> ix -> m (a, e)) -> a -> m (a, Array r ix e)
- forPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (e -> m e) -> m ()
- forPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (e -> m ()) -> m ()
- iforPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (ix -> e -> m e) -> m ()
- iforPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (ix -> e -> m ()) -> m ()
- iforLinearPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (Int -> e -> m e) -> m ()
- iforLinearPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (Int -> e -> m ()) -> m ()
- for2PrimM_ :: forall r1 r2 e1 e2 ix m. (PrimMonad m, Index ix, Manifest r1 e1, Manifest r2 e2) => MArray (PrimState m) r1 ix e1 -> MArray (PrimState m) r2 ix e2 -> (e1 -> e2 -> m ()) -> m ()
- ifor2PrimM_ :: forall r1 r2 e1 e2 ix m. (PrimMonad m, Index ix, Manifest r1 e1, Manifest r2 e2) => MArray (PrimState m) r1 ix e1 -> MArray (PrimState m) r2 ix e2 -> (ix -> e1 -> e2 -> m ()) -> m ()
- 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
Generate
generateArray :: forall r ix e m. (MonadUnliftIO m, Manifest r e, Index ix) => Comp -> Sz ix -> (ix -> m e) -> m (Array r ix e) Source #
Just like generateArrayS
, except this generator will respect the supplied computation
strategy, and for that reason it is restricted to IO
.
Since: 0.2.6
generateArrayLinear :: forall r ix e m. (MonadUnliftIO m, Manifest r e, Index ix) => Comp -> Sz ix -> (Ix1 -> m e) -> m (Array r ix e) Source #
Just like generateArray
, except generating action will receive a row-major linear
index.
Since: 0.3.0
:: forall r ix e m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the array |
-> (ix -> m e) | Element producing action |
-> m (Array r ix e) |
Sequentially generate a pure array. Much like makeArray
creates a pure array this
function will use Manifest
interface to generate a pure Array
in the end, except that
computation strategy is set to Seq
. Element producing function no longer has to be pure
but is a stateful action, becuase it is restricted to PrimMonad
thus allows for sharing
the state between computation of each element.
Examples
>>>
import Data.Massiv.Array
>>>
import Data.IORef
>>>
ref <- newIORef (0 :: Int)
>>>
generateArrayS (Sz1 6) (\ i -> modifyIORef' ref (+i) >> print i >> pure i) :: IO (Array U Ix1 Int)
0 1 2 3 4 5 Array U Seq (Sz1 6) [ 0, 1, 2, 3, 4, 5 ]>>>
readIORef ref
15
Since: 0.2.6
:: forall r ix e m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Resulting size of the array |
-> (Int -> m e) | Element producing generator |
-> m (Array r ix e) |
Same as generateArray
but with action that accepts row-major linear index.
Since: 0.3.0
generateSplitSeedArray Source #
:: forall r ix e g it. (Iterator it, Manifest r e, Index ix) | |
=> it | Iterator |
-> g | Initial seed |
-> (forall s. g -> ST s (g, g)) | An ST action that can split a seed into two independent seeds. It will be called the same number of times as the number of jobs that will get scheduled during parallelization. Eg. only once for the sequential case. |
-> Comp | Computation strategy. |
-> Sz ix | Resulting size of the array. |
-> (forall s. Ix1 -> ix -> g -> ST s (e, g)) | An ST action that produces a value and the next seed. It takes both versions of the index, in linear and in multi-dimensional forms, as well as the current seeding value. Returns the element for the array cell together with the new seed that will be used for the next element generation |
-> (g, [g], Array r ix e) | Returned values are:
|
Similar to makeSplitSeedArray
, except it will produce a
Manifest array and will return back the last unused seed together with all
final seeds produced by each scheduled job. This function can be thought of
as an unfolding done in parallel while iterating in a customizable manner.
Since: 1.0.2
Stateful worker threads
generateArrayWS :: forall r ix e s m. (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (ix -> s -> m e) -> m (Array r ix e) Source #
Use per worker thread state while generating elements of the array. Very useful for things that are not thread safe.
Since: 0.3.4
generateArrayLinearWS :: forall r ix e s m. (Manifest r e, Index ix, MonadUnliftIO m, PrimMonad m) => WorkerStates s -> Sz ix -> (Int -> s -> m e) -> m (Array r ix e) Source #
Same as generateArrayWS
, but use linear indexing instead.
Since: 0.3.4
Unfold
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> m (e, a)) | Unfolding action |
-> a | Initial accumulator |
-> m (Array r ix e) |
Sequentially unfold an array from the left.
Examples
Create an array with Fibonacci numbers while performing an IO
action at each iteration.
>>>
import Data.Massiv.Array
>>>
unfoldrPrimM_ (Sz1 10) (\(f0, f1) -> (f0, (f1, f0 + f1)) <$ print f1) (0, 1) :: IO (Array P Ix1 Int)
1 1 2 3 5 8 13 21 34 55 Array P Seq (Sz1 10) [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ]
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> ix -> m (e, a)) | Unfolding action |
-> a | Initial accumulator |
-> m (Array r ix e) |
Same as unfoldrPrimM_
but do the unfolding with index aware function.
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> m (e, a)) | Unfolding action |
-> a | Initial accumulator |
-> m (a, Array r ix e) |
Just like iunfoldrPrimM
, but do the unfolding with index aware function.
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> ix -> m (e, a)) | Unfolding action |
-> a | Initial accumulator |
-> m (a, Array r ix e) |
Just like iunfoldrPrimM_
, but also returns the final value of the accumulator.
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> m (a, e)) | Unfolding action |
-> a | Initial accumulator |
-> m (Array r ix e) |
Sequentially unfold an array from the left.
Examples
Create an array with Fibonacci numbers starting at the end while performing and IO
action on
the accumulator for each element of the array.
>>>
import Data.Massiv.Array
>>>
unfoldlPrimM_ (Sz1 10) (\a@(f0, f1) -> let fn = f0 + f1 in print a >> return ((f1, fn), f0)) (0, 1) :: IO (Array P Ix1 Int)
(0,1) (1,1) (1,2) (2,3) (3,5) (5,8) (8,13) (13,21) (21,34) (34,55) Array P Seq (Sz1 10) [ 34, 21, 13, 8, 5, 3, 2, 1, 1, 0 ]
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> ix -> m (a, e)) | Unfolding action |
-> a | Initial accumulator |
-> m (Array r ix e) |
Same as unfoldlPrimM_
but do the unfolding with index aware function.
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> m (a, e)) | Unfolding action |
-> a | Initial accumulator |
-> m (a, Array r ix e) |
Just like iunfoldlPrimM
, but do the unfolding with index aware function.
Since: 0.3.0
:: forall r ix e a m. (Manifest r e, Index ix, PrimMonad m) | |
=> Sz ix | Size of the desired array |
-> (a -> ix -> m (a, e)) | Unfolding action |
-> a | Initial accumulator |
-> m (a, Array r ix e) |
Just like iunfoldlPrimM_
, but also returns the final value of the accumulator.
Since: 0.3.0
Mapping
forPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (e -> m e) -> m () Source #
Sequentially loop over a mutable array while modifying each element with an action.
Since: 0.4.0
forPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (e -> m ()) -> m () Source #
Sequentially loop over a mutable array while reading each element and applying an action to it. There is no mutation to the array, unless the action itself modifies it.
Since: 0.4.0
iforPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (ix -> e -> m e) -> m () Source #
Sequentially loop over a mutable array while modifying each element with an index aware action.
Since: 0.4.0
iforPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (ix -> e -> m ()) -> m () Source #
Sequentially loop over a mutable array while reading each element and applying an index aware action to it. There is no mutation to the array, unless the action itself modifies it.
Since: 0.4.0
iforLinearPrimM :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (Int -> e -> m e) -> m () Source #
Sequentially loop over a mutable array while modifying each element with an index aware action.
Since: 0.4.0
iforLinearPrimM_ :: (Manifest r e, Index ix, PrimMonad m) => MArray (PrimState m) r ix e -> (Int -> e -> m ()) -> m () Source #
Sequentially loop over a mutable array while reading each element and applying a linear index aware action to it. There is no mutation to the array, unless the action itself modifies it.
Since: 0.4.0
for2PrimM_ :: forall r1 r2 e1 e2 ix m. (PrimMonad m, Index ix, Manifest r1 e1, Manifest r2 e2) => MArray (PrimState m) r1 ix e1 -> MArray (PrimState m) r2 ix e2 -> (e1 -> e2 -> m ()) -> m () Source #
Sequentially loop over the intersection of two mutable arrays while reading elements from both and applying an action to it. There is no mutation to the actual arrays, unless the action itself modifies either one of them.
Since: 1.0.0
ifor2PrimM_ :: forall r1 r2 e1 e2 ix m. (PrimMonad m, Index ix, Manifest r1 e1, Manifest r2 e2) => MArray (PrimState m) r1 ix e1 -> MArray (PrimState m) r2 ix e2 -> (ix -> e1 -> e2 -> m ()) -> m () Source #
Same as for2PrimM_
, but with index aware action.
Since: 1.0.0
Boxed
Array representation for Boxed elements. Its 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.
Example
Memoized version of a factorial that relies on laziness. Note that computing memoized factorial of a million would likely overflow memory.
>>>
import Data.Massiv.Array as A
>>>
:{
mkMemoFactorial :: Int -> (Int -> Integer) mkMemoFactorial n = let arr = makeVectorR BL Seq (Sz1 n) fact fact i | i == 0 = 1 | otherwise = (arr ! (i - 1)) * toInteger i in (arr !) :}
>>>
let fact = mkMemoFactorial 1000001
>>>
fact 50
30414093201713378043612608166064768844377641568960512000000000000>>>
length $ show $ fact 5000
16326
Instances
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
Exception Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception | |
Show Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception showsPrec :: Int -> Uninitialized -> ShowS # show :: Uninitialized -> String # showList :: [Uninitialized] -> ShowS # |
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)
Instances
mallocCompute :: forall r ix e. (Size r, Load r ix e, Storable e) => Array r ix e -> IO (Array S ix e) Source #
mallocCopy :: forall ix e. (Index ix, Storable e) => Array S ix e -> IO (Array S ix e) Source #
Allocate memory on C heap with malloc
and copy the source array over.
Since: 0.5.9
Conversion
Storable Vector
toStorableVector :: Index ix => Array S ix e -> Vector e Source #
O(1) - Unwrap storable array and pull out the underlying storable vector.
Since: 0.2.1
toStorableMVector :: Index ix => 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 :: Comp -> Vector e -> Vector S e Source #
O(1) - Cast a storable vector to a storable array.
Since: 0.5.0
fromStorableMVector :: MVector s e -> MVector s S e Source #
O(1) - Cast a mutable storable vector to a mutable storable array.
Since: 0.5.0
Direct Pointer Access
withPtr :: MonadUnliftIO m => MArray RealWorld S ix e -> (Ptr e -> 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
Unboxed Vector
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 => Comp -> Vector e -> Vector U e Source #
O(1) - Wrap an unboxed vector and produce an unboxed flat array.
Since: 0.6.0
fromUnboxedMVector :: Unbox e => MVector s e -> MVector s U e Source #
O(1) - Wrap an unboxed mutable vector and produce a mutable unboxed flat array.
Since: 0.5.0
ByteString Conversion
:: Load r Ix1 Word8 | |
=> Comp | Computation strategy |
-> ByteString | Strict ByteString to use as a source. |
-> Vector r Word8 |
O(n) - 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 -> Vector S 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 :: Index ix => Array S ix Word8 -> ByteString Source #
O(1) - Cast a S
torable array into a strict ByteString
Since: 0.3.0