math.matrices: adding the outer product.

db4
John Benediktsson 2012-08-08 17:02:39 -07:00
parent adbe117b5a
commit 2e9c20a12e
3 changed files with 18 additions and 0 deletions

View File

@ -22,3 +22,12 @@ HELP: kron
"{ { 1 2 } { 3 4 } } { { 0 5 } { 6 7 } } kron ."
"{ { 0 5 0 10 } { 6 7 12 14 } { 0 15 0 20 } { 18 21 24 28 } }" }
} ;
HELP: outer
{ $values { "u" sequence } { "v" sequence } { "m" sequence } }
{ $description "Computers the outer product of " { $snippet "u" } " and " { $snippet "v" } "." }
{ $examples
{ $example "USING: math.matrices prettyprint ;"
"{ 5 6 7 } { 1 2 3 } outer ."
"{ { 5 10 15 } { 6 12 18 } { 7 14 21 } }" }
} ;

View File

@ -276,3 +276,9 @@ IN: math.matrices.tests
{ { 1 1 } { 1 -1 } }
{ { 1 2 3 4 5 } { 6 7 8 9 10 } } swap kron
] unit-test
{
{ { 5 10 15 }
{ 6 12 18 }
{ 7 14 21 } }
} [ { 5 6 7 } { 1 2 3 } outer ] unit-test

View File

@ -165,3 +165,6 @@ IN: math.matrices
: kron ( m1 m2 -- m )
'[ [ _ n*m ] map ] map stitch stitch ;
: outer ( u v -- m )
[ n*v ] curry map ;