From b6bcf214e638fd36ef7d76c9f573a84e6e016482 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 11 Jun 2022 20:08:12 -0400 Subject: Nothing but edits yet again --- docs/doc/transpose.html | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'docs/doc/transpose.html') diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html index 807173ba..8c9841b3 100644 --- a/docs/doc/transpose.html +++ b/docs/doc/transpose.html @@ -36,7 +36,7 @@ a23456 ⟨ 3 4 5 6 2 ⟩ -

In terms of the argument data as given by Deshape (), this looks like a simple 2-dimensional transpose: one axis is exchanged with a compound axis made up of the other axes. Here we transpose a rank 3 matrix:

+

In terms of the index-ordered elements as given by Deshape (), this looks like a simple 2-dimensional transpose: one axis is exchanged with a compound axis made up of the other axes. Here we transpose a rank 3 matrix:

↗️
    a322  322⥊↕12
      a322
 ┌─                      
@@ -71,7 +71,7 @@
 ⟨ 6 2 3 4 5 ⟩
 

In fact, we have ≢⍉k a ←→ k⌽≢a for any whole number k and array a.

-

To move axes other than the first, use the Rank modifier in order to leave initial axes untouched. A rank of k>0 transposes only the last k axes while a rank of k<0 ignores the first |k axes.

+

To move axes other than the first, use the Rank modifier in order to leave initial axes untouched. A rank of k>0 transposes only the last k axes while a rank of k<0 ignores the first |k axes.

↗️
     3 a23456
 ⟨ 2 3 5 6 4 ⟩
 
@@ -82,14 +82,14 @@

Using these forms (and the Rank function), we can state BQN's generalized matrix product swapping rule:

a MP b  ←→  (1-=a) (b) MP (a)
 
-

Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, so that APL's simpler rule MP MP˜ holds in BQN.

+

Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, so that APL's simpler rule MP MP˜ holds in BQN on rank 2.

Axis permutations of the types we've shown generate the complete permutation group on any number of axes, so you could produce any transposition you want with the right sequence of monadic transpositions with Rank. However, this can be unintuitive and tedious. What if you want to transpose the first three axes, leaving the rest alone? With monadic Transpose you have to send some axes to the end, then bring them back to the beginning. For example [following four or five failed tries]:

↗️
     ¯2  a23456  # Restrict Transpose to the first three axes
 ⟨ 3 4 2 5 6 ⟩
 

In a case like this the dyadic version of , called Reorder Axes, is much easier.

Reorder Axes

-

Transpose also allows a left argument that specifies a permutation of 𝕩's axes. For each index pi𝕨 in the left argument, axis i of 𝕩 is used for axis p of the result. Multiple argument axes can be sent to the same result axis, in which case that axis goes along a diagonal of 𝕩, and the result will have a lower rank than 𝕩.

+

Transpose also allows a left argument that specifies a permutation of 𝕩's axes. For each index pi𝕨 in the left argument, axis i of 𝕩 is used for axis p of the result. Multiple argument axes can be sent to the same result axis, in which case that axis goes along a diagonal of 𝕩, and the result will have a lower rank than 𝕩 (see the next section).

↗️
     13204  a23456
 ⟨ 5 2 4 3 6 ⟩
 
@@ -109,8 +109,26 @@
 ⟨ 3 4 2 5 6 ⟩
 

Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to Reorder Axes with a "default" left argument: (=-1˙).

+

Taking diagonals

+

When 𝕨 contains an axis index more than once, the corresponding axes of 𝕩 will all be sent to that axis of the result. This isn't a special case: it follows the same rule that i𝕨𝕩 is (𝕨i)𝕩. Only the result shape has to be adjusted for this case: the length along a result axis is the minimum of all the axes of 𝕩 that go into it, because any indices outside this range will be out of bounds along at least one axis.

+

A bit abstract. This rule is almost always used simply as 00𝕩 to get the main diagonal of a matrix.

+↗️
     a  35'a'+↕15
+┌─       
+╵"abcde  
+  fghij  
+  klmno" 
+        ┘
+
+    00  a
+"agm"
+
+    200a  # Single index into result
+'m'
+    2,2a    # is like a doubled index into a
+'m'
+

Definitions

Here we define the two valences of Transpose more precisely.

-

An atom right argument to either valence of Transpose is always enclosed to get an array before doing anything else.

-

Monadic transpose is identical to (=-1˙), except that if 𝕩 is a unit it is returned unchanged (after enclosing, if it's an atom) rather than giving an error.

-

In Reorder Axes, 𝕨 is a number or numeric array of rank 1 or less, and 𝕨≠≢𝕩. Define the result rank r(=𝕩)-+´¬∊𝕨 to be the right argument rank minus the number of duplicate entries in the left argument. We require ´𝕨<r. Bring 𝕨 to full length by appending the missing indices: 𝕨𝕨(¬˜/⊢)r. Now the result shape is defined to be ´¨𝕨⊔≢𝕩. Element iz of the result z is element (𝕨i)𝕩 of the argument.

+

An atom right argument to Transpose or Reorder Axes is always enclosed to get an array before doing anything else.

+

Monadic Transpose is identical to (=-1˙), except that if 𝕩 is a unit it's returned unchanged (after enclosing, if it's an atom) rather than giving an error.

+

In Reorder Axes, 𝕨 is a number or numeric array of rank 1 or less, and 𝕨≠≢𝕩. Define the result rank r(=𝕩)-+´¬∊𝕨 to be the rank of 𝕩 minus the number of duplicate entries in 𝕨. We require ´𝕨<r. Bring 𝕨 to full length by appending the missing indices: 𝕨𝕨(¬˜/⊢)r. Now the result shape is defined to be ´¨𝕨⊔≢𝕩. Element iz of the result z is element (𝕨i)𝕩 of the argument.

-- cgit v1.2.3