]> gitweb.factorcode.org Git - factor.git/commitdiff
math.matrics: Add some combinators and indexing words to math.matrices.
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 3 Oct 2012 00:53:24 +0000 (17:53 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 22 Oct 2012 16:47:35 +0000 (09:47 -0700)
basis/math/matrices/matrices.factor

index 0b8f0a13b650a53dfd1265c510d3ac8b466e53e4..3f594c87d21abd74c53403898e08e02076477c4c 100644 (file)
@@ -168,3 +168,31 @@ IN: math.matrices
 
 : outer ( u v -- m )
     [ n*v ] curry map ;
+
+: row ( n m -- col )
+    nth ; inline
+
+: rows ( seq m -- cols )
+    '[ _ row ] map ; inline
+
+: col ( n m -- col )
+    swap '[ _ swap nth ] map ; inline
+
+: cols ( seq m -- cols )
+    '[ _ col ] map ; inline
+
+: matrix-map ( m quot -- )
+    '[ _ map ] map ; inline
+
+: column-map ( m quot -- seq )
+    [ [ first length iota ] keep ] dip '[ _ col @ ] map ; inline
+
+: cartesian-indices ( n -- matrix )
+    iota dup cartesian-product ; inline
+
+: cartesian-matrix-map ( m quot -- m' )
+    [ [ first length cartesian-indices ] keep ] dip
+    '[ _ @ ] matrix-map ; inline
+
+: cartesian-matrix-column-map ( m quot -- m' )
+    [ cols first2 ] prepose cartesian-matrix-map ; inline