Rank/Atop: Difference between revisions
Sudleyplace (talk | contribs) No edit summary |
Sudleyplace (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
<table border="0" cellpadding="5" cellspacing="0" summary=""> | <table border="0" cellpadding="5" cellspacing="0" summary=""> | ||
<tr> | <tr> | ||
<td><apll>Z←(<i>f</i>⍤X) R</apll></td> | <td valign="top"><apll>Z←(<i>f</i>⍤X) R</apll></td> | ||
<td></td> | <td></td> | ||
<td></td> | <td></td> | ||
Line 59: | Line 59: | ||
<table border="0" cellpadding="5" cellspacing="0" summary=""> | <table border="0" cellpadding="5" cellspacing="0" summary=""> | ||
<tr> | <tr> | ||
<td><apll>Z←L (<i>f</i>⍤X) R</apll></td> | <td valign="top"><apll>Z←L (<i>f</i>⍤X) R</apll></td> | ||
<td></td> | <td></td> | ||
<td></td> | <td></td> |
Revision as of 20:24, 7 May 2008
Monadic Derived Function
|
||||
If 1<⍴⍴X, signal a RANK ERROR. | ||||
If 1=⍴⍴X and 3<⍴X, signal a LENGTH ERROR. | ||||
Normalize X by setting it to X←(-⍴⍴R)⌈(⍴⍴R)⌊1↑⌽3⍴⌽X. | ||||
The cells from R are of rank |X. | ||||
If X is positive, the cells from R are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, CR←(-X)↑⍴R is the shape of the righthand cells, and FR←(-X)↓⍴R is the shape of the righthand frame. | ||||
Loop through the frame applying f to the shape CR cells from R. | ||||
The result is the conforming disclose of the above. |
This dyadic operator is partially implemented by calling the following internal magic function:
∇ Z←(LO #MonRank X) R;O
[1] X←1⍴X
[2] O←⍴⍴R
[3] X←(-O)⌈O⌊X
[4] Z←LO¨⊂[⍳-X]R⋄→0
[5] ⎕PROTOTYPE:Z←⊃LO¨¨⊂[⍳-X]¨0⍴⊂R
∇
Dyadic Derived Function
|
||||
L and R are arbitrary arrays, f is an arbitrary dyadic function, and X is an integer scalar or vector. | ||||
If 1<⍴⍴X, signal a RANK ERROR. | ||||
If 1=⍴⍴X and 3<⍴X, signal a LENGTH ERROR. | ||||
Normalize X by setting it to X←(-(⍴⍴L),⍴⍴R)⌈((⍴⍴L),⍴⍴R)⌊1↓⌽3⍴⌽X. | ||||
The cells from L are of rank |X[⎕IO]; the cells from R are of rank |X[⎕IO+1]. | ||||
If 1↑X is positive, the cells from L are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, CL←(-1↑X)↑⍴L is the shape of the lefthand cells, and FL←(-1↑X)↓⍴L is the shape of the lefthand frame. | ||||
If 1↓X is positive, the cells from R are taken from the right end of the shape vector; if negative, the cells are taken from the left end of the shape vector. In particular, CR←(-1↓X)↑⍴R is the shape of the righthand cells, and FR←(-1↓X)↓⍴R is the shape of the righthand frame. | ||||
If FL and FR are both non-empty and (⍴FL)≠⍴FR, signal a RANK ERROR; if the shapes of FL and FR are the same, but their values differ, signal a LENGTH ERROR. | ||||
Loop through the frames (scalar extending as necessary) applying f between the shape CL cells from L and the shape CR cells from R. | ||||
The result is the conforming disclose of the above. |
This dyadic operator is partially implemented by calling the following internal magic function:
∇ Z←L (LO #DydRank X) R;O
[1] X←1↓⌽3⍴⌽X
[2] O←(⍴⍴L),⍴⍴R
[3] X←(-O)⌈O⌊X
[4] Z←(⊂[⍳-1↑X]L)LO¨⊂[⍳-1↓X]R⋄→0
[5] ⎕PROTOTYPE:Z←⊃(⊂[⍳-1↑X]¨0⍴⊂L)LO¨¨⊂[⍳-1↓X]¨0⍴⊂R
∇
Both of the above magic functions implement their respective derived function except for some final processing which is essentially a disclose but one which allows for mismatched ranks. That part is implemented by the following function where L has already been calculated as the maximum rank across all items:
∇ Z←L #Conform R
[1] Z←⊃(((L-∊⍴∘⍴¨R)⍴¨1),¨⍴¨R)⍴¨R
∇