math.statistics: fix stack effect on collect-by
parent
27ac4c60f4
commit
38a5184fdf
|
@ -1,4 +1,4 @@
|
||||||
USING: kernel math math.functions math.statistics tools.test ;
|
USING: assocs kernel math math.functions math.statistics sequences tools.test ;
|
||||||
IN: math.statistics.tests
|
IN: math.statistics.tests
|
||||||
|
|
||||||
[ 1 ] [ { 1 } mean ] unit-test
|
[ 1 ] [ { 1 } mean ] unit-test
|
||||||
|
@ -53,3 +53,12 @@ IN: math.statistics.tests
|
||||||
] [
|
] [
|
||||||
"aabbcc" histogram
|
"aabbcc" histogram
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
{
|
||||||
|
V{ 0 3 6 9 }
|
||||||
|
V{ 1 4 7 }
|
||||||
|
V{ 2 5 8 }
|
||||||
|
} [
|
||||||
|
10 iota [ 3 mod ] collect-by
|
||||||
|
[ 0 swap at ] [ 1 swap at ] [ 2 swap at ] tri
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -84,10 +84,10 @@ PRIVATE>
|
||||||
: sorted-histogram ( seq -- alist )
|
: sorted-histogram ( seq -- alist )
|
||||||
histogram sort-values ;
|
histogram sort-values ;
|
||||||
|
|
||||||
: collect-pairs ( seq quot: ( x -- x' ) -- hashtable )
|
: collect-pairs ( seq quot: ( x -- v k ) -- hashtable )
|
||||||
[ push-at ] sequence>hashtable ; inline
|
[ push-at ] sequence>hashtable ; inline
|
||||||
|
|
||||||
: collect-by ( seq quot -- hashtable )
|
: collect-by ( seq quot: ( x -- x' ) -- hashtable )
|
||||||
[ dup ] prepose collect-pairs ; inline
|
[ dup ] prepose collect-pairs ; inline
|
||||||
|
|
||||||
: mode ( seq -- x )
|
: mode ( seq -- x )
|
||||||
|
|
Loading…
Reference in New Issue