math.extras: adding linspace.

db4
John Benediktsson 2013-03-20 13:44:54 -07:00
parent 94c5cdad3e
commit a21fddc4dc
3 changed files with 10 additions and 1 deletions

View File

@ -57,3 +57,7 @@ HELP: sinc
{ $values { "x" number } { "y" number } }
{ $description "Returns the " { $link sinc } " function, calculated according to " { $snippet "sin(pi * x) / (pi * x)" } ". The name " { $link sinc } " is short for \"sine cardinal\" or \"sinus cardinalis\"." }
{ $notes { $snippet "0 sinc" } " is the limit value of 1." } ;
HELP: linspace
{ $values { "from" number } { "to" number } { "points" number } { "seq" sequence } }
{ $description "Return evenly spaced numbers over a specified interval " { $snippet "[from,to]" } "." } ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: math math.extras math.ranges sequences tools.test ;
USING: arrays math math.extras math.ranges sequences tools.test ;
IN: math.extras.test
@ -77,3 +77,5 @@ IN: math.extras.test
{ 1 2 3 4 }
{ 0 1 0 0 2 3 }
} [ { 1 2 1 1 3 4 } unique-indices ] unit-test
{ { 1 10+3/4 20+1/2 30+1/4 40 } } [ 1 40 5 linspace >array ] unit-test

View File

@ -198,3 +198,6 @@ PRIVATE>
: unique-indices ( seq -- unique indices )
[ members ] keep over dup length iota H{ } zip-as '[ _ at ] map ;
: linspace ( from to points -- seq )
1 - [ 2dup swap - ] dip / <range> ;