Indexing: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 4: Line 4:
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <tr>
     <tr>
       <td><apll>Z←R[L]</apll>, <apll>R[L]←A</apll>, and <apll>R[L]<i>f</i>←A</apll></td>
       <td valign="top"><apll>Z←R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
Line 22: Line 22:
</tr>
</tr>
<tr>
<tr>
   <td><b>Reach Indexing</b>:  If <apll>L⊃R</apll> is valid, it is equivalent to <apll>⊃R[⊂L]</apll></td>
   <td><apll><i>f</i></apll> is an arbitrary function.</td>
</tr>
</tr>
<tr>
<tr>
   <td><b>Scatter Indexing</b>: If <apll>L⌷R</apll> is valid, it is equivalent to <apll>R[⊃∘.,/L]</apll></td>
   <td><table border="0" cellpadding="0" cellspacing="0" summary="">
    <tr>
      <td><b>Reach Indexing</b>:&nbsp;&nbsp;</td>
      <td>If <apll>L⊃R</apll> is valid, it is equivalent to <apll>⊃R[⊂L]</apll>, and</td>
    </tr>
    <tr>
      <td></td>
      <td>if <apll>L⊃¨⊂R</apll> is valid, it is equivalent to <apll>R[L]</apll></td>
    </tr>
    <tr>
      <td><b>Scatter Indexing</b>:&nbsp;&nbsp;</td>
      <td>If <apll>L⌷R</apll> is valid, it is equivalent to <apll>R[⊃∘.,/L]</apll>, and</td>
    <tr>
      <td></td>
      <td>if <apll>L⌷¨⊂R</apll> is valid, it is equivalent to <apll>⊂¨R[⊂¨L]</apll></td>
    </tr>     
</table>
</tr>
</tr>
<tr>
<tr>
   <td>Both Reach and Scatter indexing may appear together within a single instance of <apll>R[L]</apll>, <apll>R[L]←A</apll>, and <apll>R[L]<i>f</i>←A</apll></td>
   <td>Both Reach and Scatter indexing may appear together within a single instance of <apll>R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll></td>
</tr>
<tr>
  <td>These functions are sensitive to <apll>⎕IO</apll>.</td>
</tr>
</tr>
</table>
</table>
Line 34: Line 53:
<p>For example, in origin-1</p>
<p>For example, in origin-1</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V←'123'(⊂4 5)</apll><br />
<apll><pre>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V[1 (2 ⍬ 1)]</apll><br />
      V←'123'(⊂4 5)
<apll>&nbsp;123 4</apll>
      V[1 (2 ⍬ 1)]
 
123 4
 
      M←2 2⍴(10 20) (30 40 'abc') 50 60
      M[(1 1)((1 2) 3)]
10 20  abc</pre></apll>
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
<tr>
Line 44: Line 65:
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <tr>
     <tr>
       <td><apll>Z←R[L]</apll>, <apll>R[L]←A</apll>, <apll>R[L]<i>f</i>←A</apll>, <apll>L⌷R</apll>, and <apll>L⊃R</apll></td>
       <td valign="top"><apll>Z←R[L]</apll>, &nbsp;&nbsp; <apll>R[L]←A</apll>, &nbsp;&nbsp; <apll>R[L]<i>f</i>←A</apll>, &nbsp;&nbsp; <apll>L⌷[X] R</apll>, &nbsp;&nbsp; <apll>L⍉R</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>L⊃R</apll></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td>are all extended to allow negative index values.</td>
       <td>are all extended to allow negative values in <apll>L</apll>.</td>
     </tr>
     </tr>
     </table>
     </table>
Line 53: Line 74:
</tr>
</tr>
<tr>
<tr>
   <td><apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>.</td>
   <td>For all but transpose, <apll>L</apll> is a nested array of integer scalars and/or vectors, suitable for indexing <apll>R</apll>; for transpose, <apll>L</apll> is an integer scalar or vector of integers, suitable for transposing <apll>R</apll>.</td>
