diff --git a/basis/math/matrices/matrices-tests.factor b/basis/math/matrices/matrices-tests.factor index 3855357b46..f82fef7c85 100644 --- a/basis/math/matrices/matrices-tests.factor +++ b/basis/math/matrices/matrices-tests.factor @@ -383,3 +383,12 @@ CONSTANT: test-points { { t } [ { { 1 2 } { 3 4 } } square-matrix? ] unit-test { f } [ { { 1 } { 2 3 } } square-matrix? ] unit-test { f } [ { { 1 2 } } square-matrix? ] unit-test + +{ 9 } +[ { { 2 -2 1 } { 1 3 -1 } { 2 -4 2 } } m-1norm ] unit-test + +{ 8 } +[ { { 2 -2 1 } { 1 3 -1 } { 2 -4 2 } } m-infinity-norm ] unit-test + +{ 2.0 } +[ { { 1 1 } { 1 1 } } frobenius-norm ] unit-test diff --git a/basis/math/matrices/matrices.factor b/basis/math/matrices/matrices.factor index 0cab9a1472..ef5a06a22f 100644 --- a/basis/math/matrices/matrices.factor +++ b/basis/math/matrices/matrices.factor @@ -141,6 +141,9 @@ IN: math.matrices : mmin ( m -- n ) [ 1/0. ] dip [ [ min ] each ] each ; : mmax ( m -- n ) [ -1/0. ] dip [ [ max ] each ] each ; : mnorm ( m -- n ) dup mmax abs m/n ; +: m-infinity-norm ( m -- n ) [ [ abs ] map-sum ] map supremum ; +: m-1norm ( m -- n ) flip m-infinity-norm ; +: frobenius-norm ( m -- n ) [ [ sq ] map-sum ] map-sum sqrt ; : cross ( vec1 vec2 -- vec3 ) [ [ { 1 2 0 } vshuffle ] [ { 2 0 1 } vshuffle ] bi* v* ]