{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Massiv.Array.Manifest.Boxed
( B(..)
, BL(..)
, BN(..)
, N
, pattern N
, Array(..)
, MArray(..)
, wrapLazyArray
, unwrapLazyArray
, unwrapNormalForm
, evalNormalForm
, unwrapArray
, evalArray
, toLazyArray
, evalLazyArray
, forceLazyArray
, unwrapMutableArray
, unwrapMutableLazyArray
, evalMutableArray
, unwrapNormalFormArray
, evalNormalFormArray
, unwrapNormalFormMutableArray
, evalNormalFormMutableArray
, toBoxedVector
, toBoxedMVector
, fromBoxedVector
, fromBoxedMVector
, evalBoxedVector
, evalBoxedMVector
, evalNormalBoxedVector
, evalNormalBoxedMVector
, coerceBoxedArray
, coerceNormalBoxedArray
, seqArray
, deepseqArray
) where
import Control.DeepSeq (NFData(..), deepseq)
import Control.Exception
import Control.Monad ((>=>))
import Control.Monad.Primitive
import qualified Data.Foldable as F (Foldable(..))
import Data.Massiv.Array.Delayed.Pull (D)
import Data.Massiv.Array.Delayed.Push (DL)
import Data.Massiv.Array.Delayed.Stream (DS)
import Data.Massiv.Array.Manifest.Internal (compute, computeAs)
import Data.Massiv.Array.Manifest.List as L
import Data.Massiv.Array.Mutable
import Data.Massiv.Array.Ops.Fold
import Data.Massiv.Array.Ops.Fold.Internal
import Data.Massiv.Array.Ops.Map (traverseA)
import Data.Massiv.Core.Common
import Data.Massiv.Core.List
import Data.Massiv.Core.Operations
import Data.Massiv.Vector.Stream as S (isteps, steps)
import qualified Data.Primitive.Array as A
import qualified Data.Vector as VB
import qualified Data.Vector.Mutable as MVB
import GHC.Exts as GHC
import Prelude hiding (mapM, replicate)
import System.IO.Unsafe (unsafePerformIO)
#if !MIN_VERSION_vector(0,13,0)
import Unsafe.Coerce (unsafeCoerce)
#endif
#include "massiv.h"
data BL = BL deriving Int -> BL -> ShowS
[BL] -> ShowS
BL -> String
(Int -> BL -> ShowS)
-> (BL -> String) -> ([BL] -> ShowS) -> Show BL
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BL -> ShowS
showsPrec :: Int -> BL -> ShowS
$cshow :: BL -> String
show :: BL -> String
$cshowList :: [BL] -> ShowS
showList :: [BL] -> ShowS
Show
data instance Array BL ix e = BLArray { forall ix e. Array BL ix e -> Comp
blComp :: !Comp
, forall ix e. Array BL ix e -> Sz ix
blSize :: !(Sz ix)
, forall ix e. Array BL ix e -> Int
blOffset :: {-# UNPACK #-} !Int
, forall ix e. Array BL ix e -> Array e
blData :: {-# UNPACK #-} !(A.Array e)
}
data instance MArray s BL ix e =
MBLArray !(Sz ix) {-# UNPACK #-} !Int {-# UNPACK #-} !(A.MutableArray s e)
instance (Ragged L ix e, Show e) => Show (Array BL ix e) where
showsPrec :: Int -> Array BL ix e -> ShowS
showsPrec = (Array BL ix e -> Array BL ix e) -> Int -> Array BL ix e -> ShowS
forall r r' ix e.
(Ragged L ix e, Load r ix e, Load r' ix e, Source r' e, Show e) =>
(Array r ix e -> Array r' ix e) -> Int -> Array r ix e -> ShowS
showsArrayPrec Array BL ix e -> Array BL ix e
forall a. a -> a
id
showList :: [Array BL ix e] -> ShowS
showList = [Array BL ix e] -> ShowS
forall arr. Show arr => [arr] -> ShowS
showArrayList
instance (Ragged L ix e, Show e) => Show (Array DL ix e) where
showsPrec :: Int -> Array DL ix e -> ShowS
showsPrec = (Array DL ix e -> Array BL ix e) -> Int -> Array DL ix e -> ShowS
forall r r' ix e.
(Ragged L ix e, Load r ix e, Load r' ix e, Source r' e, Show e) =>
(Array r ix e -> Array r' ix e) -> Int -> Array r ix e -> ShowS
showsArrayPrec (BL -> Array DL ix e -> Array BL ix e
forall r e r' ix.
(Manifest r e, Load r' ix e) =>
r -> Array r' ix e -> Array r ix e
computeAs BL
BL)
showList :: [Array DL ix e] -> ShowS
showList = [Array DL ix e] -> ShowS
forall arr. Show arr => [arr] -> ShowS
showArrayList
instance Show e => Show (Array DS Ix1 e) where
showsPrec :: Int -> Array DS Int e -> ShowS
showsPrec = (Array DS Int e -> Array BL Int e)
-> Int -> Array DS Int e -> ShowS
forall r r' ix e.
(Ragged L ix e, Load r ix e, Load r' ix e, Source r' e, Show e) =>
(Array r ix e -> Array r' ix e) -> Int -> Array r ix e -> ShowS
showsArrayPrec (BL -> Array DS Int e -> Array BL Int e
forall r e r' ix.
(Manifest r e, Load r' ix e) =>
r -> Array r' ix e -> Array r ix e
computeAs BL
BL)
showList :: [Array DS Int e] -> ShowS
showList = [Array DS Int e] -> ShowS
forall arr. Show arr => [arr] -> ShowS
showArrayList
instance (Index ix, NFData e) => NFData (Array BL ix e) where
rnf :: Array BL ix e -> ()
rnf = (Array BL ix e -> () -> ()
forall a ix t. (NFData a, Index ix) => Array BL ix a -> t -> t
`deepseqArray` ())
{-# INLINE rnf #-}
instance (Index ix, Eq e) => Eq (Array BL ix e) where
== :: Array BL ix e -> Array BL ix e -> Bool
(==) = (e -> e -> Bool) -> Array BL ix e -> Array BL ix e -> Bool
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Bool) -> Array r1 ix e1 -> Array r2 ix e2 -> Bool
eqArrays e -> e -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE (==) #-}
instance (Index ix, Ord e) => Ord (Array BL ix e) where
compare :: Array BL ix e -> Array BL ix e -> Ordering
compare = (e -> e -> Ordering) -> Array BL ix e -> Array BL ix e -> Ordering
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Ordering)
-> Array r1 ix e1 -> Array r2 ix e2 -> Ordering
compareArrays e -> e -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
{-# INLINE compare #-}
instance Strategy BL where
setComp :: forall ix e. Comp -> Array BL ix e -> Array BL ix e
setComp Comp
c Array BL ix e
arr = Array BL ix e
arr { blComp = c }
{-# INLINE setComp #-}
getComp :: forall ix e. Array BL ix e -> Comp
getComp = Array BL ix e -> Comp
forall ix e. Array BL ix e -> Comp
blComp
{-# INLINE getComp #-}
repr :: BL
repr = BL
BL
instance Source BL e where
unsafeLinearIndex :: forall ix. Index ix => Array BL ix e -> Int -> e
unsafeLinearIndex (BLArray Comp
_ Sz ix
_sz Int
o Array e
a) Int
i =
String
-> (Array e -> Sz1) -> (Array e -> Int -> e) -> Array e -> Int -> e
forall a ix e.
String -> (a -> Sz ix) -> (a -> ix -> e) -> a -> ix -> e
indexAssert String
"BL.unsafeLinearIndex" (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1) -> (Array e -> Int) -> Array e -> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array e -> Int
forall a. Array a -> Int
A.sizeofArray) Array e -> Int -> e
forall a. Array a -> Int -> a
A.indexArray Array e
a (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o)
{-# INLINE unsafeLinearIndex #-}
unsafeOuterSlice :: forall ix.
(Index ix, Index (Lower ix)) =>
Array BL ix e -> Sz (Lower ix) -> Int -> Array BL (Lower ix) e
unsafeOuterSlice (BLArray Comp
c Sz ix
_ Int
o Array e
a) Sz (Lower ix)
szL Int
i = Comp -> Sz (Lower ix) -> Int -> Array e -> Array BL (Lower ix) e
forall ix e. Comp -> Sz ix -> Int -> Array e -> Array BL ix e
BLArray Comp
c Sz (Lower ix)
szL (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Sz (Lower ix) -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz (Lower ix)
szL Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o) Array e
a
{-# INLINE unsafeOuterSlice #-}
unsafeLinearSlice :: forall ix.
Index ix =>
Int -> Sz1 -> Array BL ix e -> Array BL Int e
unsafeLinearSlice Int
i Sz1
k (BLArray Comp
c Sz ix
_ Int
o Array e
a) = Comp -> Sz1 -> Int -> Array e -> Array BL Int e
forall ix e. Comp -> Sz ix -> Int -> Array e -> Array BL ix e
BLArray Comp
c Sz1
k (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i) Array e
a
{-# INLINE unsafeLinearSlice #-}
instance Manifest BL e where
unsafeLinearIndexM :: forall ix. Index ix => Array BL ix e -> Int -> e
unsafeLinearIndexM (BLArray Comp
_ Sz ix
_sz Int
o Array e
a) Int
i =
String
-> (Array e -> Sz1) -> (Array e -> Int -> e) -> Array e -> Int -> e
forall a ix e.
String -> (a -> Sz ix) -> (a -> ix -> e) -> a -> ix -> e
indexAssert String
"BL.unsafeLinearIndexM" (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1) -> (Array e -> Int) -> Array e -> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array e -> Int
forall a. Array a -> Int
A.sizeofArray) Array e -> Int -> e
forall a. Array a -> Int -> a
A.indexArray Array e
a (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o)
{-# INLINE unsafeLinearIndexM #-}
sizeOfMArray :: forall ix s. Index ix => MArray s BL ix e -> Sz ix
sizeOfMArray (MBLArray Sz ix
sz Int
_ MutableArray s e
_) = Sz ix
sz
{-# INLINE sizeOfMArray #-}
unsafeResizeMArray :: forall ix' ix s.
(Index ix', Index ix) =>
Sz ix' -> MArray s BL ix e -> MArray s BL ix' e
unsafeResizeMArray Sz ix'
sz (MBLArray Sz ix
_ Int
off MutableArray s e
marr) = Sz ix' -> Int -> MutableArray s e -> MArray s BL ix' e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray Sz ix'
sz Int
off MutableArray s e
marr
{-# INLINE unsafeResizeMArray #-}
unsafeLinearSliceMArray :: forall ix s.
Index ix =>
Int -> Sz1 -> MArray s BL ix e -> MVector s BL e
unsafeLinearSliceMArray Int
i Sz1
k (MBLArray Sz ix
_ Int
o MutableArray s e
a) = Sz1 -> Int -> MutableArray s e -> MArray s BL Int e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray Sz1
k (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o) MutableArray s e
a
{-# INLINE unsafeLinearSliceMArray #-}
unsafeThaw :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Array BL ix e -> m (MArray (PrimState m) BL ix e)
unsafeThaw (BLArray Comp
_ Sz ix
sz Int
o Array e
a) = Sz ix
-> Int
-> MutableArray (PrimState m) e
-> MArray (PrimState m) BL ix e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray Sz ix
sz Int
o (MutableArray (PrimState m) e -> MArray (PrimState m) BL ix e)
-> m (MutableArray (PrimState m) e)
-> m (MArray (PrimState m) BL ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array e -> m (MutableArray (PrimState m) e)
forall (m :: * -> *) a.
PrimMonad m =>
Array a -> m (MutableArray (PrimState m) a)
A.unsafeThawArray Array e
a
{-# INLINE unsafeThaw #-}
unsafeFreeze :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
unsafeFreeze Comp
comp (MBLArray Sz ix
sz Int
o MutableArray (PrimState m) e
ma) = Comp -> Sz ix -> Int -> Array e -> Array BL ix e
forall ix e. Comp -> Sz ix -> Int -> Array e -> Array BL ix e
BLArray Comp
comp Sz ix
sz Int
o (Array e -> Array BL ix e) -> m (Array e) -> m (Array BL ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MutableArray (PrimState m) e -> m (Array e)
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> m (Array a)
A.unsafeFreezeArray MutableArray (PrimState m) e
ma
{-# INLINE unsafeFreeze #-}
unsafeNew :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) BL ix e)
unsafeNew Sz ix
sz = Sz ix
-> Int
-> MutableArray (PrimState m) e
-> MArray (PrimState m) BL ix e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray Sz ix
sz Int
0 (MutableArray (PrimState m) e -> MArray (PrimState m) BL ix e)
-> m (MutableArray (PrimState m) e)
-> m (MArray (PrimState m) BL ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> e -> m (MutableArray (PrimState m) e)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
A.newArray (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz) e
forall a. a
uninitialized
{-# INLINE unsafeNew #-}
initialize :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> m ()
initialize MArray (PrimState m) BL ix e
_ = () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE initialize #-}
newMArray :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BL ix e)
newMArray Sz ix
sz e
e = Sz ix
-> Int
-> MutableArray (PrimState m) e
-> MArray (PrimState m) BL ix e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray Sz ix
sz Int
0 (MutableArray (PrimState m) e -> MArray (PrimState m) BL ix e)
-> m (MutableArray (PrimState m) e)
-> m (MArray (PrimState m) BL ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> e -> m (MutableArray (PrimState m) e)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> a -> m (MutableArray (PrimState m) a)
A.newArray (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz) e
e
{-# INLINE newMArray #-}
unsafeLinearRead :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> m e
unsafeLinearRead (MBLArray Sz ix
_ Int
o MutableArray (PrimState m) e
ma) Int
i =
String
-> (MutableArray (PrimState m) e -> Sz1)
-> (MutableArray (PrimState m) e -> Int -> m e)
-> MutableArray (PrimState m) e
-> Int
-> m e
forall a ix e.
String -> (a -> Sz ix) -> (a -> ix -> e) -> a -> ix -> e
indexAssert String
"B.unsafeLinearRead" (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1)
-> (MutableArray (PrimState m) e -> Int)
-> MutableArray (PrimState m) e
-> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutableArray (PrimState m) e -> Int
forall s a. MutableArray s a -> Int
A.sizeofMutableArray) MutableArray (PrimState m) e -> Int -> m e
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> m a
A.readArray MutableArray (PrimState m) e
ma (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o)
{-# INLINE unsafeLinearRead #-}
unsafeLinearWrite :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> e -> m ()
unsafeLinearWrite (MBLArray Sz ix
_sz Int
o MutableArray (PrimState m) e
ma) Int
i =
String
-> (MutableArray (PrimState m) e -> Sz1)
-> (MutableArray (PrimState m) e -> Int -> e -> m ())
-> MutableArray (PrimState m) e
-> Int
-> e
-> m ()
forall a ix e.
String -> (a -> Sz ix) -> (a -> ix -> e) -> a -> ix -> e
indexAssert String
"B.unsafeLinearWrite" (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1)
-> (MutableArray (PrimState m) e -> Int)
-> MutableArray (PrimState m) e
-> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutableArray (PrimState m) e -> Int
forall s a. MutableArray s a -> Int
A.sizeofMutableArray) MutableArray (PrimState m) e -> Int -> e -> m ()
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> a -> m ()
A.writeArray MutableArray (PrimState m) e
ma (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o)
{-# INLINE unsafeLinearWrite #-}
instance Size BL where
size :: forall ix e. Array BL ix e -> Sz ix
size = Array BL ix e -> Sz ix
forall ix e. Array BL ix e -> Sz ix
blSize
{-# INLINE size #-}
unsafeResize :: forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array BL ix e -> Array BL ix' e
unsafeResize !Sz ix'
sz !Array BL ix e
arr = Array BL ix e
arr { blSize = sz }
{-# INLINE unsafeResize #-}
instance Index ix => Shape BL ix where
maxLinearSize :: forall e. Array BL ix e -> Maybe Sz1
maxLinearSize = Sz1 -> Maybe Sz1
forall a. a -> Maybe a
Just (Sz1 -> Maybe Sz1)
-> (Array BL ix e -> Sz1) -> Array BL ix e -> Maybe Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1) -> (Array BL ix e -> Int) -> Array BL ix e -> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BL ix e -> Int
forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount
{-# INLINE maxLinearSize #-}
instance Index ix => Load BL ix e where
makeArray :: Comp -> Sz ix -> (ix -> e) -> Array BL ix e
makeArray Comp
comp Sz ix
sz ix -> e
f = Array D ix e -> Array BL ix e
forall r ix e r'.
(Manifest r e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Comp -> Sz ix -> (ix -> e) -> Array D ix e
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray Comp
comp Sz ix
sz ix -> e
f :: Array D ix e)
{-# INLINE makeArray #-}
makeArrayLinear :: Comp -> Sz ix -> (Int -> e) -> Array BL ix e
makeArrayLinear !Comp
comp !Sz ix
sz Int -> e
f = IO (Array BL ix e) -> Array BL ix e
forall a. IO a -> a
unsafePerformIO (IO (Array BL ix e) -> Array BL ix e)
-> IO (Array BL ix e) -> Array BL ix e
forall a b. (a -> b) -> a -> b
$ Comp -> Sz ix -> (Int -> IO e) -> IO (Array BL ix e)
forall r ix e (m :: * -> *).
(MonadUnliftIO m, Manifest r e, Index ix) =>
Comp -> Sz ix -> (Int -> m e) -> m (Array r ix e)
generateArrayLinear Comp
comp Sz ix
sz (e -> IO e
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> IO e) -> (Int -> e) -> Int -> IO e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e
f)
{-# INLINE makeArrayLinear #-}
replicate :: Comp -> Sz ix -> e -> Array BL ix e
replicate Comp
comp Sz ix
sz e
e = (forall s. ST s (Array BL ix e)) -> Array BL ix e
forall a. (forall s. ST s a) -> a
runST (Sz ix -> e -> ST s (MArray (PrimState (ST s)) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BL ix e)
newMArray Sz ix
sz e
e ST s (MArray s BL ix e)
-> (MArray s BL ix e -> ST s (Array BL ix e))
-> ST s (Array BL ix e)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Comp -> MArray (PrimState (ST s)) BL ix e -> ST s (Array BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
unsafeFreeze Comp
comp)
{-# INLINE replicate #-}
iterArrayLinearST_ :: forall s.
Scheduler s () -> Array BL ix e -> (Int -> e -> ST s ()) -> ST s ()
iterArrayLinearST_ !Scheduler s ()
scheduler !Array BL ix e
arr =
Scheduler s ()
-> Int -> (Int -> e) -> (Int -> e -> ST s ()) -> ST s ()
forall s (m :: * -> *) b.
MonadPrimBase s m =>
Scheduler s () -> Int -> (Int -> b) -> (Int -> b -> m ()) -> m ()
splitLinearlyWith_ Scheduler s ()
scheduler (Array BL ix e -> Int
forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Array BL ix e
arr) (Array BL ix e -> Int -> e
forall ix. Index ix => Array BL ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Array BL ix e
arr)
{-# INLINE iterArrayLinearST_ #-}
instance Index ix => StrideLoad BL ix e
instance Index ix => Stream BL ix e where
toStream :: Array BL ix e -> Steps Id e
toStream = Array BL ix e -> Steps Id e
forall r ix e (m :: * -> *).
(Monad m, Index ix, Source r e) =>
Array r ix e -> Steps m e
S.steps
{-# INLINE toStream #-}
toStreamIx :: Array BL ix e -> Steps Id (ix, e)
toStreamIx = Array BL ix e -> Steps Id (ix, e)
forall r ix e (m :: * -> *).
(Monad m, Index ix, Source r e) =>
Array r ix e -> Steps m (ix, e)
S.isteps
{-# INLINE toStreamIx #-}
instance Index ix => Foldable (Array BL ix) where
fold :: forall m. Monoid m => Array BL ix m -> m
fold = Array BL ix m -> m
forall e ix r.
(Monoid e, Index ix, Source r e) =>
Array r ix e -> e
fold
{-# INLINE fold #-}
foldMap :: forall m a. Monoid m => (a -> m) -> Array BL ix a -> m
foldMap = (a -> m) -> Array BL ix a -> m
forall ix r e m.
(Index ix, Source r e, Monoid m) =>
(e -> m) -> Array r ix e -> m
foldMono
{-# INLINE foldMap #-}
foldl :: forall b a. (b -> a -> b) -> b -> Array BL ix a -> b
foldl = (b -> a -> b) -> b -> Array BL ix a -> b
forall ix r e a.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> Array r ix e -> a
lazyFoldlS
{-# INLINE foldl #-}
foldl' :: forall b a. (b -> a -> b) -> b -> Array BL ix a -> b
foldl' = (b -> a -> b) -> b -> Array BL ix a -> b
forall ix r e a.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> Array r ix e -> a
foldlS
{-# INLINE foldl' #-}
foldr :: forall a b. (a -> b -> b) -> b -> Array BL ix a -> b
foldr = (a -> b -> b) -> b -> Array BL ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrFB
{-# INLINE foldr #-}
foldr' :: forall a b. (a -> b -> b) -> b -> Array BL ix a -> b
foldr' = (a -> b -> b) -> b -> Array BL ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrS
{-# INLINE foldr' #-}
null :: forall a. Array BL ix a -> Bool
null (BLArray Comp
_ Sz ix
sz Int
_ Array a
_) = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
{-# INLINE null #-}
length :: forall a. Array BL ix a -> Int
length = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem (Sz ix -> Int) -> (Array BL ix a -> Sz ix) -> Array BL ix a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BL ix a -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array BL ix e -> Sz ix
size
{-# INLINE length #-}
toList :: forall a. Array BL ix a -> [a]
toList Array BL ix a
arr = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\ a -> b -> b
c b
n -> (a -> b -> b) -> b -> Array BL ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrFB a -> b -> b
c b
n Array BL ix a
arr)
{-# INLINE toList #-}
instance Index ix => Functor (Array BL ix) where
fmap :: forall a b. (a -> b) -> Array BL ix a -> Array BL ix b
fmap a -> b
f Array BL ix a
arr = Comp -> Sz ix -> (Int -> b) -> Array BL ix b
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (Int -> e) -> Array r ix e
makeArrayLinear (Array BL ix a -> Comp
forall ix e. Array BL ix e -> Comp
blComp Array BL ix a
arr) (Array BL ix a -> Sz ix
forall ix e. Array BL ix e -> Sz ix
blSize Array BL ix a
arr) (a -> b
f (a -> b) -> (Int -> a) -> Int -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BL ix a -> Int -> a
forall ix. Index ix => Array BL ix a -> Int -> a
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Array BL ix a
arr)
{-# INLINE fmap #-}
<$ :: forall a b. a -> Array BL ix b -> Array BL ix a
(<$) a
e Array BL ix b
arr = Comp -> Sz ix -> a -> Array BL ix a
forall r ix e. Load r ix e => Comp -> Sz ix -> e -> Array r ix e
replicate (Array BL ix b -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array BL ix e -> Comp
getComp Array BL ix b
arr) (Array BL ix b -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array BL ix e -> Sz ix
size Array BL ix b
arr) a
e
{-# INLINE (<$) #-}
instance Index ix => Traversable (Array BL ix) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Array BL ix a -> f (Array BL ix b)
traverse = (a -> f b) -> Array BL ix a -> f (Array BL ix b)
forall r ix e r' a (f :: * -> *).
(Source r' a, Manifest r e, Index ix, Applicative f) =>
(a -> f e) -> Array r' ix a -> f (Array r ix e)
traverseA
{-# INLINE traverse #-}
instance (IsList (Array L ix e), Ragged L ix e) => IsList (Array BL ix e) where
type Item (Array BL ix e) = Item (Array L ix e)
fromList :: [Item (Array BL ix e)] -> Array BL ix e
fromList = Comp -> [ListItem ix e] -> Array BL ix e
forall r ix e.
(HasCallStack, Ragged L ix e, Manifest r e) =>
Comp -> [ListItem ix e] -> Array r ix e
L.fromLists' Comp
Seq
{-# INLINE fromList #-}
toList :: Array BL ix e -> [Item (Array BL ix e)]
toList = Array L ix e -> [Item (Array L ix e)]
Array L ix e -> [ListItem ix e]
forall l. IsList l => l -> [Item l]
GHC.toList (Array L ix e -> [ListItem ix e])
-> (Array BL ix e -> Array L ix e)
-> Array BL ix e
-> [ListItem ix e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BL ix e -> Array L ix e
forall ix e r.
(Ragged L ix e, Shape r ix, Source r e) =>
Array r ix e -> Array L ix e
toListArray
{-# INLINE toList #-}
instance Num e => FoldNumeric BL e where
unsafeDotProduct :: forall ix. Index ix => Array BL ix e -> Array BL ix e -> e
unsafeDotProduct = Array BL ix e -> Array BL ix e -> e
forall e ix r.
(Num e, Index ix, Source r e) =>
Array r ix e -> Array r ix e -> e
defaultUnsafeDotProduct
{-# INLINE unsafeDotProduct #-}
powerSumArray :: forall ix. Index ix => Array BL ix e -> Int -> e
powerSumArray = Array BL ix e -> Int -> e
forall ix r e.
(Index ix, Source r e, Num e) =>
Array r ix e -> Int -> e
defaultPowerSumArray
{-# INLINE powerSumArray #-}
foldArray :: forall ix. Index ix => (e -> e -> e) -> e -> Array BL ix e -> e
foldArray = (e -> e -> e) -> e -> Array BL ix e -> e
forall ix r e.
(Index ix, Source r e) =>
(e -> e -> e) -> e -> Array r ix e -> e
defaultFoldArray
{-# INLINE foldArray #-}
instance Num e => Numeric BL e where
unsafeLiftArray :: forall ix. Index ix => (e -> e) -> Array BL ix e -> Array BL ix e
unsafeLiftArray = (e -> e) -> Array BL ix e -> Array BL ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e) -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray
{-# INLINE unsafeLiftArray #-}
unsafeLiftArray2 :: forall ix.
Index ix =>
(e -> e -> e) -> Array BL ix e -> Array BL ix e -> Array BL ix e
unsafeLiftArray2 = (e -> e -> e) -> Array BL ix e -> Array BL ix e -> Array BL ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray2
{-# INLINE unsafeLiftArray2 #-}
data B = B deriving Int -> B -> ShowS
[B] -> ShowS
B -> String
(Int -> B -> ShowS) -> (B -> String) -> ([B] -> ShowS) -> Show B
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> B -> ShowS
showsPrec :: Int -> B -> ShowS
$cshow :: B -> String
show :: B -> String
$cshowList :: [B] -> ShowS
showList :: [B] -> ShowS
Show
newtype instance Array B ix e = BArray (Array BL ix e)
newtype instance MArray s B ix e = MBArray (MArray s BL ix e)
instance (Ragged L ix e, Show e) => Show (Array B ix e) where
showsPrec :: Int -> Array B ix e -> ShowS
showsPrec = (Array B ix e -> Array B ix e) -> Int -> Array B ix e -> ShowS
forall r r' ix e.
(Ragged L ix e, Load r ix e, Load r' ix e, Source r' e, Show e) =>
(Array r ix e -> Array r' ix e) -> Int -> Array r ix e -> ShowS
showsArrayPrec Array B ix e -> Array B ix e
forall a. a -> a
id
showList :: [Array B ix e] -> ShowS
showList = [Array B ix e] -> ShowS
forall arr. Show arr => [arr] -> ShowS
showArrayList
instance (Index ix, NFData e) => NFData (Array B ix e) where
rnf :: Array B ix e -> ()
rnf = (Array BL ix e -> () -> ()
forall a ix t. (NFData a, Index ix) => Array BL ix a -> t -> t
`deepseqArray` ()) (Array BL ix e -> ())
-> (Array B ix e -> Array BL ix e) -> Array B ix e -> ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE rnf #-}
instance (Index ix, Eq e) => Eq (Array B ix e) where
== :: Array B ix e -> Array B ix e -> Bool
(==) = (e -> e -> Bool) -> Array B ix e -> Array B ix e -> Bool
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Bool) -> Array r1 ix e1 -> Array r2 ix e2 -> Bool
eqArrays e -> e -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE (==) #-}
instance (Index ix, Ord e) => Ord (Array B ix e) where
compare :: Array B ix e -> Array B ix e -> Ordering
compare = (e -> e -> Ordering) -> Array B ix e -> Array B ix e -> Ordering
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Ordering)
-> Array r1 ix e1 -> Array r2 ix e2 -> Ordering
compareArrays e -> e -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
{-# INLINE compare #-}
instance Source B e where
unsafeLinearIndex :: forall ix. Index ix => Array B ix e -> Int -> e
unsafeLinearIndex Array B ix e
arr = Array BL ix e -> Int -> e
forall ix. Index ix => Array BL ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex (Array B ix e -> Array BL ix e
forall ix e. Array B ix e -> Array BL ix e
toLazyArray Array B ix e
arr)
{-# INLINE unsafeLinearIndex #-}
unsafeLinearSlice :: forall ix. Index ix => Int -> Sz1 -> Array B ix e -> Array B Int e
unsafeLinearSlice Int
i Sz1
k Array B ix e
arr = Array BL Int e -> Array B Int e
forall a b. Coercible a b => a -> b
coerce (Int -> Sz1 -> Array BL ix e -> Array BL Int e
forall ix.
Index ix =>
Int -> Sz1 -> Array BL ix e -> Array BL Int e
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i Sz1
k (Array B ix e -> Array BL ix e
forall ix e. Array B ix e -> Array BL ix e
toLazyArray Array B ix e
arr))
{-# INLINE unsafeLinearSlice #-}
unsafeOuterSlice :: forall ix.
(Index ix, Index (Lower ix)) =>
Array B ix e -> Sz (Lower ix) -> Int -> Array B (Lower ix) e
unsafeOuterSlice Array B ix e
arr Sz (Lower ix)
i = (Int -> Array BL (Lower ix) e) -> Int -> Array B (Lower ix) e
forall a b. Coercible a b => a -> b
coerce (Array BL ix e -> Sz (Lower ix) -> Int -> Array BL (Lower ix) e
forall ix.
(Index ix, Index (Lower ix)) =>
Array BL ix e -> Sz (Lower ix) -> Int -> Array BL (Lower ix) e
forall r e ix.
(Source r e, Index ix, Index (Lower ix)) =>
Array r ix e -> Sz (Lower ix) -> Int -> Array r (Lower ix) e
unsafeOuterSlice (Array B ix e -> Array BL ix e
forall ix e. Array B ix e -> Array BL ix e
toLazyArray Array B ix e
arr) Sz (Lower ix)
i)
{-# INLINE unsafeOuterSlice #-}
instance Strategy B where
getComp :: forall ix e. Array B ix e -> Comp
getComp = Array BL ix e -> Comp
forall ix e. Array BL ix e -> Comp
blComp (Array BL ix e -> Comp)
-> (Array B ix e -> Array BL ix e) -> Array B ix e -> Comp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE getComp #-}
setComp :: forall ix e. Comp -> Array B ix e -> Array B ix e
setComp Comp
c Array B ix e
arr = Array BL ix e -> Array B ix e
forall ix e. Array BL ix e -> Array B ix e
coerceBoxedArray (Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce Array B ix e
arr) { blComp = c }
{-# INLINE setComp #-}
repr :: B
repr = B
B
instance Index ix => Shape B ix where
maxLinearSize :: forall e. Array B ix e -> Maybe Sz1
maxLinearSize = Sz1 -> Maybe Sz1
forall a. a -> Maybe a
Just (Sz1 -> Maybe Sz1)
-> (Array B ix e -> Sz1) -> Array B ix e -> Maybe Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1) -> (Array B ix e -> Int) -> Array B ix e -> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Int
forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount
{-# INLINE maxLinearSize #-}
instance Size B where
size :: forall ix e. Array B ix e -> Sz ix
size = Array BL ix e -> Sz ix
forall ix e. Array BL ix e -> Sz ix
blSize (Array BL ix e -> Sz ix)
-> (Array B ix e -> Array BL ix e) -> Array B ix e -> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE size #-}
unsafeResize :: forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array B ix e -> Array B ix' e
unsafeResize Sz ix'
sz = (Array BL ix e -> Array BL ix' e) -> Array B ix e -> Array B ix' e
forall a b. Coercible a b => a -> b
coerce (\Array BL ix e
arr -> Array BL ix e
arr { blSize = sz })
{-# INLINE unsafeResize #-}
instance Manifest B e where
unsafeLinearIndexM :: forall ix. Index ix => Array B ix e -> Int -> e
unsafeLinearIndexM = (Array BL ix e -> Int -> e) -> Array B ix e -> Int -> e
forall a b. Coercible a b => a -> b
coerce Array BL ix e -> Int -> e
forall ix. Index ix => Array BL ix e -> Int -> e
forall r e ix. (Manifest r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndexM
{-# INLINE unsafeLinearIndexM #-}
sizeOfMArray :: forall ix s. Index ix => MArray s B ix e -> Sz ix
sizeOfMArray = MArray s BL ix e -> Sz ix
forall ix s. Index ix => MArray s BL ix e -> Sz ix
forall r e ix s.
(Manifest r e, Index ix) =>
MArray s r ix e -> Sz ix
sizeOfMArray (MArray s BL ix e -> Sz ix)
-> (MArray s B ix e -> MArray s BL ix e)
-> MArray s B ix e
-> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s B ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE sizeOfMArray #-}
unsafeResizeMArray :: forall ix' ix s.
(Index ix', Index ix) =>
Sz ix' -> MArray s B ix e -> MArray s B ix' e
unsafeResizeMArray Sz ix'
sz = MArray s BL ix' e -> MArray s B ix' e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (MArray s BL ix' e -> MArray s B ix' e)
-> (MArray s B ix e -> MArray s BL ix' e)
-> MArray s B ix e
-> MArray s B ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz ix' -> MArray s BL ix e -> MArray s BL ix' e
forall r e ix' ix s.
(Manifest r e, Index ix', Index ix) =>
Sz ix' -> MArray s r ix e -> MArray s r ix' e
forall ix' ix s.
(Index ix', Index ix) =>
Sz ix' -> MArray s BL ix e -> MArray s BL ix' e
unsafeResizeMArray Sz ix'
sz (MArray s BL ix e -> MArray s BL ix' e)
-> (MArray s B ix e -> MArray s BL ix e)
-> MArray s B ix e
-> MArray s BL ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s B ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unsafeResizeMArray #-}
unsafeLinearSliceMArray :: forall ix s.
Index ix =>
Int -> Sz1 -> MArray s B ix e -> MVector s B e
unsafeLinearSliceMArray Int
i Sz1
k = MArray s BL Int e -> MArray s B Int e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (MArray s BL Int e -> MArray s B Int e)
-> (MArray s B ix e -> MArray s BL Int e)
-> MArray s B ix e
-> MArray s B Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1 -> MArray s BL ix e -> MArray s BL Int e
forall ix s.
Index ix =>
Int -> Sz1 -> MArray s BL ix e -> MVector s BL e
forall r e ix s.
(Manifest r e, Index ix) =>
Int -> Sz1 -> MArray s r ix e -> MVector s r e
unsafeLinearSliceMArray Int
i Sz1
k (MArray s BL ix e -> MArray s BL Int e)
-> (MArray s B ix e -> MArray s BL ix e)
-> MArray s B ix e
-> MArray s BL Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s B ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unsafeLinearSliceMArray #-}
unsafeThaw :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Array B ix e -> m (MArray (PrimState m) B ix e)
unsafeThaw Array B ix e
arr = MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) B ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array BL ix e -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Array r ix e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Array BL ix e -> m (MArray (PrimState m) BL ix e)
unsafeThaw (Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce Array B ix e
arr)
{-# INLINE unsafeThaw #-}
unsafeFreeze :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) B ix e -> m (Array B ix e)
unsafeFreeze Comp
comp MArray (PrimState m) B ix e
marr = Array BL ix e -> Array B ix e
forall ix e. Array BL ix e -> Array B ix e
BArray (Array BL ix e -> Array B ix e)
-> m (Array BL ix e) -> m (Array B ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
unsafeFreeze Comp
comp (MArray (PrimState m) B ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) B ix e
marr)
{-# INLINE unsafeFreeze #-}
unsafeNew :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) B ix e)
unsafeNew Sz ix
sz = MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) B ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sz ix -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) BL ix e)
unsafeNew Sz ix
sz
{-# INLINE unsafeNew #-}
initialize :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) B ix e -> m ()
initialize MArray (PrimState m) B ix e
_ = () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE initialize #-}
newMArray :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) B ix e)
newMArray Sz ix
sz !e
e = MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) B ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) B ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sz ix -> e -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BL ix e)
newMArray Sz ix
sz e
e
{-# INLINE newMArray #-}
unsafeLinearRead :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) B ix e -> Int -> m e
unsafeLinearRead MArray (PrimState m) B ix e
ma = MArray (PrimState m) BL ix e -> Int -> m e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> m e
unsafeLinearRead (MArray (PrimState m) B ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) B ix e
ma)
{-# INLINE unsafeLinearRead #-}
unsafeLinearWrite :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) B ix e -> Int -> e -> m ()
unsafeLinearWrite MArray (PrimState m) B ix e
ma Int
i e
e = e
e e -> m () -> m ()
forall a b. a -> b -> b
`seq` MArray (PrimState m) BL ix e -> Int -> e -> m ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> e -> m ()
unsafeLinearWrite (MArray (PrimState m) B ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) B ix e
ma) Int
i e
e
{-# INLINE unsafeLinearWrite #-}
instance Index ix => Load B ix e where
makeArray :: Comp -> Sz ix -> (ix -> e) -> Array B ix e
makeArray Comp
comp Sz ix
sz ix -> e
f = Array D ix e -> Array B ix e
forall r ix e r'.
(Manifest r e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Comp -> Sz ix -> (ix -> e) -> Array D ix e
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray Comp
comp Sz ix
sz ix -> e
f :: Array D ix e)
{-# INLINE makeArray #-}
makeArrayLinear :: Comp -> Sz ix -> (Int -> e) -> Array B ix e
makeArrayLinear !Comp
comp !Sz ix
sz Int -> e
f = IO (Array B ix e) -> Array B ix e
forall a. IO a -> a
unsafePerformIO (IO (Array B ix e) -> Array B ix e)
-> IO (Array B ix e) -> Array B ix e
forall a b. (a -> b) -> a -> b
$ Comp -> Sz ix -> (Int -> IO e) -> IO (Array B ix e)
forall r ix e (m :: * -> *).
(MonadUnliftIO m, Manifest r e, Index ix) =>
Comp -> Sz ix -> (Int -> m e) -> m (Array r ix e)
generateArrayLinear Comp
comp Sz ix
sz (e -> IO e
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> IO e) -> (Int -> e) -> Int -> IO e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e
f)
{-# INLINE makeArrayLinear #-}
replicate :: Comp -> Sz ix -> e -> Array B ix e
replicate Comp
comp Sz ix
sz e
e = (forall s. ST s (Array B ix e)) -> Array B ix e
forall a. (forall s. ST s a) -> a
runST (Sz ix -> e -> ST s (MArray (PrimState (ST s)) B ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) B ix e)
newMArray Sz ix
sz e
e ST s (MArray s B ix e)
-> (MArray s B ix e -> ST s (Array B ix e)) -> ST s (Array B ix e)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Comp -> MArray (PrimState (ST s)) B ix e -> ST s (Array B ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) B ix e -> m (Array B ix e)
unsafeFreeze Comp
comp)
{-# INLINE replicate #-}
iterArrayLinearST_ :: forall s.
Scheduler s () -> Array B ix e -> (Int -> e -> ST s ()) -> ST s ()
iterArrayLinearST_ Scheduler s ()
scheduler = (Array BL ix e -> (Int -> e -> ST s ()) -> ST s ())
-> Array B ix e -> (Int -> e -> ST s ()) -> ST s ()
forall a b. Coercible a b => a -> b
coerce (Scheduler s () -> Array BL ix e -> (Int -> e -> ST s ()) -> ST s ()
forall s.
Scheduler s () -> Array BL ix e -> (Int -> e -> ST s ()) -> ST s ()
forall r ix e s.
Load r ix e =>
Scheduler s () -> Array r ix e -> (Int -> e -> ST s ()) -> ST s ()
iterArrayLinearST_ Scheduler s ()
scheduler)
{-# INLINE iterArrayLinearST_ #-}
instance Index ix => StrideLoad B ix e
instance Index ix => Stream B ix e where
toStream :: Array B ix e -> Steps Id e
toStream = Array B ix e -> Steps Id e
forall r ix e (m :: * -> *).
(Monad m, Index ix, Source r e) =>
Array r ix e -> Steps m e
S.steps
{-# INLINE toStream #-}
toStreamIx :: Array B ix e -> Steps Id (ix, e)
toStreamIx = Array B ix e -> Steps Id (ix, e)
forall r ix e (m :: * -> *).
(Monad m, Index ix, Source r e) =>
Array r ix e -> Steps m (ix, e)
S.isteps
{-# INLINE toStreamIx #-}
instance Index ix => Foldable (Array B ix) where
fold :: forall m. Monoid m => Array B ix m -> m
fold = Array B ix m -> m
forall e ix r.
(Monoid e, Index ix, Source r e) =>
Array r ix e -> e
fold
{-# INLINE fold #-}
foldMap :: forall m a. Monoid m => (a -> m) -> Array B ix a -> m
foldMap = (a -> m) -> Array B ix a -> m
forall ix r e m.
(Index ix, Source r e, Monoid m) =>
(e -> m) -> Array r ix e -> m
foldMono
{-# INLINE foldMap #-}
foldl :: forall b a. (b -> a -> b) -> b -> Array B ix a -> b
foldl = (b -> a -> b) -> b -> Array B ix a -> b
forall ix r e a.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> Array r ix e -> a
lazyFoldlS
{-# INLINE foldl #-}
foldl' :: forall b a. (b -> a -> b) -> b -> Array B ix a -> b
foldl' = (b -> a -> b) -> b -> Array B ix a -> b
forall ix r e a.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> Array r ix e -> a
foldlS
{-# INLINE foldl' #-}
foldr :: forall a b. (a -> b -> b) -> b -> Array B ix a -> b
foldr = (a -> b -> b) -> b -> Array B ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrFB
{-# INLINE foldr #-}
foldr' :: forall a b. (a -> b -> b) -> b -> Array B ix a -> b
foldr' = (a -> b -> b) -> b -> Array B ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrS
{-# INLINE foldr' #-}
null :: forall a. Array B ix a -> Bool
null Array B ix a
arr = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem (Array B ix a -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array B ix e -> Sz ix
size Array B ix a
arr) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
{-# INLINE null #-}
length :: forall a. Array B ix a -> Int
length = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem (Sz ix -> Int) -> (Array B ix a -> Sz ix) -> Array B ix a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix a -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array B ix e -> Sz ix
size
{-# INLINE length #-}
toList :: forall a. Array B ix a -> [a]
toList Array B ix a
arr = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\ a -> b -> b
c b
n -> (a -> b -> b) -> b -> Array B ix a -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrFB a -> b -> b
c b
n Array B ix a
arr)
{-# INLINE toList #-}
instance Index ix => Functor (Array B ix) where
fmap :: forall a b. (a -> b) -> Array B ix a -> Array B ix b
fmap a -> b
f Array B ix a
arr = Comp -> Sz ix -> (Int -> b) -> Array B ix b
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (Int -> e) -> Array r ix e
makeArrayLinear (Array B ix a -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array B ix e -> Comp
getComp Array B ix a
arr) (Array B ix a -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array B ix e -> Sz ix
size Array B ix a
arr) (a -> b
f (a -> b) -> (Int -> a) -> Int -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix a -> Int -> a
forall ix. Index ix => Array B ix a -> Int -> a
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Array B ix a
arr)
{-# INLINE fmap #-}
<$ :: forall a b. a -> Array B ix b -> Array B ix a
(<$) !a
e Array B ix b
arr = Comp -> Sz ix -> a -> Array B ix a
forall r ix e. Load r ix e => Comp -> Sz ix -> e -> Array r ix e
replicate (Array B ix b -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array B ix e -> Comp
getComp Array B ix b
arr) (Array B ix b -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array B ix e -> Sz ix
size Array B ix b
arr) a
e
{-# INLINE (<$) #-}
instance Index ix => Traversable (Array B ix) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Array B ix a -> f (Array B ix b)
traverse = (a -> f b) -> Array B ix a -> f (Array B ix b)
forall r ix e r' a (f :: * -> *).
(Source r' a, Manifest r e, Index ix, Applicative f) =>
(a -> f e) -> Array r' ix a -> f (Array r ix e)
traverseA
{-# INLINE traverse #-}
instance (IsList (Array L ix e), Ragged L ix e) => IsList (Array B ix e) where
type Item (Array B ix e) = Item (Array L ix e)
fromList :: [Item (Array B ix e)] -> Array B ix e
fromList = Comp -> [ListItem ix e] -> Array B ix e
forall r ix e.
(HasCallStack, Ragged L ix e, Manifest r e) =>
Comp -> [ListItem ix e] -> Array r ix e
L.fromLists' Comp
Seq
{-# INLINE fromList #-}
toList :: Array B ix e -> [Item (Array B ix e)]
toList = Array L ix e -> [Item (Array L ix e)]
Array L ix e -> [ListItem ix e]
forall l. IsList l => l -> [Item l]
GHC.toList (Array L ix e -> [ListItem ix e])
-> (Array B ix e -> Array L ix e)
-> Array B ix e
-> [ListItem ix e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Array L ix e
forall ix e r.
(Ragged L ix e, Shape r ix, Source r e) =>
Array r ix e -> Array L ix e
toListArray
{-# INLINE toList #-}
instance Num e => FoldNumeric B e where
unsafeDotProduct :: forall ix. Index ix => Array B ix e -> Array B ix e -> e
unsafeDotProduct = Array B ix e -> Array B ix e -> e
forall e ix r.
(Num e, Index ix, Source r e) =>
Array r ix e -> Array r ix e -> e
defaultUnsafeDotProduct
{-# INLINE unsafeDotProduct #-}
powerSumArray :: forall ix. Index ix => Array B ix e -> Int -> e
powerSumArray = Array B ix e -> Int -> e
forall ix r e.
(Index ix, Source r e, Num e) =>
Array r ix e -> Int -> e
defaultPowerSumArray
{-# INLINE powerSumArray #-}
foldArray :: forall ix. Index ix => (e -> e -> e) -> e -> Array B ix e -> e
foldArray = (e -> e -> e) -> e -> Array B ix e -> e
forall ix r e.
(Index ix, Source r e) =>
(e -> e -> e) -> e -> Array r ix e -> e
defaultFoldArray
{-# INLINE foldArray #-}
instance Num e => Numeric B e where
unsafeLiftArray :: forall ix. Index ix => (e -> e) -> Array B ix e -> Array B ix e
unsafeLiftArray = (e -> e) -> Array B ix e -> Array B ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e) -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray
{-# INLINE unsafeLiftArray #-}
unsafeLiftArray2 :: forall ix.
Index ix =>
(e -> e -> e) -> Array B ix e -> Array B ix e -> Array B ix e
unsafeLiftArray2 = (e -> e -> e) -> Array B ix e -> Array B ix e -> Array B ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray2
{-# INLINE unsafeLiftArray2 #-}
data BN = BN deriving Int -> BN -> ShowS
[BN] -> ShowS
BN -> String
(Int -> BN -> ShowS)
-> (BN -> String) -> ([BN] -> ShowS) -> Show BN
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BN -> ShowS
showsPrec :: Int -> BN -> ShowS
$cshow :: BN -> String
show :: BN -> String
$cshowList :: [BN] -> ShowS
showList :: [BN] -> ShowS
Show
type N = BN
pattern N :: N
pattern $mN :: forall {r}. BN -> ((# #) -> r) -> ((# #) -> r) -> r
$bN :: BN
N = BN
{-# COMPLETE N #-}
{-# DEPRECATED N "In favor of more consistently named `BN`" #-}
newtype instance Array BN ix e = BNArray (Array BL ix e)
newtype instance MArray s BN ix e = MBNArray (MArray s BL ix e)
instance (Ragged L ix e, Show e, NFData e) => Show (Array BN ix e) where
showsPrec :: Int -> Array BN ix e -> ShowS
showsPrec = (Array BN ix e -> Array BL ix e) -> Int -> Array BN ix e -> ShowS
forall r r' ix e.
(Ragged L ix e, Load r ix e, Load r' ix e, Source r' e, Show e) =>
(Array r ix e -> Array r' ix e) -> Int -> Array r ix e -> ShowS
showsArrayPrec Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
showList :: [Array BN ix e] -> ShowS
showList = [Array BN ix e] -> ShowS
forall arr. Show arr => [arr] -> ShowS
showArrayList
instance NFData (Array BN ix e) where
rnf :: Array BN ix e -> ()
rnf = (Array BN ix e -> () -> ()
forall a b. a -> b -> b
`seq` ())
{-# INLINE rnf #-}
instance (Index ix, NFData e, Eq e) => Eq (Array BN ix e) where
== :: Array BN ix e -> Array BN ix e -> Bool
(==) = (e -> e -> Bool) -> Array BN ix e -> Array BN ix e -> Bool
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Bool) -> Array r1 ix e1 -> Array r2 ix e2 -> Bool
eqArrays e -> e -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE (==) #-}
instance (Index ix, NFData e, Ord e) => Ord (Array BN ix e) where
compare :: Array BN ix e -> Array BN ix e -> Ordering
compare = (e -> e -> Ordering) -> Array BN ix e -> Array BN ix e -> Ordering
forall ix r1 e1 r2 e2.
(Index ix, Source r1 e1, Source r2 e2) =>
(e1 -> e2 -> Ordering)
-> Array r1 ix e1 -> Array r2 ix e2 -> Ordering
compareArrays e -> e -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
{-# INLINE compare #-}
instance Strategy BN where
setComp :: forall ix e. Comp -> Array BN ix e -> Array BN ix e
setComp Comp
c = (Array BL ix e -> Array BL ix e) -> Array BN ix e -> Array BN ix e
forall a b. Coercible a b => a -> b
coerce (Comp -> Array BL ix e -> Array BL ix e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array BL ix e -> Array BL ix e
setComp Comp
c)
{-# INLINE setComp #-}
getComp :: forall ix e. Array BN ix e -> Comp
getComp = Array BL ix e -> Comp
forall ix e. Array BL ix e -> Comp
blComp (Array BL ix e -> Comp)
-> (Array BN ix e -> Array BL ix e) -> Array BN ix e -> Comp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE getComp #-}
repr :: BN
repr = BN
BN
instance NFData e => Source BN e where
unsafeLinearIndex :: forall ix. Index ix => Array BN ix e -> Int -> e
unsafeLinearIndex (BNArray Array BL ix e
arr) = Array BL ix e -> Int -> e
forall ix. Index ix => Array BL ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Array BL ix e
arr
{-# INLINE unsafeLinearIndex #-}
unsafeLinearSlice :: forall ix.
Index ix =>
Int -> Sz1 -> Array BN ix e -> Array BN Int e
unsafeLinearSlice Int
i Sz1
k (BNArray Array BL ix e
a) = Array BL Int e -> Array BN Int e
forall a b. Coercible a b => a -> b
coerce (Int -> Sz1 -> Array BL ix e -> Array BL Int e
forall ix.
Index ix =>
Int -> Sz1 -> Array BL ix e -> Array BL Int e
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i Sz1
k Array BL ix e
a)
{-# INLINE unsafeLinearSlice #-}
unsafeOuterSlice :: forall ix.
(Index ix, Index (Lower ix)) =>
Array BN ix e -> Sz (Lower ix) -> Int -> Array BN (Lower ix) e
unsafeOuterSlice (BNArray Array BL ix e
a) Sz (Lower ix)
i = (Int -> Array BL (Lower ix) e) -> Int -> Array BN (Lower ix) e
forall a b. Coercible a b => a -> b
coerce (Array BL ix e -> Sz (Lower ix) -> Int -> Array BL (Lower ix) e
forall ix.
(Index ix, Index (Lower ix)) =>
Array BL ix e -> Sz (Lower ix) -> Int -> Array BL (Lower ix) e
forall r e ix.
(Source r e, Index ix, Index (Lower ix)) =>
Array r ix e -> Sz (Lower ix) -> Int -> Array r (Lower ix) e
unsafeOuterSlice Array BL ix e
a Sz (Lower ix)
i)
{-# INLINE unsafeOuterSlice #-}
instance Index ix => Shape BN ix where
maxLinearSize :: forall e. Array BN ix e -> Maybe Sz1
maxLinearSize = Sz1 -> Maybe Sz1
forall a. a -> Maybe a
Just (Sz1 -> Maybe Sz1)
-> (Array BN ix e -> Sz1) -> Array BN ix e -> Maybe Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Sz1) -> (Array BN ix e -> Int) -> Array BN ix e -> Sz1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Int
forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount
{-# INLINE maxLinearSize #-}
instance Size BN where
size :: forall ix e. Array BN ix e -> Sz ix
size = Array BL ix e -> Sz ix
forall ix e. Array BL ix e -> Sz ix
blSize (Array BL ix e -> Sz ix)
-> (Array BN ix e -> Array BL ix e) -> Array BN ix e -> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE size #-}
unsafeResize :: forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array BN ix e -> Array BN ix' e
unsafeResize !Sz ix'
sz = Array BL ix' e -> Array BN ix' e
forall a b. Coercible a b => a -> b
coerce (Array BL ix' e -> Array BN ix' e)
-> (Array BN ix e -> Array BL ix' e)
-> Array BN ix e
-> Array BN ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz ix' -> Array BL ix e -> Array BL ix' e
forall r ix ix' e.
(Size r, Index ix, Index ix') =>
Sz ix' -> Array r ix e -> Array r ix' e
forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array BL ix e -> Array BL ix' e
unsafeResize Sz ix'
sz (Array BL ix e -> Array BL ix' e)
-> (Array BN ix e -> Array BL ix e)
-> Array BN ix e
-> Array BL ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unsafeResize #-}
instance NFData e => Manifest BN e where
unsafeLinearIndexM :: forall ix. Index ix => Array BN ix e -> Int -> e
unsafeLinearIndexM Array BN ix e
arr = Array BL ix e -> Int -> e
forall ix. Index ix => Array BL ix e -> Int -> e
forall r e ix. (Manifest r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndexM (Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce Array BN ix e
arr)
{-# INLINE unsafeLinearIndexM #-}
sizeOfMArray :: forall ix s. Index ix => MArray s BN ix e -> Sz ix
sizeOfMArray = MArray s BL ix e -> Sz ix
forall ix s. Index ix => MArray s BL ix e -> Sz ix
forall r e ix s.
(Manifest r e, Index ix) =>
MArray s r ix e -> Sz ix
sizeOfMArray (MArray s BL ix e -> Sz ix)
-> (MArray s BN ix e -> MArray s BL ix e)
-> MArray s BN ix e
-> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s BN ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE sizeOfMArray #-}
unsafeResizeMArray :: forall ix' ix s.
(Index ix', Index ix) =>
Sz ix' -> MArray s BN ix e -> MArray s BN ix' e
unsafeResizeMArray Sz ix'
sz = MArray s BL ix' e -> MArray s BN ix' e
forall a b. Coercible a b => a -> b
coerce (MArray s BL ix' e -> MArray s BN ix' e)
-> (MArray s BN ix e -> MArray s BL ix' e)
-> MArray s BN ix e
-> MArray s BN ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz ix' -> MArray s BL ix e -> MArray s BL ix' e
forall r e ix' ix s.
(Manifest r e, Index ix', Index ix) =>
Sz ix' -> MArray s r ix e -> MArray s r ix' e
forall ix' ix s.
(Index ix', Index ix) =>
Sz ix' -> MArray s BL ix e -> MArray s BL ix' e
unsafeResizeMArray Sz ix'
sz (MArray s BL ix e -> MArray s BL ix' e)
-> (MArray s BN ix e -> MArray s BL ix e)
-> MArray s BN ix e
-> MArray s BL ix' e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s BN ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unsafeResizeMArray #-}
unsafeLinearSliceMArray :: forall ix s.
Index ix =>
Int -> Sz1 -> MArray s BN ix e -> MVector s BN e
unsafeLinearSliceMArray Int
i Sz1
k = MArray s BL Int e -> MArray s BN Int e
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (MArray s BL Int e -> MArray s BN Int e)
-> (MArray s BN ix e -> MArray s BL Int e)
-> MArray s BN ix e
-> MArray s BN Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1 -> MArray s BL ix e -> MArray s BL Int e
forall ix s.
Index ix =>
Int -> Sz1 -> MArray s BL ix e -> MVector s BL e
forall r e ix s.
(Manifest r e, Index ix) =>
Int -> Sz1 -> MArray s r ix e -> MVector s r e
unsafeLinearSliceMArray Int
i Sz1
k (MArray s BL ix e -> MArray s BL Int e)
-> (MArray s BN ix e -> MArray s BL ix e)
-> MArray s BN ix e
-> MArray s BL Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s BN ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unsafeLinearSliceMArray #-}
unsafeThaw :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Array BN ix e -> m (MArray (PrimState m) BN ix e)
unsafeThaw Array BN ix e
arr = MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) BN ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array BL ix e -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Array r ix e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Array BL ix e -> m (MArray (PrimState m) BL ix e)
unsafeThaw (Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce Array BN ix e
arr)
{-# INLINE unsafeThaw #-}
unsafeFreeze :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BN ix e -> m (Array BN ix e)
unsafeFreeze Comp
comp MArray (PrimState m) BN ix e
marr = Array BL ix e -> Array BN ix e
forall ix e. Array BL ix e -> Array BN ix e
BNArray (Array BL ix e -> Array BN ix e)
-> m (Array BL ix e) -> m (Array BN ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BL ix e -> m (Array BL ix e)
unsafeFreeze Comp
comp (MArray (PrimState m) BN ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) BN ix e
marr)
{-# INLINE unsafeFreeze #-}
unsafeNew :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) BN ix e)
unsafeNew Sz ix
sz = MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) BN ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sz ix -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) BL ix e)
unsafeNew Sz ix
sz
{-# INLINE unsafeNew #-}
initialize :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BN ix e -> m ()
initialize MArray (PrimState m) BN ix e
_ = () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE initialize #-}
newMArray :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BN ix e)
newMArray Sz ix
sz e
e = e
e e
-> m (MArray (PrimState m) BN ix e)
-> m (MArray (PrimState m) BN ix e)
forall a b. NFData a => a -> b -> b
`deepseq` (MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (MArray (PrimState m) BL ix e -> MArray (PrimState m) BN ix e)
-> m (MArray (PrimState m) BL ix e)
-> m (MArray (PrimState m) BN ix e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sz ix -> e -> m (MArray (PrimState m) BL ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BL ix e)
newMArray Sz ix
sz e
e)
{-# INLINE newMArray #-}
unsafeLinearRead :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BN ix e -> Int -> m e
unsafeLinearRead MArray (PrimState m) BN ix e
ma = MArray (PrimState m) BL ix e -> Int -> m e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> m e
unsafeLinearRead (MArray (PrimState m) BN ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) BN ix e
ma)
{-# INLINE unsafeLinearRead #-}
unsafeLinearWrite :: forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BN ix e -> Int -> e -> m ()
unsafeLinearWrite MArray (PrimState m) BN ix e
ma Int
i e
e = e
e e -> m () -> m ()
forall a b. NFData a => a -> b -> b
`deepseq` MArray (PrimState m) BL ix e -> Int -> e -> m ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) BL ix e -> Int -> e -> m ()
unsafeLinearWrite (MArray (PrimState m) BN ix e -> MArray (PrimState m) BL ix e
forall a b. Coercible a b => a -> b
coerce MArray (PrimState m) BN ix e
ma) Int
i e
e
{-# INLINE unsafeLinearWrite #-}
instance (Index ix, NFData e) => Load BN ix e where
makeArray :: Comp -> Sz ix -> (ix -> e) -> Array BN ix e
makeArray Comp
comp Sz ix
sz ix -> e
f = Array D ix e -> Array BN ix e
forall r ix e r'.
(Manifest r e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Comp -> Sz ix -> (ix -> e) -> Array D ix e
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray Comp
comp Sz ix
sz ix -> e
f :: Array D ix e)
{-# INLINE makeArray #-}
makeArrayLinear :: Comp -> Sz ix -> (Int -> e) -> Array BN ix e
makeArrayLinear !Comp
comp !Sz ix
sz Int -> e
f = IO (Array BN ix e) -> Array BN ix e
forall a. IO a -> a
unsafePerformIO (IO (Array BN ix e) -> Array BN ix e)
-> IO (Array BN ix e) -> Array BN ix e
forall a b. (a -> b) -> a -> b
$ Comp -> Sz ix -> (Int -> IO e) -> IO (Array BN ix e)
forall r ix e (m :: * -> *).
(MonadUnliftIO m, Manifest r e, Index ix) =>
Comp -> Sz ix -> (Int -> m e) -> m (Array r ix e)
generateArrayLinear Comp
comp Sz ix
sz (e -> IO e
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> IO e) -> (Int -> e) -> Int -> IO e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e
f)
{-# INLINE makeArrayLinear #-}
replicate :: Comp -> Sz ix -> e -> Array BN ix e
replicate Comp
comp Sz ix
sz e
e = (forall s. ST s (Array BN ix e)) -> Array BN ix e
forall a. (forall s. ST s a) -> a
runST (Sz ix -> e -> ST s (MArray (PrimState (ST s)) BN ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) BN ix e)
newMArray Sz ix
sz e
e ST s (MArray s BN ix e)
-> (MArray s BN ix e -> ST s (Array BN ix e))
-> ST s (Array BN ix e)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Comp -> MArray (PrimState (ST s)) BN ix e -> ST s (Array BN ix e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BN ix e -> m (Array BN ix e)
unsafeFreeze Comp
comp)
{-# INLINE replicate #-}
iterArrayLinearST_ :: forall s.
Scheduler s () -> Array BN ix e -> (Int -> e -> ST s ()) -> ST s ()
iterArrayLinearST_ !Scheduler s ()
scheduler !Array BN ix e
arr =
Scheduler s ()
-> Int -> (Int -> e) -> (Int -> e -> ST s ()) -> ST s ()
forall s (m :: * -> *) b.
MonadPrimBase s m =>
Scheduler s () -> Int -> (Int -> b) -> (Int -> b -> m ()) -> m ()
splitLinearlyWith_ Scheduler s ()
scheduler (Array BN ix e -> Int
forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Array BN ix e
arr) (Array BN ix e -> Int -> e
forall ix. Index ix => Array BN ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Array BN ix e
arr)
{-# INLINE iterArrayLinearST_ #-}
instance (Index ix, NFData e) => StrideLoad BN ix e
instance (Index ix, NFData e) => Stream BN ix e where
toStream :: Array BN ix e -> Steps Id e
toStream = Array BL ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream (Array BL ix e -> Steps Id e)
-> (Array BN ix e -> Array BL ix e) -> Array BN ix e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE toStream #-}
toStreamIx :: Array BN ix e -> Steps Id (ix, e)
toStreamIx = Array BL ix e -> Steps Id (ix, e)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
toStreamIx (Array BL ix e -> Steps Id (ix, e))
-> (Array BN ix e -> Array BL ix e)
-> Array BN ix e
-> Steps Id (ix, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE toStreamIx #-}
instance (NFData e, IsList (Array L ix e), Ragged L ix e) => IsList (Array BN ix e) where
type Item (Array BN ix e) = Item (Array L ix e)
fromList :: [Item (Array BN ix e)] -> Array BN ix e
fromList = Comp -> [ListItem ix e] -> Array BN ix e
forall r ix e.
(HasCallStack, Ragged L ix e, Manifest r e) =>
Comp -> [ListItem ix e] -> Array r ix e
L.fromLists' Comp
Seq
{-# INLINE fromList #-}
toList :: Array BN ix e -> [Item (Array BN ix e)]
toList = Array L ix e -> [Item (Array L ix e)]
Array L ix e -> [ListItem ix e]
forall l. IsList l => l -> [Item l]
GHC.toList (Array L ix e -> [ListItem ix e])
-> (Array BN ix e -> Array L ix e)
-> Array BN ix e
-> [ListItem ix e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array L ix e
forall ix e r.
(Ragged L ix e, Shape r ix, Source r e) =>
Array r ix e -> Array L ix e
toListArray
{-# INLINE toList #-}
instance (NFData e, Num e) => FoldNumeric BN e where
unsafeDotProduct :: forall ix. Index ix => Array BN ix e -> Array BN ix e -> e
unsafeDotProduct = Array BN ix e -> Array BN ix e -> e
forall e ix r.
(Num e, Index ix, Source r e) =>
Array r ix e -> Array r ix e -> e
defaultUnsafeDotProduct
{-# INLINE unsafeDotProduct #-}
powerSumArray :: forall ix. Index ix => Array BN ix e -> Int -> e
powerSumArray = Array BN ix e -> Int -> e
forall ix r e.
(Index ix, Source r e, Num e) =>
Array r ix e -> Int -> e
defaultPowerSumArray
{-# INLINE powerSumArray #-}
foldArray :: forall ix. Index ix => (e -> e -> e) -> e -> Array BN ix e -> e
foldArray = (e -> e -> e) -> e -> Array BN ix e -> e
forall ix r e.
(Index ix, Source r e) =>
(e -> e -> e) -> e -> Array r ix e -> e
defaultFoldArray
{-# INLINE foldArray #-}
instance (NFData e, Num e) => Numeric BN e where
unsafeLiftArray :: forall ix. Index ix => (e -> e) -> Array BN ix e -> Array BN ix e
unsafeLiftArray = (e -> e) -> Array BN ix e -> Array BN ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e) -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray
{-# INLINE unsafeLiftArray #-}
unsafeLiftArray2 :: forall ix.
Index ix =>
(e -> e -> e) -> Array BN ix e -> Array BN ix e -> Array BN ix e
unsafeLiftArray2 = (e -> e -> e) -> Array BN ix e -> Array BN ix e -> Array BN ix e
forall r ix e.
(Load r ix e, Source r e) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
defaultUnsafeLiftArray2
{-# INLINE unsafeLiftArray2 #-}
uninitialized :: a
uninitialized :: forall a. a
uninitialized = Uninitialized -> a
forall a e. Exception e => e -> a
throw Uninitialized
Uninitialized
unwrapArray :: Array B ix e -> A.Array e
unwrapArray :: forall ix e. Array B ix e -> Array e
unwrapArray = Array BL ix e -> Array e
forall ix e. Array BL ix e -> Array e
blData (Array BL ix e -> Array e)
-> (Array B ix e -> Array BL ix e) -> Array B ix e -> Array e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unwrapArray #-}
evalArray ::
Comp
-> A.Array e
-> Vector B e
evalArray :: forall e. Comp -> Array e -> Vector B e
evalArray Comp
comp Array e
a = Array BL Int e -> Array B Int e
forall ix e. Index ix => Array BL ix e -> Array B ix e
evalLazyArray (Array BL Int e -> Array B Int e)
-> Array BL Int e -> Array B Int e
forall a b. (a -> b) -> a -> b
$ Comp -> Array BL Int e -> Array BL Int e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array BL ix e -> Array BL ix e
setComp Comp
comp (Array BL Int e -> Array BL Int e)
-> Array BL Int e -> Array BL Int e
forall a b. (a -> b) -> a -> b
$ Array e -> Array BL Int e
forall e. Array e -> Vector BL e
wrapLazyArray Array e
a
{-# INLINE evalArray #-}
unwrapLazyArray :: Array BL ix e -> A.Array e
unwrapLazyArray :: forall ix e. Array BL ix e -> Array e
unwrapLazyArray = Array BL ix e -> Array e
forall ix e. Array BL ix e -> Array e
blData
{-# INLINE unwrapLazyArray #-}
wrapLazyArray :: A.Array e -> Vector BL e
wrapLazyArray :: forall e. Array e -> Vector BL e
wrapLazyArray Array e
a = Comp -> Sz1 -> Int -> Array e -> Array BL Int e
forall ix e. Comp -> Sz ix -> Int -> Array e -> Array BL ix e
BLArray Comp
Seq (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Array e -> Int
forall a. Array a -> Int
A.sizeofArray Array e
a)) Int
0 Array e
a
{-# INLINE wrapLazyArray #-}
toLazyArray :: Array B ix e -> Array BL ix e
toLazyArray :: forall ix e. Array B ix e -> Array BL ix e
toLazyArray = Array B ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE toLazyArray #-}
evalLazyArray :: Index ix => Array BL ix e -> Array B ix e
evalLazyArray :: forall ix e. Index ix => Array BL ix e -> Array B ix e
evalLazyArray Array BL ix e
arr = Array BL ix e
arr Array BL ix e -> Array B ix e -> Array B ix e
forall ix a t. Index ix => Array BL ix a -> t -> t
`seqArray` Array BL ix e -> Array B ix e
forall ix e. Array BL ix e -> Array B ix e
BArray Array BL ix e
arr
{-# INLINE evalLazyArray #-}
forceLazyArray :: (NFData e, Index ix) => Array BL ix e -> Array N ix e
forceLazyArray :: forall e ix. (NFData e, Index ix) => Array BL ix e -> Array BN ix e
forceLazyArray Array BL ix e
arr = Array BL ix e
arr Array BL ix e -> Array BN ix e -> Array BN ix e
forall a ix t. (NFData a, Index ix) => Array BL ix a -> t -> t
`deepseqArray` Array BL ix e -> Array BN ix e
forall ix e. Array BL ix e -> Array BN ix e
BNArray Array BL ix e
arr
{-# INLINE forceLazyArray #-}
unwrapMutableArray :: MArray s B ix e -> A.MutableArray s e
unwrapMutableArray :: forall s ix e. MArray s B ix e -> MutableArray s e
unwrapMutableArray (MBArray (MBLArray Sz ix
_ Int
_ MutableArray s e
marr)) = MutableArray s e
marr
{-# INLINE unwrapMutableArray #-}
unwrapMutableLazyArray :: MArray s BL ix e -> A.MutableArray s e
unwrapMutableLazyArray :: forall s ix e. MArray s BL ix e -> MutableArray s e
unwrapMutableLazyArray (MBLArray Sz ix
_ Int
_ MutableArray s e
marr) = MutableArray s e
marr
{-# INLINE unwrapMutableLazyArray #-}
evalMutableArray ::
PrimMonad m
=> A.MutableArray (PrimState m) e
-> m (MArray (PrimState m) B Ix1 e)
evalMutableArray :: forall (m :: * -> *) e.
PrimMonad m =>
MutableArray (PrimState m) e -> m (MArray (PrimState m) B Int e)
evalMutableArray = (MArray (PrimState m) BL Int e -> MArray (PrimState m) B Int e)
-> m (MArray (PrimState m) BL Int e)
-> m (MArray (PrimState m) B Int e)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MArray (PrimState m) BL Int e -> MArray (PrimState m) B Int e
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (m (MArray (PrimState m) BL Int e)
-> m (MArray (PrimState m) B Int e))
-> (MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e))
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) B Int e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> m () -> m ())
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e)
forall (m :: * -> *) e a.
PrimMonad m =>
(e -> m () -> m a)
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e)
fromMutableArraySeq e -> m () -> m ()
forall a b. a -> b -> b
seq
{-# INLINE evalMutableArray #-}
unwrapNormalFormArray :: Array N ix e -> A.Array e
unwrapNormalFormArray :: forall ix e. Array BN ix e -> Array e
unwrapNormalFormArray = Array BL ix e -> Array e
forall ix e. Array BL ix e -> Array e
blData (Array BL ix e -> Array e)
-> (Array BN ix e -> Array BL ix e) -> Array BN ix e -> Array e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array BN ix e -> Array BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unwrapNormalFormArray #-}
evalNormalFormArray ::
NFData e
=> Comp
-> A.Array e
-> Array N Ix1 e
evalNormalFormArray :: forall e. NFData e => Comp -> Array e -> Array BN Int e
evalNormalFormArray Comp
comp = Array BL Int e -> Array BN Int e
forall e ix. (NFData e, Index ix) => Array BL ix e -> Array BN ix e
forceLazyArray (Array BL Int e -> Array BN Int e)
-> (Array e -> Array BL Int e) -> Array e -> Array BN Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comp -> Array BL Int e -> Array BL Int e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array BL ix e -> Array BL ix e
setComp Comp
comp (Array BL Int e -> Array BL Int e)
-> (Array e -> Array BL Int e) -> Array e -> Array BL Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array e -> Array BL Int e
forall e. Array e -> Vector BL e
wrapLazyArray
{-# INLINE evalNormalFormArray #-}
unwrapNormalFormMutableArray :: MArray s N ix e -> A.MutableArray s e
unwrapNormalFormMutableArray :: forall s ix e. MArray s BN ix e -> MutableArray s e
unwrapNormalFormMutableArray = MArray s BL ix e -> MutableArray s e
forall s ix e. MArray s BL ix e -> MutableArray s e
unwrapMutableLazyArray (MArray s BL ix e -> MutableArray s e)
-> (MArray s BN ix e -> MArray s BL ix e)
-> MArray s BN ix e
-> MutableArray s e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MArray s BN ix e -> MArray s BL ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unwrapNormalFormMutableArray #-}
evalNormalFormMutableArray ::
(PrimMonad m, NFData e)
=> A.MutableArray (PrimState m) e
-> m (MArray (PrimState m) N Ix1 e)
evalNormalFormMutableArray :: forall (m :: * -> *) e.
(PrimMonad m, NFData e) =>
MutableArray (PrimState m) e -> m (MArray (PrimState m) BN Int e)
evalNormalFormMutableArray MutableArray (PrimState m) e
marr = MArray (PrimState m) BL Int e -> MArray (PrimState m) BN Int e
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (MArray (PrimState m) BL Int e -> MArray (PrimState m) BN Int e)
-> m (MArray (PrimState m) BL Int e)
-> m (MArray (PrimState m) BN Int e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (e -> m () -> m ())
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e)
forall (m :: * -> *) e a.
PrimMonad m =>
(e -> m () -> m a)
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e)
fromMutableArraySeq e -> m () -> m ()
forall a b. NFData a => a -> b -> b
deepseq MutableArray (PrimState m) e
marr
{-# INLINE evalNormalFormMutableArray #-}
fromMutableArraySeq ::
PrimMonad m
=> (e -> m () -> m a)
-> A.MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Ix1 e)
fromMutableArraySeq :: forall (m :: * -> *) e a.
PrimMonad m =>
(e -> m () -> m a)
-> MutableArray (PrimState m) e
-> m (MArray (PrimState m) BL Int e)
fromMutableArraySeq e -> m () -> m a
with MutableArray (PrimState m) e
ma = do
let !sz :: Int
sz = MutableArray (PrimState m) e -> Int
forall s a. MutableArray s a -> Int
A.sizeofMutableArray MutableArray (PrimState m) e
ma
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m a) -> m ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
0 (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
sz) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (MutableArray (PrimState m) e -> Int -> m e
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> m a
A.readArray MutableArray (PrimState m) e
ma (Int -> m e) -> (e -> m a) -> Int -> m a
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (e -> m () -> m a
`with` () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()))
MArray (PrimState m) BL Int e -> m (MArray (PrimState m) BL Int e)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (MArray (PrimState m) BL Int e
-> m (MArray (PrimState m) BL Int e))
-> MArray (PrimState m) BL Int e
-> m (MArray (PrimState m) BL Int e)
forall a b. (a -> b) -> a -> b
$! Sz1
-> Int
-> MutableArray (PrimState m) e
-> MArray (PrimState m) BL Int e
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
sz) Int
0 MutableArray (PrimState m) e
ma
{-# INLINE fromMutableArraySeq #-}
seqArray :: Index ix => Array BL ix a -> t -> t
seqArray :: forall ix a t. Index ix => Array BL ix a -> t -> t
seqArray !Array BL ix a
arr t
t = (() -> a -> ())
-> () -> (() -> () -> ()) -> () -> Array BL ix a -> ()
forall ix r e a b.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> (b -> a -> b) -> b -> Array r ix e -> b
foldlInternal ((a -> () -> ()) -> () -> a -> ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> () -> ()
forall a b. a -> b -> b
seq) () ((() -> () -> ()) -> () -> () -> ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip () -> () -> ()
forall a b. a -> b -> b
seq) () Array BL ix a
arr () -> t -> t
forall a b. a -> b -> b
`seq` t
t
{-# INLINE seqArray #-}
deepseqArray :: (NFData a, Index ix) => Array BL ix a -> t -> t
deepseqArray :: forall a ix t. (NFData a, Index ix) => Array BL ix a -> t -> t
deepseqArray !Array BL ix a
arr t
t = (() -> a -> ())
-> () -> (() -> () -> ()) -> () -> Array BL ix a -> ()
forall ix r e a b.
(Index ix, Source r e) =>
(a -> e -> a) -> a -> (b -> a -> b) -> b -> Array r ix e -> b
foldlInternal ((a -> () -> ()) -> () -> a -> ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> () -> ()
forall a b. NFData a => a -> b -> b
deepseq) () ((() -> () -> ()) -> () -> () -> ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip () -> () -> ()
forall a b. a -> b -> b
seq) () Array BL ix a
arr () -> t -> t
forall a b. a -> b -> b
`seq` t
t
{-# INLINE deepseqArray #-}
unwrapNormalForm :: Array N ix e -> Array B ix e
unwrapNormalForm :: forall ix e. Array BN ix e -> Array B ix e
unwrapNormalForm = Array BN ix e -> Array B ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE unwrapNormalForm #-}
evalNormalForm :: (Index ix, NFData e) => Array B ix e -> Array N ix e
evalNormalForm :: forall ix e. (Index ix, NFData e) => Array B ix e -> Array BN ix e
evalNormalForm (BArray Array BL ix e
arr) = Array BL ix e
arr Array BL ix e -> Array BN ix e -> Array BN ix e
forall a ix t. (NFData a, Index ix) => Array BL ix a -> t -> t
`deepseqArray` Array BL ix e -> Array BN ix e
forall ix e. Array BL ix e -> Array BN ix e
BNArray Array BL ix e
arr
{-# INLINE evalNormalForm #-}
{-# INLINE toBoxedVector #-}
toBoxedVector :: Index ix => Array BL ix a -> VB.Vector a
toBoxedVector :: forall ix a. Index ix => Array BL ix a -> Vector a
toBoxedVector BLArray{blOffset :: forall ix e. Array BL ix e -> Int
blOffset = Int
off, blSize :: forall ix e. Array BL ix e -> Sz ix
blSize = Sz ix
sz, blData :: forall ix e. Array BL ix e -> Array e
blData = Array a
arr } =
#if MIN_VERSION_vector(0,13,0)
Array a -> Int -> Int -> Vector a
forall a. Array a -> Int -> Int -> Vector a
VB.unsafeFromArraySlice Array a
arr Int
off (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz)
#elif MIN_VERSION_vector(0,12,2)
VB.unsafeTake (totalElem sz) (VB.unsafeDrop off (VB.fromArray arr))
#else
fromVectorCast $ VectorCast off (totalElem sz) arr
fromVectorCast :: VectorCast a -> VB.Vector a
fromVectorCast = unsafeCoerce
#endif
toBoxedMVector :: Index ix => MArray s BL ix a -> MVB.MVector s a
toBoxedMVector :: forall ix s a. Index ix => MArray s BL ix a -> MVector s a
toBoxedMVector (MBLArray Sz ix
sz Int
o MutableArray s a
marr) = Int -> Int -> MutableArray s a -> MVector s a
forall s a. Int -> Int -> MutableArray s a -> MVector s a
MVB.MVector Int
o (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz) MutableArray s a
marr
{-# INLINE toBoxedMVector #-}
evalBoxedVector :: Comp -> VB.Vector a -> Array B Ix1 a
evalBoxedVector :: forall a. Comp -> Vector a -> Array B Int a
evalBoxedVector Comp
comp = Array BL Int a -> Array B Int a
forall ix e. Index ix => Array BL ix e -> Array B ix e
evalLazyArray (Array BL Int a -> Array B Int a)
-> (Vector a -> Array BL Int a) -> Vector a -> Array B Int a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comp -> Array BL Int a -> Array BL Int a
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array BL ix e -> Array BL ix e
setComp Comp
comp (Array BL Int a -> Array BL Int a)
-> (Vector a -> Array BL Int a) -> Vector a -> Array BL Int a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> Array BL Int a
forall a. Vector a -> Vector BL a
fromBoxedVector
{-# INLINE evalBoxedVector #-}
evalBoxedMVector :: PrimMonad m => MVB.MVector (PrimState m) a -> m (MArray (PrimState m) B Ix1 a)
evalBoxedMVector :: forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> m (MArray (PrimState m) B Int a)
evalBoxedMVector (MVB.MVector Int
o Int
k MutableArray (PrimState m) a
ma) =
let marr :: MArray (PrimState m) B Int a
marr = MArray (PrimState m) BL Int a -> MArray (PrimState m) B Int a
forall s ix e. MArray s BL ix e -> MArray s B ix e
MBArray (Sz1
-> Int
-> MutableArray (PrimState m) a
-> MArray (PrimState m) BL Int a
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
k) Int
o MutableArray (PrimState m) a
ma)
in MArray (PrimState m) B Int a
marr MArray (PrimState m) B Int a
-> m () -> m (MArray (PrimState m) B Int a)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m ()) -> m ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
o (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
k) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (MutableArray (PrimState m) a -> Int -> m a
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> m a
A.readArray MutableArray (PrimState m) a
ma (Int -> m a) -> (a -> m ()) -> Int -> m ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (a -> m () -> m ()
forall a b. a -> b -> b
`seq` () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()))
{-# INLINE evalBoxedMVector #-}
fromBoxedVector :: VB.Vector a -> Vector BL a
{-# INLINE fromBoxedVector #-}
fromBoxedVector :: forall a. Vector a -> Vector BL a
fromBoxedVector Vector a
v =
BLArray {blComp :: Comp
blComp = Comp
Seq, blSize :: Sz1
blSize = Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
n, blOffset :: Int
blOffset = Int
offset, blData :: Array a
blData = Array a
arr}
where
#if MIN_VERSION_vector(0,13,0)
(Array a
arr, Int
offset, Int
n) = Vector a -> (Array a, Int, Int)
forall a. Vector a -> (Array a, Int, Int)
VB.toArraySlice Vector a
v
#else
VectorCast offset n arr = toVectorCast v
data VectorCast a =
VectorCast {-# UNPACK #-}!Int {-# UNPACK #-}!Int {-# UNPACK #-}!(A.Array a)
toVectorCast :: VB.Vector a -> VectorCast a
toVectorCast = unsafeCoerce
#endif
fromBoxedMVector :: MVB.MVector s a -> MArray s BL Ix1 a
fromBoxedMVector :: forall s a. MVector s a -> MArray s BL Int a
fromBoxedMVector (MVB.MVector Int
o Int
k MutableArray s a
ma) = Sz1 -> Int -> MutableArray s a -> MArray s BL Int a
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
k) Int
o MutableArray s a
ma
{-# INLINE fromBoxedMVector #-}
coerceNormalBoxedArray :: Array BL ix e -> Array N ix e
coerceNormalBoxedArray :: forall ix e. Array BL ix e -> Array BN ix e
coerceNormalBoxedArray = Array BL ix e -> Array BN ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE coerceNormalBoxedArray #-}
coerceBoxedArray :: Array BL ix e -> Array B ix e
coerceBoxedArray :: forall ix e. Array BL ix e -> Array B ix e
coerceBoxedArray = Array BL ix e -> Array B ix e
forall a b. Coercible a b => a -> b
coerce
{-# INLINE coerceBoxedArray #-}
evalNormalBoxedMVector ::
(NFData a, PrimMonad m) => MVB.MVector (PrimState m) a -> m (MArray (PrimState m) N Ix1 a)
evalNormalBoxedMVector :: forall a (m :: * -> *).
(NFData a, PrimMonad m) =>
MVector (PrimState m) a -> m (MArray (PrimState m) BN Int a)
evalNormalBoxedMVector (MVB.MVector Int
o Int
k MutableArray (PrimState m) a
ma) =
let marr :: MArray (PrimState m) BN Int a
marr = MArray (PrimState m) BL Int a -> MArray (PrimState m) BN Int a
forall s ix e. MArray s BL ix e -> MArray s BN ix e
MBNArray (Sz1
-> Int
-> MutableArray (PrimState m) a
-> MArray (PrimState m) BL Int a
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
k) Int
o MutableArray (PrimState m) a
ma)
in MArray (PrimState m) BN Int a
marr MArray (PrimState m) BN Int a
-> m () -> m (MArray (PrimState m) BN Int a)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m ()) -> m ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
o (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
k) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (MutableArray (PrimState m) a -> Int -> m a
forall (m :: * -> *) a.
PrimMonad m =>
MutableArray (PrimState m) a -> Int -> m a
A.readArray MutableArray (PrimState m) a
ma (Int -> m a) -> (a -> m ()) -> Int -> m ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> m ()) -> (a -> ()) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ()
forall a. NFData a => a -> ()
rnf)
{-# INLINE evalNormalBoxedMVector #-}
evalNormalBoxedVector :: NFData a => Comp -> VB.Vector a -> Array N Ix1 a
evalNormalBoxedVector :: forall a. NFData a => Comp -> Vector a -> Array BN Int a
evalNormalBoxedVector Comp
comp Vector a
v =
(forall s. ST s (Array BN Int a)) -> Array BN Int a
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Array BN Int a)) -> Array BN Int a)
-> (forall s. ST s (Array BN Int a)) -> Array BN Int a
forall a b. (a -> b) -> a -> b
$ do
MVB.MVector Int
o Int
k MutableArray s a
ma <- Vector a -> ST s (MVector (PrimState (ST s)) a)
forall (m :: * -> *) a.
PrimMonad m =>
Vector a -> m (MVector (PrimState m) a)
VB.unsafeThaw Vector a
v
Array BL Int a -> Array BN Int a
forall e ix. (NFData e, Index ix) => Array BL ix e -> Array BN ix e
forceLazyArray (Array BL Int a -> Array BN Int a)
-> ST s (Array BL Int a) -> ST s (Array BN Int a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comp -> MArray (PrimState (ST s)) BL Int a -> ST s (Array BL Int a)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) BL ix a -> m (Array BL ix a)
unsafeFreeze Comp
comp (Sz1 -> Int -> MutableArray s a -> MArray s BL Int a
forall s ix e. Sz ix -> Int -> MutableArray s e -> MArray s BL ix e
MBLArray (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
k) Int
o MutableArray s a
ma)
{-# INLINE evalNormalBoxedVector #-}