sequences.windowed: faster rolling-map.

db4
John Benediktsson 2013-10-12 11:43:46 -07:00
parent de62db7775
commit a82e916bcf
1 changed files with 6 additions and 4 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2012 Doug Coleman. ! Copyright (C) 2012 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors fry kernel math math.order math.statistics USING: accessors fry kernel locals math math.order
sequences sequences.private ; math.statistics sequences sequences.private ;
IN: sequences.windowed IN: sequences.windowed
TUPLE: windowed-sequence TUPLE: windowed-sequence
@ -24,8 +24,10 @@ M: windowed-sequence length
: in-bounds ( a b sequence -- a' b' sequence ) : in-bounds ( a b sequence -- a' b' sequence )
[ nip in-bound ] [ [ nip ] dip in-bound ] [ 2nip ] 3tri ; [ nip in-bound ] [ [ nip ] dip in-bound ] [ 2nip ] 3tri ;
: rolling-map ( seq n quot: ( slice -- elt ) -- newseq ) :: rolling-map ( seq n quot: ( slice -- elt ) -- newseq )
[ <windowed-sequence> ] [ map ] bi* ; inline seq length [
[ n [-] ] [ seq <slice-unsafe> ] bi quot call
] { } map-integers ; inline
: rolling-sum ( seq n -- newseq ) : rolling-sum ( seq n -- newseq )
[ sum ] rolling-map ; [ sum ] rolling-map ;