@@ -75,6 +75,8 @@ data SpliceState s arr
75 | SpliceYielding arr (SpliceState s arr)
75 | SpliceYielding arr (SpliceState s arr)
76 | SpliceFinish
76 | SpliceFinish
78+-- XXX This can be removed once compactLEFold/compactLE are implemented.
78-- | This mutates the first array (if it has space) to append values from the
80-- | This mutates the first array (if it has space) to append values from the
79-- second one. This would work for immutable arrays as well because an
81-- second one. This would work for immutable arrays as well because an
80-- immutable array never has space so a new array is allocated instead of
82-- immutable array never has space so a new array is allocated instead of
@@ -132,6 +134,9 @@ packArraysChunksOf n (D.Stream step state) =
133 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
135 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
137+-- XXX Remove this once compactLEFold is implemented
138+-- lpackArraysChunksOf = Fold.many compactLEFold
135{-# INLINE_NORMAL lpackArraysChunksOf #-}
140{-# INLINE_NORMAL lpackArraysChunksOf #-}
136lpackArraysChunksOf :: (MonadIO m, Storable a)
141lpackArraysChunksOf :: (MonadIO m, Storable a)
137 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
142 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
@@ -188,18 +193,19 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
188 return $ first (Tuple' Nothing) res
193 return $ first (Tuple' Nothing) res
189 else return $ FL.Partial $ Tuple' (Just buf'') r1
194 else return $ FL.Partial $ Tuple' (Just buf'') r1
191−-- XXX replace by compactLE
196+-- XXX Same as compactLE, to be removed once that is implemented.
193-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
198-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
194-- maximum specified size in bytes.
199-- maximum specified size in bytes.
196−-- @since 0.7.0
201+-- /Internal/
197{-# INLINE compact #-}
202{-# INLINE compact #-}
198compact :: (MonadIO m, Storable a)
203compact :: (MonadIO m, Storable a)
199 => Int -> SerialT m (Array a) -> SerialT m (Array a)
204 => Int -> SerialT m (Array a) -> SerialT m (Array a)
200compact n xs = D.fromStreamD $ packArraysChunksOf n (D.toStreamD xs)
205compact n xs = D.fromStreamD $ packArraysChunksOf n (D.toStreamD xs)
202−-- XXX Replace the above functions by a compactLEFold
207+-- See lpackArraysChunksOf/packArraysChunksOf to implement this.
203-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
209-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
204-- maximum specified size. Note that if a single array is bigger than the
210-- maximum specified size. Note that if a single array is bigger than the
205-- specified size we do not split it to fit. When we coalesce multiple arrays
211-- specified size we do not split it to fit. When we coalesce multiple arrays
@@ -212,12 +218,16 @@ compactLEFold :: -- (MonadIO m, Storable a) =>
212 Int -> Fold m (Array a) (Array a)
218 Int -> Fold m (Array a) (Array a)
213compactLEFold = undefined
219compactLEFold = undefined
221+-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
222+-- maximum specified size in bytes.
215compactLE :: (MonadIO m {-, Storable a-}) =>
225compactLE :: (MonadIO m {-, Storable a-}) =>
216 Int -> SerialT m (Array a) -> SerialT m (Array a)
226 Int -> SerialT m (Array a) -> SerialT m (Array a)
217compactLE n xs = D.fromStreamD $ D.foldMany (compactLEFold n) (D.toStreamD xs)
227compactLE n xs = D.fromStreamD $ D.foldMany (compactLEFold n) (D.toStreamD xs)
219−-- | Like 'compact' but generates arrays of exactly equal to the size specified
229+-- | Like 'compactLE' but generates arrays of exactly equal to the size
220−-- except for the last array in the stream which could be shorter.
230+-- specified except for the last array in the stream which could be shorter.
222-- /Unimplemented/
232-- /Unimplemented/
223{-# INLINE compactEQ #-}
233{-# INLINE compactEQ #-}
@@ -226,7 +236,7 @@ compactEQ :: -- (MonadIO m, Storable a) =>
226compactEQ _n _xs = undefined
236compactEQ _n _xs = undefined
227 -- D.fromStreamD $ D.foldMany (compactEQFold n) (D.toStreamD xs)
237 -- D.fromStreamD $ D.foldMany (compactEQFold n) (D.toStreamD xs)
229−-- | Like 'compact' but generates arrays of size greater than or equal to the
239+-- | Like 'compactLE' but generates arrays of size greater than or equal to the
230-- specified except for the last array in the stream which could be shorter.
240-- specified except for the last array in the stream which could be shorter.
232-- /Unimplemented/
242-- /Unimplemented/