Skip to content

Commit 944c158

Browse files
authored
Merge pull request #125 from dolio/master
Fix iscanr/l functions
2 parents 31edb3f + 02d4dc8 commit 944c158

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Data/Vector/Generic.hs

Lines changed: 10 additions & 6 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

@@ -1822,18 +1822,22 @@ scanr' f z = unstreamR . Bundle.scanl' (flip f) z . streamR
18221822
-- | /O(n)/ Right-to-left scan over a vector with its index
18231823
iscanr :: (Vector v a, Vector v b) => (Int -> a -> b -> b) -> b -> v a -> v b
18241824
{-# INLINE iscanr #-}
1825-
iscanr f z =
1825+
iscanr f z v =
18261826
unstreamR
1827-
. inplace (S.scanl (flip $ uncurry f) z . S.indexed) id
1827+
. inplace (S.scanl (flip $ uncurry f) z . S.indexedR n) (+1)
18281828
. streamR
1829+
$ v
1830+
where n = length v
18291831

18301832
-- | /O(n)/ Right-to-left scan over a vector (strictly) with its index
18311833
iscanr' :: (Vector v a, Vector v b) => (Int -> a -> b -> b) -> b -> v a -> v b
18321834
{-# INLINE iscanr' #-}
1833-
iscanr' f z =
1835+
iscanr' f z v =
18341836
unstreamR
1835-
. inplace (S.scanl' (flip $ uncurry f) z . S.indexed) id
1837+
. inplace (S.scanl' (flip $ uncurry f) z . S.indexedR n) (+1)
18361838
. streamR
1839+
$ v
1840+
where n = length v
18371841

18381842
-- | /O(n)/ Right-to-left scan over a non-empty vector
18391843
scanr1 :: Vector v a => (a -> a -> a) -> v a -> v a

0 commit comments

Comments
 (0)