massiv 0.3.0.1 → 0.3.1.0
raw patch · 12 files changed
+197/−51 lines, 12 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Massiv.Array: flatten :: (Load r ix e, Resize r ix) => Array r ix e -> Array r Ix1 e
+ Data.Massiv.Array: iforSchedulerM_ :: (Source r ix e, Monad m) => Scheduler m () -> Array r ix e -> (ix -> e -> m a) -> m ()
+ Data.Massiv.Array: imapSchedulerM_ :: (Source r ix e, Monad m) => Scheduler m () -> (ix -> e -> m a) -> Array r ix e -> m ()
+ Data.Massiv.Array: infix 4 ..:
+ Data.Massiv.Array: rangeStepInclusive' :: Index ix => Comp -> ix -> ix -> ix -> Array D ix ix
+ Data.Massiv.Array: zoomWithGrid :: Source r ix e => e -> Stride ix -> Array r ix e -> Array DL ix e
+ Data.Massiv.Array.Delayed: makeLoadArrayS :: Index ix => Sz ix -> e -> (forall m. Monad m => (ix -> e -> m Bool) -> m ()) -> Array DL ix e
+ Data.Massiv.Array.Unsafe: unsafeMakeLoadArray :: Comp -> Sz ix -> Maybe e -> (forall m. Monad m => Scheduler m () -> Int -> (Int -> e -> m ()) -> m ()) -> Array DL ix e
- Data.Massiv.Array: (...) :: Int -> Int -> Array D Ix1 Int
+ Data.Massiv.Array: (...) :: Index ix => ix -> ix -> Array D ix ix
- Data.Massiv.Array: (..:) :: Int -> Int -> Array D Ix1 Int
+ Data.Massiv.Array: (..:) :: Index ix => ix -> ix -> Array D ix ix
Files
- massiv.cabal +1/−1
- src/Data/Massiv/Array/Delayed.hs +1/−0
- src/Data/Massiv/Array/Delayed/Push.hs +49/−6
- src/Data/Massiv/Array/Mutable.hs +11/−2
- src/Data/Massiv/Array/Ops/Construct.hs +16/−5
- src/Data/Massiv/Array/Ops/Map.hs +25/−0
- src/Data/Massiv/Array/Ops/Transform.hs +61/−3
- src/Data/Massiv/Array/Unsafe.hs +10/−10
- src/Data/Massiv/Core/Common.hs +12/−14
- src/Data/Massiv/Core/Index/Internal.hs +1/−1
- src/Data/Massiv/Core/Iterator.hs +4/−3
- src/Data/Massiv/Core/List.hs +6/−6
massiv.cabal view
@@ -1,5 +1,5 @@ name: massiv-version: 0.3.0.1+version: 0.3.1.0 synopsis: Massiv (Массив) is an Array Library. description: Multi-dimensional Arrays with fusion, stencils and parallel computation. homepage: https://github.com/lehins/massiv
src/Data/Massiv/Array/Delayed.hs view
@@ -14,6 +14,7 @@ -- ** Delayed Push Array , DL(..) , toLoadArray+ , makeLoadArrayS , makeLoadArray , fromStrideLoad -- ** Delayed Interleaved Array
src/Data/Massiv/Array/Delayed/Push.hs view
@@ -20,7 +20,9 @@ ( DL(..) , Array(..) , toLoadArray+ , makeLoadArrayS , makeLoadArray+ , unsafeMakeLoadArray , fromStrideLoad ) where @@ -28,6 +30,7 @@ import Data.Massiv.Core.Index.Internal (Sz(SafeSz)) import qualified Data.Semigroup as Semigroup import Prelude hiding (map, zipWith)+import Control.Applicative #include "massiv.h" @@ -38,6 +41,7 @@ data instance Array DL ix e = DLArray { dlComp :: !Comp , dlSize :: !(Sz ix)+ , dlDefault :: !(Maybe e) , dlLoad :: forall m . Monad m => Scheduler m () -> Int -- start loading at this linear index@@ -51,7 +55,7 @@ setComp c arr = arr {dlComp = c} {-# INLINE setComp #-} makeArrayLinear comp sz f =- DLArray comp sz $ \scheduler startAt dlWrite ->+ DLArray comp sz Nothing $ \scheduler startAt dlWrite -> splitLinearlyWithStartAtM_ scheduler startAt (totalElem sz) (pure . f) dlWrite {-# INLINE makeArrayLinear #-} @@ -60,8 +64,9 @@ {-# INLINE unsafeResize #-} instance Semigroup (Array DL Ix1 e) where- (<>) (DLArray c1 sz1 load1) (DLArray c2 sz2 load2) =- DLArray {dlComp = c1 <> c2, dlSize = SafeSz (k + unSz sz2), dlLoad = load}+ (<>) (DLArray c1 sz1 def1 load1) (DLArray c2 sz2 def2 load2) =+ DLArray+ {dlComp = c1 <> c2, dlSize = SafeSz (k + unSz sz2), dlDefault = def1 <|> def2, dlLoad = load} where !k = unSz sz1 load :: Monad m => Scheduler m () -> Int -> (Int -> e -> m ()) -> m ()@@ -79,6 +84,26 @@ mappend = (Semigroup.<>) {-# INLINE mappend #-} +-- | Describe how an array should be loaded into memory+--+-- @since 0.3.1+makeLoadArrayS ::+ Index ix =>+ Sz ix+ -- ^ Size of the resulting array+ -> e+ -- ^ Default value to use for all cells that have possibly been ommitted by the writing function+ -> (forall m. Monad m => (ix -> e -> m Bool) -> m ())+ -- ^ Writing function that described which elements to write into the target array.+ -> Array DL ix e+makeLoadArrayS sz defVal writer =+ DLArray Seq sz (Just defVal) $ \_scheduler !startAt uWrite ->+ let safeWrite !ix !e+ | isSafeIndex sz ix = uWrite (startAt + toLinearIndex sz ix) e >> pure True+ | otherwise = pure False+ {-# INLINE safeWrite #-}+ in writer safeWrite+{-# INLINE makeLoadArrayS #-} -- | Specify how an array can be loaded/computed through creation of a `DL` array. --@@ -88,15 +113,30 @@ -> Sz ix -> (forall m. Monad m => Scheduler m () -> Int -> (Int -> e -> m ()) -> m ()) -> Array DL ix e-makeLoadArray = DLArray+makeLoadArray comp sz = DLArray comp sz Nothing {-# INLINE makeLoadArray #-}+{-# DEPRECATED makeLoadArray "In favor of equivalent `unsafeMakeLoadArray` and safe `makeLoadArrayS`" #-} +-- | Specify how an array can be loaded/computed through creation of a `DL` array. Unlike+-- `makeLoadArrayS` this function is unsafe since there is no guarantee that all elements will be+-- initialized and in case of parallel scheduler there is a possibility of non-determinism.+--+-- @since 0.3.1+unsafeMakeLoadArray ::+ Comp+ -> Sz ix+ -> Maybe e+ -> (forall m. Monad m => Scheduler m () -> Int -> (Int -> e -> m ()) -> m ())+ -> Array DL ix e+unsafeMakeLoadArray = DLArray+{-# INLINE unsafeMakeLoadArray #-}+ -- | Convert any `Load`able array into `DL` representation. -- -- @since 0.3.0 toLoadArray :: Load r ix e => Array r ix e -> Array DL ix e toLoadArray arr =- DLArray (getComp arr) (size arr) $ \scheduler startAt dlWrite ->+ DLArray (getComp arr) (size arr) Nothing $ \scheduler startAt dlWrite -> loadArrayM scheduler arr (\ !i -> dlWrite (i + startAt)) {-# INLINE toLoadArray #-} @@ -106,7 +146,7 @@ fromStrideLoad :: StrideLoad r ix e => Stride ix -> Array r ix e -> Array DL ix e fromStrideLoad stride arr =- DLArray (getComp arr) newsz $ \scheduler startAt dlWrite ->+ DLArray (getComp arr) newsz Nothing $ \scheduler startAt dlWrite -> loadArrayWithStrideM scheduler stride newsz arr (\ !i -> dlWrite (i + startAt)) where newsz = strideSize stride (size arr)@@ -119,11 +159,14 @@ {-# INLINE getComp #-} loadArrayM scheduler DLArray {dlLoad} = dlLoad scheduler 0 {-# INLINE loadArrayM #-}+ defaultElement = dlDefault+ {-# INLINE defaultElement #-} instance Functor (Array DL ix) where fmap f arr = arr { dlLoad = \scheduler startAt uWrite -> dlLoad arr scheduler startAt (\ !i e -> uWrite i (f e))+ , dlDefault = f <$> dlDefault arr } {-# INLINE fmap #-}
src/Data/Massiv/Array/Mutable.hs view
@@ -197,7 +197,16 @@ freezeS marr = generateArrayLinearS Seq (msize marr) (unsafeLinearRead marr) {-# INLINE freezeS #-} +newMaybeInitialized ::+ (Load r' ix e, Mutable r ix e, PrimMonad m) => Array r' ix e -> m (MArray (PrimState m) r ix e)+newMaybeInitialized !arr = do+ let !sz = size arr+ marr <- unsafeNew sz+ mapM_ (unsafeLinearSet marr 0 (totalElem sz)) $ defaultElement arr+ pure marr+{-# INLINE newMaybeInitialized #-} + -- | Load sequentially a pure array into the newly created mutable array. -- -- @since 0.3.0@@ -206,7 +215,7 @@ => Array r' ix e -> m (MArray (PrimState m) r ix e) loadArrayS arr = do- marr <- unsafeNew (size arr)+ marr <- newMaybeInitialized arr loadArrayM trivialScheduler_ arr (unsafeLinearWrite marr) pure marr {-# INLINE loadArrayS #-}@@ -221,7 +230,7 @@ -> m (MArray RealWorld r ix e) loadArray arr = liftIO $ do- marr <- unsafeNew (size arr)+ marr <- newMaybeInitialized arr withScheduler_ (getComp arr) $ \scheduler -> loadArrayM scheduler arr (unsafeLinearWrite marr) pure marr {-# INLINE loadArray #-}
src/Data/Massiv/Array/Ops/Construct.hs view
@@ -44,6 +44,7 @@ , rangeStep , rangeInclusive , rangeStepInclusiveM+ , rangeStepInclusive' , rangeSize , rangeStepSize , enumFromN@@ -199,6 +200,7 @@ DLArray { dlComp = comp , dlSize = sz+ , dlDefault = Nothing , dlLoad = \_ startAt dlWrite -> void $@@ -228,6 +230,7 @@ DLArray { dlComp = comp , dlSize = sz+ , dlDefault = Nothing , dlLoad = \ _ startAt dlWrite -> void $ loopDeepM startAt (< (totalElem sz + startAt)) (+ 1) acc0 $ \ !i !acc -> do@@ -237,26 +240,27 @@ } {-# INLINE iunfoldlS_ #-} +infix 4 ..., ..: -- | Handy synonym for `rangeInclusive` `Seq` ----- >>> 4 ... 10+-- >>> Ix1 4 ... 10 -- Array D Seq (Sz1 7) -- [ 4, 5, 6, 7, 8, 9, 10 ] -- -- @since 0.3.0-(...) :: Int -> Int -> Array D Ix1 Int+(...) :: Index ix => ix -> ix -> Array D ix ix (...) = rangeInclusive Seq {-# INLINE (...) #-} -- | Handy synonym for `range` `Seq` ----- >>> 4 ..: 10+-- >>> Ix1 4 ..: 10 -- Array D Seq (Sz1 6) -- [ 4, 5, 6, 7, 8, 9 ] -- -- @since 0.3.0-(..:) :: Int -> Int -> Array D Ix1 Int+(..:) :: Index ix => ix -> ix -> Array D ix ix (..:) = range Seq {-# INLINE (..:) #-} @@ -320,7 +324,7 @@ in pure $ rangeStepSize comp from step (Sz (liftIndex2 (+) sz r)) {-# INLINE rangeStepM #-} --- | Same as `rangeStep`, but will throw an error whenever @step@ contains zeros.+-- | Same as `rangeStepM`, but will throw an error whenever @step@ contains zeros. -- -- ==== __Example__ --@@ -349,6 +353,13 @@ rangeStepInclusiveM :: (MonadThrow m, Index ix) => Comp -> ix -> ix -> ix -> m (Array D ix ix) rangeStepInclusiveM comp ixFrom step ixTo = rangeStepM comp ixFrom step (liftIndex (1 +) ixTo) {-# INLINE rangeStepInclusiveM #-}++-- | Just like `range`, except the finish index is included.+--+-- @since 0.3.1+rangeStepInclusive' :: Index ix => Comp -> ix -> ix -> ix -> Array D ix ix+rangeStepInclusive' comp ixFrom step = either throw id . rangeStepInclusiveM comp ixFrom step+{-# INLINE rangeStepInclusive' #-} -- | Create an array of specified size with indices starting with some index at position @0@ and
src/Data/Massiv/Array/Ops/Map.hs view
@@ -51,6 +51,8 @@ , forIO_ , iforIO , iforIO_+ , imapSchedulerM_+ , iforSchedulerM_ -- ** Zipping , zip , zip3@@ -568,6 +570,29 @@ (unsafeLinearIndex arr) (\i -> void . action (fromLinearIndex sz i)) {-# INLINE imapIO_ #-}++-- | Same as `imapM_`, but will use the supplied scheduler.+--+-- @since 0.3.1+imapSchedulerM_ ::+ (Source r ix e, Monad m) => Scheduler m () -> (ix -> e -> m a) -> Array r ix e -> m ()+imapSchedulerM_ scheduler action arr = do+ let sz = size arr+ splitLinearlyWith_+ scheduler+ (totalElem sz)+ (unsafeLinearIndex arr)+ (\i -> void . action (fromLinearIndex sz i))+{-# INLINE imapSchedulerM_ #-}++-- | Same as `imapM_`, but will use the supplied scheduler.+--+-- @since 0.3.1+iforSchedulerM_ ::+ (Source r ix e, Monad m) => Scheduler m () -> Array r ix e -> (ix -> e -> m a) -> m ()+iforSchedulerM_ scheduler arr action = imapSchedulerM_ scheduler action arr+{-# INLINE iforSchedulerM_ #-}+ -- | Same as `mapIO` but map an index aware action instead.
src/Data/Massiv/Array/Ops/Transform.hs view
@@ -25,6 +25,7 @@ , resizeM , resize' , resize+ , flatten -- ** Extract , extractM , extract@@ -48,6 +49,8 @@ -- ** Upsample/Downsample , upsample , downsample+ -- ** Zoom+ , zoomWithGrid -- ** Transform , transformM , transform'@@ -67,9 +70,10 @@ import Data.Massiv.Array.Delayed.Push import Data.Massiv.Array.Mutable import Data.Massiv.Array.Ops.Construct+import Data.Massiv.Array.Ops.Map import Data.Massiv.Core.Common import Data.Massiv.Core.Index.Internal (Sz(SafeSz))-import Prelude as P hiding (concat, splitAt, traverse)+import Prelude as P hiding (concat, splitAt, traverse, mapM_) -- | Extract a sub-array from within a larger source array. Array that is being extracted must be@@ -89,7 +93,8 @@ eIx = liftIndex2 (+) sIx $ unSz newSz {-# INLINE extractM #-} --- | Same as `extract`, but will throw an error if supplied dimensions are incorrect.+-- | Same as `extractM`, but will throw a runtime exception from pure code if supplied dimensions+-- are incorrect. -- -- @since 0.1.0 extract' :: Extract r ix e@@ -183,7 +188,13 @@ resize' sz = either throw id . resizeM sz {-# INLINE resize' #-} +-- | /O(1)/ - Reduce a multi-dimensional array into a flat vector+-- @since 0.3.1+flatten :: (Load r ix e, Resize r ix) => Array r ix e -> Array r Ix1 e+flatten arr = unsafeResize (SafeSz (totalElem (size arr))) arr+{-# INLINE flatten #-} + -- | Transpose a 2-dimensional array -- -- ==== __Examples__@@ -485,6 +496,7 @@ DLArray { dlComp = getComp arr1 <> getComp arr2 , dlSize = newSz+ , dlDefault = Nothing , dlLoad = \scheduler startAt dlWrite -> do scheduleWork scheduler $@@ -541,13 +553,14 @@ -- / make sure to fail as soon as at least one of the arrays has a mismatching inner size traverse_ (\(sz', _) -> throwM (SizeMismatchException (SafeSz sz) (SafeSz sz')))- (dropWhile ((== szl) . snd) $ zip szs szls)+ (dropWhile ((== szl) . snd) $ P.zip szs szls) let kTotal = SafeSz $ F.foldl' (+) k ks newSz <- insertSzM (SafeSz szl) n kTotal return $ DLArray { dlComp = mconcat $ P.map getComp arrs , dlSize = newSz+ , dlDefault = Nothing , dlLoad = \scheduler startAt dlWrite -> let arrayLoader !kAcc (kCur, arr) = do@@ -614,6 +627,7 @@ DLArray { dlComp = getComp arr , dlSize = resultSize+ , dlDefault = Nothing , dlLoad = \scheduler startAt dlWrite -> splitLinearlyWithStartAtM_@@ -641,6 +655,7 @@ DLArray { dlComp = getComp arr , dlSize = newsz+ , dlDefault = Nothing , dlLoad = \scheduler startAt dlWrite -> do unless (stride == pureIndex 1) $@@ -760,3 +775,46 @@ where (sz, a) = getSz (size arr1) (size arr2) {-# INLINE transform2' #-}++++-- | Replicate each element of the array by a factor in stride along each dimension and surround each+-- such group with a box of supplied grid value. It will essentially zoom up an array and create a+-- grid around each element from the original array. Very useful for zooming up images to inspect+-- individual pixels.+--+-- ==== __Example__+--+-- >>> import Data.Massiv.Array as A+-- >>> zoomWithGrid 0 (Stride (2 :. 3)) $ resize' (Sz2 3 2) (Ix1 1 ... 6)+-- Array DL Seq (Sz (10 :. 9))+-- [ [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]+-- , [ 0, 1, 1, 1, 0, 2, 2, 2, 0 ]+-- , [ 0, 1, 1, 1, 0, 2, 2, 2, 0 ]+-- , [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]+-- , [ 0, 3, 3, 3, 0, 4, 4, 4, 0 ]+-- , [ 0, 3, 3, 3, 0, 4, 4, 4, 0 ]+-- , [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]+-- , [ 0, 5, 5, 5, 0, 6, 6, 6, 0 ]+-- , [ 0, 5, 5, 5, 0, 6, 6, 6, 0 ]+-- , [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]+-- ]+--+-- @since 0.3.1+zoomWithGrid ::+ Source r ix e+ => e -- ^ Value to use for the grid+ -> Stride ix -- ^ Scaling factor+ -> Array r ix e -- ^ Source array+ -> Array DL ix e+zoomWithGrid gridVal (Stride zoomFactor) arr =+ unsafeMakeLoadArray Seq newSz (Just gridVal) $ \scheduler _ writeElement ->+ iforSchedulerM_ scheduler arr $ \ !ix !e -> do+ let !kix = liftIndex2 (*) ix kx+ mapM_ (\ !ix' -> writeElement (toLinearIndex newSz ix') e) $+ range Seq (liftIndex (+1) kix) (liftIndex2 (+) kix kx)+ where+ !kx = liftIndex (+1) zoomFactor+ !lastNewIx = liftIndex2 (*) kx $ unSz (size arr)+ !newSz = Sz (liftIndex (+1) lastNewIx)+{-# INLINE zoomWithGrid #-}
src/Data/Massiv/Array/Unsafe.hs view
@@ -13,28 +13,27 @@ -- module Data.Massiv.Array.Unsafe ( -- * Creation- -- , unsafeGenerateArray- -- , unsafeGenerateArrayP- -- * Indexing- Sz(SafeSz)+ unsafeMakeLoadArray+ -- * Indexing+ , Sz(SafeSz) , Stride(SafeStride) , unsafeIndex , unsafeLinearIndex , unsafeLinearIndexM- -- * Manipulations+ -- * Manipulations , unsafeBackpermute , unsafeResize , unsafeExtract , unsafeTransform , unsafeTransform2- -- ** Deprecated+ -- ** Deprecated , unsafeTraverse , unsafeTraverse2- -- * Slicing+ -- * Slicing , unsafeSlice , unsafeOuterSlice , unsafeInnerSlice- -- * Mutable interface+ -- * Mutable interface , unsafeThaw , unsafeFreeze , unsafeNew@@ -43,7 +42,7 @@ , unsafeWrite , unsafeLinearWrite , unsafeLinearSet- -- * Pointer access+ -- * Pointer access , unsafeWithPtr , unsafeArrayToForeignPtr , unsafeMArrayToForeignPtr@@ -51,7 +50,7 @@ , unsafeArrayFromForeignPtr0 , unsafeMArrayFromForeignPtr , unsafeMArrayFromForeignPtr0- -- ** Atomic Operations+ -- ** Atomic Operations , unsafeAtomicReadIntArray , unsafeAtomicWriteIntArray , unsafeAtomicModifyIntArray@@ -65,6 +64,7 @@ ) where import Data.Massiv.Array.Delayed.Pull (D)+import Data.Massiv.Array.Delayed.Push (unsafeMakeLoadArray) import Data.Massiv.Array.Manifest.Primitive import Data.Massiv.Array.Manifest.Storable import Data.Massiv.Core.Common
src/Data/Massiv/Core/Common.hs view
@@ -214,6 +214,11 @@ -> (Int -> e -> m ()) -- ^ Function that writes an element into target array -> m () + defaultElement :: Array r ix e -> Maybe e+ defaultElement _ = Nothing+ {-# INLINE defaultElement #-}++ class Load r ix e => StrideLoad r ix e where -- | Load an array into memory with stride. Default implementation requires an instance of -- `Source`.@@ -273,33 +278,27 @@ -- | Convert immutable array into a mutable array without copy. -- -- @since 0.1.0- unsafeThaw :: PrimMonad m =>- Array r ix e -> m (MArray (PrimState m) r ix e)+ unsafeThaw :: PrimMonad m => Array r ix e -> m (MArray (PrimState m) r ix e) -- | Convert mutable array into an immutable array without copy. -- -- @since 0.1.0- unsafeFreeze :: PrimMonad m =>- Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)+ unsafeFreeze :: PrimMonad m => Comp -> MArray (PrimState m) r ix e -> m (Array r ix e) - -- | Create new mutable array, leaving it's elements uninitialized. Size isn't validated- -- either.+ -- | Create new mutable array, leaving it's elements uninitialized. Size isn't validated either. -- -- @since 0.1.0- unsafeNew :: PrimMonad m =>- Sz ix -> m (MArray (PrimState m) r ix e)+ unsafeNew :: PrimMonad m => Sz ix -> m (MArray (PrimState m) r ix e) -- | Read an element at linear row-major index -- -- @since 0.1.0- unsafeLinearRead :: PrimMonad m =>- MArray (PrimState m) r ix e -> Int -> m e+ unsafeLinearRead :: PrimMonad m => MArray (PrimState m) r ix e -> Int -> m e -- | Write an element into mutable array with linear row-major index -- -- @since 0.1.0- unsafeLinearWrite :: PrimMonad m =>- MArray (PrimState m) r ix e -> Int -> e -> m ()+ unsafeLinearWrite :: PrimMonad m => MArray (PrimState m) r ix e -> Int -> e -> m () -- | Initialize mutable array to some default value. --@@ -354,7 +353,6 @@ toNested :: Array r ix e -> NestedStruct r ix e - class Construct r ix e => Ragged r ix e where emptyR :: Comp -> Array r ix e@@ -369,7 +367,7 @@ edgeSize :: Array r ix e -> Sz ix - flatten :: Array r ix e -> Array r Ix1 e+ flattenRagged :: Array r ix e -> Array r Ix1 e loadRagged :: Monad m => (m () -> m ()) -> (Int -> e -> m a) -> Int -> Int -> Sz ix -> Array r ix e -> m ()
src/Data/Massiv/Core/Index/Internal.hs view
@@ -114,7 +114,7 @@ _ -> " (" ++ show usz ++ ")" instance (Num ix, Index ix) => Num (Sz ix) where- (+) x y = SafeSz (coerce x + coerce y)+ (+) x y = Sz (coerce x + coerce y) {-# INLINE (+) #-} (-) x y = Sz (coerce x - coerce y) {-# INLINE (-) #-}
src/Data/Massiv/Core/Iterator.hs view
@@ -121,20 +121,21 @@ -- | Interator that can be used to split computation jobs ----- @since 0.2.6.0+-- @since 0.2.6 splitLinearlyWithM_ :: Monad m => Scheduler m () -> Int -> (Int -> m b) -> (Int -> b -> m c) -> m () splitLinearlyWithM_ scheduler totalLength make write = splitLinearly (numWorkers scheduler) totalLength $ \chunkLength slackStart -> do loopM_ 0 (< slackStart) (+ chunkLength) $ \ !start ->- scheduleWork scheduler $ loopM_ start (< (start + chunkLength)) (+ 1) $ \ !k -> make k >>= write k+ scheduleWork scheduler $+ loopM_ start (< (start + chunkLength)) (+ 1) $ \ !k -> make k >>= write k scheduleWork scheduler $ loopM_ slackStart (< totalLength) (+ 1) $ \ !k -> make k >>= write k {-# INLINE splitLinearlyWithM_ #-} -- | Interator that can be used to split computation jobs ----- @since 0.2.6.0+-- @since 0.3.0 splitLinearlyWithStartAtM_ :: Monad m => Scheduler m () -> Int -> Int -> (Int -> m b) -> (Int -> b -> m c) -> m () splitLinearlyWithStartAtM_ scheduler startAt totalLength make write =
src/Data/Massiv/Core/List.hs view
@@ -114,8 +114,8 @@ Nothing -> Nothing Just (x, xs) -> Just (x, LArray lComp (coerce xs)) {-# INLINE unconsR #-}- flatten = id- {-# INLINE flatten #-}+ flattenRagged = id+ {-# INLINE flattenRagged #-} generateRaggedM !comp !k f = do xs <- loopDeepM 0 (< coerce k) (+ 1) [] $ \i acc -> do e <- f i@@ -187,15 +187,15 @@ -- return (cons e acc) generateRaggedM = unsafeGenerateParM {-# INLINE generateRaggedM #-}- flatten arr = LArray {lComp = lComp arr, lData = coerce xs}+ flattenRagged arr = LArray {lComp = lComp arr, lData = coerce xs} where- xs = concatMap (unList . lData . flatten . LArray (lComp arr)) (unList (lData arr))- {-# INLINE flatten #-}+ xs = concatMap (unList . lData . flattenRagged . LArray (lComp arr)) (unList (lData arr))+ {-# INLINE flattenRagged #-} loadRagged using uWrite start end sz xs = do let (k, szL) = unconsSz sz step = totalElem szL isZero = totalElem sz == 0- when (isZero && not (isNull (flatten xs))) (return $! throw DimTooLongException)+ when (isZero && not (isNull (flattenRagged xs))) (return $! throw DimTooLongException) unless isZero $ do leftOver <- loopM start (< end) (+ step) xs $ \i zs ->