]> gitweb.factorcode.org Git - factor.git/commitdiff
math.matrices: adding matrix-map-index.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 13 Dec 2020 20:48:07 +0000 (12:48 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 13 Dec 2020 20:48:07 +0000 (12:48 -0800)
basis/math/matrices/matrices.factor

index bedd3fd480f4cbcb7258e4fc0e6bc6f8369b5551..8825b7e8ef7e2d97d320490b76c93ec38cedfb9a 100644 (file)
@@ -214,6 +214,9 @@ DEFER: matrix-set-nths
 : matrix-map ( matrix quot: ( ... elt -- ... elt' ) -- matrix' )
     '[ _ map ] map ; inline
 
+: matrix-map-index ( matrix quot: ( ... elt i j -- ... elt' ) -- matrix' )
+    '[ [ swap @ ] curry map-index ] map-index ; inline
+
 : column-map ( matrix quot: ( ... col -- ... col' ) -- matrix' )
     [ transpose ] dip map transpose ; inline
 
@@ -295,9 +298,9 @@ ALIAS: hilbert-schmidt-norm frobenius-norm
     ] if ;
 
 : normalize-matrix ( m -- m' )
-  dup zero-matrix? [ ] [
-      dup mabs mmax m/n
-  ] if ;
+    dup zero-matrix? [ ] [
+        dup mabs mmax m/n
+    ] if ;
 
 ! well-defined for square matrices; but works on nonsquare too
 : main-diagonal ( matrix -- seq )