module Z.Data.Array.Checked
(
A.Arr
, RealWorld
, A.Array(..)
, A.MutableArray(..)
, A.SmallArray(..)
, A.SmallMutableArray(..)
, A.uninitialized
, A.PrimArray(..)
, A.MutablePrimArray(..)
, Prim(..)
, newArr
, newArrWith
, readArr
, writeArr
, setArr
, indexArr
, indexArr'
, indexArrM
, freezeArr
, thawArr
, copyArr
, copyMutableArr
, moveArr
, cloneArr
, cloneMutableArr
, resizeMutableArr
, shrinkMutableArr
, A.unsafeFreezeArr
, A.unsafeThawArr
, A.sameMutableArr
, A.sizeofArr
, A.sizeofMutableArr
, A.sameArr
, newPinnedPrimArray, newAlignedPinnedPrimArray
, copyPrimArrayToPtr, copyMutablePrimArrayToPtr, copyPtrToMutablePrimArray
, A.primArrayContents, A.mutablePrimArrayContents, A.withPrimArrayContents, A.withMutablePrimArrayContents
, A.isPrimArrayPinned, A.isMutablePrimArrayPinned
, A.UnliftedArray(..)
, A.MutableUnliftedArray(..)
, A.PrimUnlifted(..)
, ArrayException(..)
, A.Cast
, A.castArray
, A.castMutableArray
) where
import Control.Exception (ArrayException (..), throw)
import Control.Monad.Primitive
import Data.Primitive.Types
import GHC.Stack
import qualified Z.Data.Array as A
check :: HasCallStack => Bool -> a -> a
{-# INLINE check #-}
check :: Bool -> a -> a
check Bool
True a
x = a
x
check Bool
False a
_ = ArrayException -> a
forall a e. Exception e => e -> a
throw (String -> ArrayException
IndexOutOfBounds (String -> ArrayException) -> String -> ArrayException
forall a b. (a -> b) -> a -> b
$ CallStack -> String
forall a. Show a => a -> String
show CallStack
HasCallStack => CallStack
callStack)
newArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> Int -> m (A.MArr arr s a)
newArr :: Int -> m (MArr arr s a)
newArr Int
n = Bool -> m (MArr arr s a) -> m (MArr arr s a)
forall a. HasCallStack => Bool -> a -> a
check (Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0) (Int -> m (MArr arr s a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
Int -> m (MArr arr s a)
A.newArr Int
n)
{-# INLINE newArr #-}
newArrWith :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> Int -> a -> m (A.MArr arr s a)
newArrWith :: Int -> a -> m (MArr arr s a)
newArrWith Int
n a
x = Bool -> m (MArr arr s a) -> m (MArr arr s a)
forall a. HasCallStack => Bool -> a -> a
check (Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0) (Int -> a -> m (MArr arr s a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
Int -> a -> m (MArr arr s a)
A.newArrWith Int
n a
x)
{-# INLINE newArrWith #-}
readArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> m a
readArr :: MArr arr s a -> Int -> m a
readArr MArr arr s a
marr Int
i = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m a -> m a
forall a. HasCallStack => Bool -> a -> a
check
(Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<Int
siz)
(MArr arr s a -> Int -> m a
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> m a
A.readArr MArr arr s a
marr Int
i)
{-# INLINE readArr #-}
writeArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> a -> m ()
writeArr :: MArr arr s a -> Int -> a -> m ()
writeArr MArr arr s a
marr Int
i a
x = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<Int
siz)
(MArr arr s a -> Int -> a -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> a -> m ()
A.writeArr MArr arr s a
marr Int
i a
x)
{-# INLINE writeArr #-}
setArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> Int -> a -> m ()
setArr :: MArr arr s a -> Int -> Int -> a -> m ()
setArr MArr arr s a
marr Int
s Int
l a
x = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MArr arr s a -> Int -> Int -> a -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> Int -> a -> m ()
A.setArr MArr arr s a
marr Int
s Int
l a
x)
{-# INLINE setArr #-}
indexArr :: (A.Arr arr a, HasCallStack)
=> arr a -> Int -> a
indexArr :: arr a -> Int -> a
indexArr arr a
arr Int
i = Bool -> a -> a
forall a. HasCallStack => Bool -> a -> a
check
(Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr)
(arr a -> Int -> a
forall (arr :: * -> *) a. Arr arr a => arr a -> Int -> a
A.indexArr arr a
arr Int
i)
{-# INLINE indexArr #-}
indexArr' :: (A.Arr arr a, HasCallStack)
=> arr a -> Int -> (# a #)
indexArr' :: arr a -> Int -> (# a #)
indexArr' arr a
arr Int
i =
if (Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr)
then arr a -> Int -> (# a #)
forall (arr :: * -> *) a. Arr arr a => arr a -> Int -> (# a #)
A.indexArr' arr a
arr Int
i
else ArrayException -> (# a #)
forall a e. Exception e => e -> a
throw (String -> ArrayException
IndexOutOfBounds (String -> ArrayException) -> String -> ArrayException
forall a b. (a -> b) -> a -> b
$ CallStack -> String
forall a. Show a => a -> String
show CallStack
HasCallStack => CallStack
callStack)
{-# INLINE indexArr' #-}
indexArrM :: (A.Arr arr a, Monad m, HasCallStack)
=> arr a -> Int -> m a
indexArrM :: arr a -> Int -> m a
indexArrM arr a
arr Int
i = Bool -> m a -> m a
forall a. HasCallStack => Bool -> a -> a
check
(Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
iInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr)
(arr a -> Int -> m a
forall (arr :: * -> *) a (m :: * -> *).
(Arr arr a, Monad m) =>
arr a -> Int -> m a
A.indexArrM arr a
arr Int
i)
{-# INLINE indexArrM #-}
freezeArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> Int -> m (arr a)
freezeArr :: MArr arr s a -> Int -> Int -> m (arr a)
freezeArr MArr arr s a
marr Int
s Int
l = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m (arr a) -> m (arr a)
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MArr arr s a -> Int -> Int -> m (arr a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> Int -> m (arr a)
A.freezeArr MArr arr s a
marr Int
s Int
l)
{-# INLINE freezeArr #-}
thawArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> arr a -> Int -> Int -> m (A.MArr arr s a)
thawArr :: arr a -> Int -> Int -> m (MArr arr s a)
thawArr arr a
arr Int
s Int
l = Bool -> m (MArr arr s a) -> m (MArr arr s a)
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr)
(arr a -> Int -> Int -> m (MArr arr s a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
arr a -> Int -> Int -> m (MArr arr s a)
A.thawArr arr a
arr Int
s Int
l)
{-# INLINE thawArr #-}
copyArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> arr a -> Int -> Int -> m ()
copyArr :: MArr arr s a -> Int -> arr a -> Int -> Int -> m ()
copyArr MArr arr s a
marr Int
s1 arr a
arr Int
s2 Int
l = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
s1Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
s2Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
s2Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr Bool -> Bool -> Bool
&& (Int
s1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MArr arr s a -> Int -> arr a -> Int -> Int -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> arr a -> Int -> Int -> m ()
A.copyArr MArr arr s a
marr Int
s1 arr a
arr Int
s2 Int
l)
{-# INLINE copyArr #-}
copyMutableArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> A.MArr arr s a -> Int -> Int -> m ()
copyMutableArr :: MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
copyMutableArr MArr arr s a
marr1 Int
s1 MArr arr s a
marr2 Int
s2 Int
l = do
Int
siz1 <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr1
Int
siz2 <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr2
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
s1Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
s2Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
s2Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz2 Bool -> Bool -> Bool
&& (Int
s1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz1)
(MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
A.copyMutableArr MArr arr s a
marr1 Int
s1 MArr arr s a
marr2 Int
s2 Int
l)
{-# INLINE copyMutableArr #-}
moveArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> A.MArr arr s a -> Int -> Int -> m ()
moveArr :: MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
moveArr MArr arr s a
marr1 Int
s1 MArr arr s a
marr2 Int
s2 Int
l = do
Int
siz1 <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr1
Int
siz2 <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr2
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
s1Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
s2Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
s2Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz2 Bool -> Bool -> Bool
&& (Int
s1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz1)
(MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> MArr arr s a -> Int -> Int -> m ()
A.copyMutableArr MArr arr s a
marr1 Int
s1 MArr arr s a
marr2 Int
s2 Int
l)
{-# INLINE moveArr #-}
cloneArr :: (A.Arr arr a, HasCallStack)
=> arr a -> Int -> Int -> arr a
cloneArr :: arr a -> Int -> Int -> arr a
cloneArr arr a
arr Int
s Int
l = Bool -> arr a -> arr a
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=arr a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr arr a
arr)
(arr a -> Int -> Int -> arr a
forall (arr :: * -> *) a. Arr arr a => arr a -> Int -> Int -> arr a
A.cloneArr arr a
arr Int
s Int
l)
{-# INLINE cloneArr #-}
cloneMutableArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> Int -> m (A.MArr arr s a)
cloneMutableArr :: MArr arr s a -> Int -> Int -> m (MArr arr s a)
cloneMutableArr MArr arr s a
marr Int
s Int
l = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m (MArr arr s a) -> m (MArr arr s a)
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MArr arr s a -> Int -> Int -> m (MArr arr s a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> Int -> m (MArr arr s a)
A.cloneMutableArr MArr arr s a
marr Int
s Int
l)
{-# INLINE cloneMutableArr #-}
resizeMutableArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> m (A.MArr arr s a)
resizeMutableArr :: MArr arr s a -> Int -> m (MArr arr s a)
resizeMutableArr MArr arr s a
marr Int
n = Bool -> m (MArr arr s a) -> m (MArr arr s a)
forall a. HasCallStack => Bool -> a -> a
check
(Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0)
(MArr arr s a -> Int -> m (MArr arr s a)
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> m (MArr arr s a)
A.resizeMutableArr MArr arr s a
marr Int
n)
{-# INLINE resizeMutableArr #-}
shrinkMutableArr :: (A.Arr arr a, PrimMonad m, PrimState m ~ s, HasCallStack)
=> A.MArr arr s a -> Int -> m ()
shrinkMutableArr :: MArr arr s a -> Int -> m ()
shrinkMutableArr MArr arr s a
marr Int
n = do
Int
siz <- MArr arr s a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MArr arr s a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MArr arr s a -> Int -> m ()
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> Int -> m ()
A.shrinkMutableArr MArr arr s a
marr Int
n)
{-# INLINE shrinkMutableArr #-}
newPinnedPrimArray :: (PrimMonad m, Prim a, HasCallStack)
=> Int -> m (A.MutablePrimArray (PrimState m) a)
{-# INLINE newPinnedPrimArray #-}
newPinnedPrimArray :: Int -> m (MutablePrimArray (PrimState m) a)
newPinnedPrimArray Int
n =
Bool
-> m (MutablePrimArray (PrimState m) a)
-> m (MutablePrimArray (PrimState m) a)
forall a. HasCallStack => Bool -> a -> a
check (Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0) (Int -> m (MutablePrimArray (PrimState m) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
A.newPinnedPrimArray Int
n)
newAlignedPinnedPrimArray :: (PrimMonad m, Prim a, HasCallStack)
=> Int -> m (A.MutablePrimArray (PrimState m) a)
{-# INLINE newAlignedPinnedPrimArray #-}
newAlignedPinnedPrimArray :: Int -> m (MutablePrimArray (PrimState m) a)
newAlignedPinnedPrimArray Int
n =
Bool
-> m (MutablePrimArray (PrimState m) a)
-> m (MutablePrimArray (PrimState m) a)
forall a. HasCallStack => Bool -> a -> a
check (Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0) (Int -> m (MutablePrimArray (PrimState m) a)
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Int -> m (MutablePrimArray (PrimState m) a)
A.newAlignedPinnedPrimArray Int
n)
copyPrimArrayToPtr :: (PrimMonad m, Prim a, HasCallStack)
=> Ptr a
-> A.PrimArray a
-> Int
-> Int
-> m ()
{-# INLINE copyPrimArrayToPtr #-}
copyPrimArrayToPtr :: Ptr a -> PrimArray a -> Int -> Int -> m ()
copyPrimArrayToPtr Ptr a
ptr PrimArray a
arr Int
s Int
l = Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=PrimArray a -> Int
forall (arr :: * -> *) a. Arr arr a => arr a -> Int
A.sizeofArr PrimArray a
arr)
(Ptr a -> PrimArray a -> Int -> Int -> m ()
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Ptr a -> PrimArray a -> Int -> Int -> m ()
A.copyPrimArrayToPtr Ptr a
ptr PrimArray a
arr Int
s Int
l)
copyMutablePrimArrayToPtr :: (PrimMonad m, Prim a, HasCallStack)
=> Ptr a
-> A.MutablePrimArray (PrimState m) a
-> Int
-> Int
-> m ()
{-# INLINE copyMutablePrimArrayToPtr #-}
copyMutablePrimArrayToPtr :: Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m ()
copyMutablePrimArrayToPtr Ptr a
ptr MutablePrimArray (PrimState m) a
marr Int
s Int
l = do
Int
siz <- MArr PrimArray (PrimState m) a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MutablePrimArray (PrimState m) a
MArr PrimArray (PrimState m) a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m ()
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m ()
A.copyMutablePrimArrayToPtr Ptr a
ptr MutablePrimArray (PrimState m) a
marr Int
s Int
l)
copyPtrToMutablePrimArray :: (PrimMonad m, Prim a, HasCallStack)
=> A.MutablePrimArray (PrimState m) a
-> Int
-> Ptr a
-> Int
-> m ()
{-# INLINE copyPtrToMutablePrimArray #-}
copyPtrToMutablePrimArray :: MutablePrimArray (PrimState m) a -> Int -> Ptr a -> Int -> m ()
copyPtrToMutablePrimArray MutablePrimArray (PrimState m) a
marr Int
s Ptr a
ptr Int
l = do
Int
siz <- MArr PrimArray (PrimState m) a -> m Int
forall (arr :: * -> *) a (m :: * -> *) s.
(Arr arr a, PrimMonad m, PrimState m ~ s) =>
MArr arr s a -> m Int
A.sizeofMutableArr MutablePrimArray (PrimState m) a
MArr PrimArray (PrimState m) a
marr
Bool -> m () -> m ()
forall a. HasCallStack => Bool -> a -> a
check
(Int
sInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& Int
lInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>=Int
0 Bool -> Bool -> Bool
&& (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l)Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
siz)
(MutablePrimArray (PrimState m) a -> Int -> Ptr a -> Int -> m ()
forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutablePrimArray (PrimState m) a -> Int -> Ptr a -> Int -> m ()
A.copyPtrToMutablePrimArray MutablePrimArray (PrimState m) a
marr Int
s Ptr a
ptr Int
l)