</tr>
</tr>
<tr>
<tr>
   <td>That is, if the largest allowed index value is <apll>N</apll>, then the previous allowable range of values was <apll>⎕IO</apll> to <apll>N</apll>, inclusive.  Now, the allowable range of values is <apll>1 ¯1[1]-N</apll> to <apll>N</apll>, inclusive.  For example, <apll>A</apll>, <apll>A[⍳⍴A]</apll>, and <apll>A[⍳-⍴A]</apll> are all identical for any array <apll>A</apll> in either origin.</td>
   <td>That is, if the largest allowed value for <apll>L</apll> is <apll>N</apll>, then the previous allowable range of values was <apll>⎕IO</apll> to <apll>N</apll>, inclusive.  Now, the allowable range of values is <apll>1 ¯1[1]-N</apll> to <apll>N</apll>, inclusive.  For example, &nbsp;&nbsp; <apll>A</apll>, &nbsp;&nbsp; <apll>A[⍳⍴A]</apll>, &nbsp;&nbsp; <apll>A[⍳-⍴A]</apll>, &nbsp;&nbsp; and even &nbsp;&nbsp; <apll>A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]</apll> &nbsp;&nbsp; are all identical for any array <apll>A</apll> in either origin.<br />Also, &nbsp;&nbsp; <apll>A</apll>, &nbsp;&nbsp; <apll>(⍳⍴⍴A)⍉A</apll>, &nbsp;&nbsp; and &nbsp;&nbsp; <apll>(⍳-⍴⍴A)⍉A</apll> &nbsp;&nbsp; are all identical for any array <apll>A</apll> in either origin.</td>
</tr>
</tr>
<tr>
<tr>
Line 63: Line 84:
<tr>
<tr>
   <td><apll>A</apll> is an arbitrary array.</td>
   <td><apll>A</apll> is an arbitrary array.</td>
</tr>
<tr>
  <td>These functions are sensitive to <apll>⎕IO</apll>.  Negative indexing is available only when the first element of <apll>⎕FEATURE</apll> is set to <apll>1</apll>.</td>
</tr>
</tr>
</table>
</table>
Line 68: Line 92:
<p>For example, in origin-1</p>
<p>For example, in origin-1</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V←'123'(⊂4 5)</apll><br />
<apll><pre>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;V[¯1 (0 ⍬ ¯1)]</apll><br />
      ⎕FEATURE[1]←1
<apll>&nbsp;123 4</apll>
      V←'123'(⊂4 5)
      V[¯1 (0 ⍬ ¯1)]
123 4</pre></apll>

Latest revision as of 13:11, 30 June 2018

Z←R[L],    R[L]←A,    and    R[L]f←A are all extended to allow both Reach and Scatter indexing.
L is a nested array of integer scalars and/or vectors, suitable for indexing R.
R is an arbitrary array.
A is an arbitrary array.
f is an arbitrary function.
Reach Indexing:   If L⊃R is valid, it is equivalent to ⊃R[⊂L], and
if L⊃¨⊂R is valid, it is equivalent to R[L]
Scatter Indexing:   If L⌷R is valid, it is equivalent to R[⊃∘.,/L], and
if L⌷¨⊂R is valid, it is equivalent to ⊂¨R[⊂¨L]
Both Reach and Scatter indexing may appear together within a single instance of R[L],    R[L]←A,    and    R[L]f←A
These functions are sensitive to ⎕IO.


For example, in origin-1

      V←'123'(⊂4 5)
      V[1 (2 ⍬ 1)]
 123 4
      M←2 2⍴(10 20) (30 40 'abc') 50 60
      M[(1 1)((1 2) 3)]
 10 20  abc
Z←R[L],    R[L]←A,    R[L]f←A,    L⌷[X] R,    L⍉R,    and    L⊃R are all extended to allow negative values in L.
For all but transpose, L is a nested array of integer scalars and/or vectors, suitable for indexing R; for transpose, L is an integer scalar or vector of integers, suitable for transposing R.
That is, if the largest allowed value for L is N, then the previous allowable range of values was ⎕IO to N, inclusive. Now, the allowable range of values is 1 ¯1[1]-N to N, inclusive. For example,    A,    A[⍳⍴A],    A[⍳-⍴A],    and even    A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]    are all identical for any array A in either origin.
Also,    A,    (⍳⍴⍴A)⍉A,    and    (⍳-⍴⍴A)⍉A    are all identical for any array A in either origin.
R is an arbitrary array.
A is an arbitrary array.
These functions are sensitive to ⎕IO. Negative indexing is available only when the first element of ⎕FEATURE is set to 1.


For example, in origin-1

      ⎕FEATURE[1]←1
      V←'123'(⊂4 5)
      V[¯1 (0 ⍬ ¯1)]
 123 4