math.extras: return new arrays to protect users from others.

db4
John Benediktsson 2012-12-04 09:06:30 -08:00
parent 82dc0bf045
commit 53382f4472
1 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2012 John Benediktsson ! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: assocs assocs.extras combinators.short-circuit fry USING: arrays assocs assocs.extras combinators.short-circuit fry
grouping kernel locals math math.combinatorics math.constants grouping kernel locals math math.combinatorics math.constants
math.functions math.order math.primes math.ranges math.functions math.order math.primes math.ranges
math.statistics math.vectors memoize random sequences math.statistics math.vectors memoize random sequences
@ -116,26 +116,26 @@ PRIVATE>
[ zero? not ] filter ; [ zero? not ] filter ;
: bartlett ( n -- seq ) : bartlett ( n -- seq )
dup 1 <= [ 1 = { 1 } { } ? ] [ dup 1 <= [ 1 = [ 1 1array ] [ { } ] if ] [
[ iota ] [ 1 - 2 / ] bi [ [ iota ] [ 1 - 2 / ] bi [
[ recip * ] [ >= ] 2bi [ 2 swap - ] when [ recip * ] [ >= ] 2bi [ 2 swap - ] when
] curry map ] curry map
] if ; ] if ;
: hanning ( n -- seq ) : hanning ( n -- seq )
dup 1 <= [ 1 = { 1 } { } ? ] [ dup 1 <= [ 1 = [ 1 1array ] [ { } ] if ] [
[ iota ] [ 1 - 2pi swap / ] bi v*n [ iota ] [ 1 - 2pi swap / ] bi v*n
[ cos -0.5 * 0.5 + ] map! [ cos -0.5 * 0.5 + ] map!
] if ; ] if ;
: hamming ( n -- seq ) : hamming ( n -- seq )
dup 1 <= [ 1 = { 1 } { } ? ] [ dup 1 <= [ 1 = [ 1 1array ] [ { } ] if ] [
[ iota ] [ 1 - 2pi swap / ] bi v*n [ iota ] [ 1 - 2pi swap / ] bi v*n
[ cos -0.46 * 0.54 + ] map! [ cos -0.46 * 0.54 + ] map!
] if ; ] if ;
: blackman ( n -- seq ) : blackman ( n -- seq )
dup 1 <= [ 1 = { 1 } { } ? ] [ dup 1 <= [ 1 = [ 1 1array ] [ { } ] if ] [
[ iota ] [ 1 - 2pi swap / ] bi v*n [ iota ] [ 1 - 2pi swap / ] bi v*n
[ [ cos -0.5 * ] map ] [ [ 2 * cos 0.08 * ] map ] bi [ [ cos -0.5 * ] map ] [ [ 2 * cos 0.08 * ] map ] bi
v+ 0.42 v+n v+ 0.42 v+n