Skip to content

Commit 59a5ba3

Browse files
committed
Fix iscanr/l functions to fuse with correct lengths
They were using inplace with id, while scans increase the number of elements by 1. iscanr functions are incorrect, though.
1 parent d6ad33a commit 59a5ba3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Data/Vector/Generic.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,15 +1757,15 @@ iscanl :: (Vector v a, Vector v b) => (Int -> a -> b -> a) -> a -> v b -> v a
17571757
{-# INLINE iscanl #-}
17581758
iscanl f z =
17591759
unstream
1760-
. inplace (S.scanl (\a (i, b) -> f i a b) z . S.indexed) id
1760+
. inplace (S.scanl (\a (i, b) -> f i a b) z . S.indexed) (+1)
17611761
. stream
17621762

17631763
-- | /O(n)/ Scan over a vector (strictly) with its index
17641764
iscanl' :: (Vector v a, Vector v b) => (Int -> a -> b -> a) -> a -> v b -> v a
17651765
{-# INLINE iscanl' #-}
17661766
iscanl' f z =
17671767
unstream
1768-
. inplace (S.scanl' (\a (i, b) -> f i a b) z . S.indexed) id
1768+
. inplace (S.scanl' (\a (i, b) -> f i a b) z . S.indexed) (+1)
17691769
. stream
17701770

17711771

@@ -1824,15 +1824,15 @@ iscanr :: (Vector v a, Vector v b) => (Int -> a -> b -> b) -> b -> v a -> v b
18241824
{-# INLINE iscanr #-}
18251825
iscanr f z =
18261826
unstreamR
1827-
. inplace (S.scanl (flip $ uncurry f) z . S.indexed) id
1827+
. inplace (S.scanl (flip $ uncurry f) z . S.indexed) (+1)
18281828
. streamR
18291829

18301830
-- | /O(n)/ Right-to-left scan over a vector (strictly) with its index
18311831
iscanr' :: (Vector v a, Vector v b) => (Int -> a -> b -> b) -> b -> v a -> v b
18321832
{-# INLINE iscanr' #-}
18331833
iscanr' f z =
18341834
unstreamR
1835-
. inplace (S.scanl' (flip $ uncurry f) z . S.indexed) id
1835+
. inplace (S.scanl' (flip $ uncurry f) z . S.indexed) (+1)
18361836
. streamR
18371837

18381838
-- | /O(n)/ Right-to-left scan over a non-empty vector

0 commit comments

Comments
 (0)