{-# LANGUAGE ExplicitForAll #-}
module Data.Massiv.Array.Mutable.Internal (
unsafeCreateArray,
unsafeCreateArray_,
unsafeCreateArrayS,
) where
import Control.Scheduler
import Data.Massiv.Core.Common
unsafeCreateArrayS
:: forall r ix e a m
. (Manifest r e, Index ix, PrimMonad m)
=> Sz ix
-> (MArray (PrimState m) r ix e -> m a)
-> m (a, Array r ix e)
unsafeCreateArrayS :: forall r ix e a (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix
-> (MArray (PrimState m) r ix e -> m a) -> m (a, Array r ix e)
unsafeCreateArrayS Sz ix
sz MArray (PrimState m) r ix e -> m a
action = do
MArray (PrimState m) r ix e
marr <- forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
unsafeNew Sz ix
sz
a
a <- MArray (PrimState m) r ix e -> m a
action MArray (PrimState m) r ix e
marr
Array r ix e
arr <- forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
Seq MArray (PrimState m) r ix e
marr
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, Array r ix e
arr)
{-# INLINE unsafeCreateArrayS #-}
unsafeCreateArray
:: forall r ix e a m b
. (Manifest r e, Index ix, MonadUnliftIO m)
=> Comp
-> Sz ix
-> (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b)
-> m ([a], Array r ix e)
unsafeCreateArray :: forall r ix e a (m :: * -> *) b.
(Manifest r e, Index ix, MonadUnliftIO m) =>
Comp
-> Sz ix
-> (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b)
-> m ([a], Array r ix e)
unsafeCreateArray Comp
comp Sz ix
sz Scheduler RealWorld a -> MArray RealWorld r ix e -> m b
action = do
MArray RealWorld r ix e
marr <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
unsafeNew Sz ix
sz
[a]
a <- forall (m :: * -> *) a b.
MonadUnliftIO m =>
Comp -> (Scheduler RealWorld a -> m b) -> m [a]
withScheduler Comp
comp (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b
`action` MArray RealWorld r ix e
marr)
Array r ix e
arr <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp MArray RealWorld r ix e
marr
forall (m :: * -> *) a. Monad m => a -> m a
return ([a]
a, Array r ix e
arr)
{-# INLINE unsafeCreateArray #-}
unsafeCreateArray_
:: forall r ix e a m b
. (Manifest r e, Index ix, MonadUnliftIO m)
=> Comp
-> Sz ix
-> (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b)
-> m (Array r ix e)
unsafeCreateArray_ :: forall r ix e a (m :: * -> *) b.
(Manifest r e, Index ix, MonadUnliftIO m) =>
Comp
-> Sz ix
-> (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b)
-> m (Array r ix e)
unsafeCreateArray_ Comp
comp Sz ix
sz Scheduler RealWorld a -> MArray RealWorld r ix e -> m b
action = do
MArray RealWorld r ix e
marr <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
unsafeNew Sz ix
sz
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Comp -> (Scheduler RealWorld a -> m b) -> m ()
withScheduler_ Comp
comp (Scheduler RealWorld a -> MArray RealWorld r ix e -> m b
`action` MArray RealWorld r ix e
marr)
Array r ix e
arr <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp MArray RealWorld r ix e
marr
forall (m :: * -> *) a. Monad m => a -> m a
return Array r ix e
arr
{-# INLINE unsafeCreateArray_ #-}