Index Generator: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 87: Line 87:
<apll>&nbsp;2 ¯2&nbsp;&nbsp;2 ¯1&nbsp;&nbsp;2 0</apll>
<apll>&nbsp;2 ¯2&nbsp;&nbsp;2 ¯1&nbsp;&nbsp;2 0</apll>


<p>In both of the above extensions it is always the case that, for an arbitrary array <apll>A</apll>, the following arrays <apll>A</apll>, <apll>A[⍳⍴A]</apll>, <apll>A[⍳-⍴A]</apll>, and even <apll>A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]</apll> are all identical.</p>
<br />
<br />
 
<p>For example, taking into account both of the above extensions, <apll>A</apll>, <apll>A[⍳⍴A]</apll>, <apll>A[⍳-⍴A]</apll>, and even <apll>A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A]</apll> are all identical for an arbitrary array <apll>A</apll> in either origin.</p>





Revision as of 21:53, 14 April 2008

Z←⍳R returns a vector of consecutive ascending integers.
R is a negative integer scalar or one-element vector.
Z is an integer vector of length |Rwhose values range from ⎕IO+R to ⎕IO-1.
This feature extends monadic iota to negative arguments.


For example, in origin-0

      ⍳3
0 1 2

      ⍳¯3
¯3 ¯2 ¯1

and in origin-1

      ⍳3
1 2 3

      ⍳¯3
¯2 ¯1 0

This function is used to create Arithmetic Progression Arrays (APAs). For example, Z←2 3 4⍴⍳24 has a very compact storage consisting of the array shape (2 3 4), the starting offset (⎕IO) and multiplier (1), plus the normal array overhead (which includes the number of elements (24)).


Z←⍳R returns an array of integer indices suitable for indexing all the elements of an array of shape |R.
R is an integer vector of length > 1.
Z is a nested array of shape |R whose items are each integer vectors of length ⍴⍴R and whose values range from ⎕IO+R to (⍴R)⍴⎕IO-1.
This feature extends monadic iota to multi-element vector arguments.


For example, in origin-0

      ⍳2 3
 0 0  0 1  0 2
 1 0  1 1  1 2

      ⍳2 ¯3
 0 ¯3  0 ¯2  0 ¯1
 1 ¯3  1 ¯2  1 ¯1

and in origin-1

      ⍳2 3
 1 1  1 2  1 3
 2 1  2 2  2 3

      ⍳2 ¯3
 1 ¯2  1 ¯1  1 0
 2 ¯2  2 ¯1  2 0



For example, taking into account both of the above extensions, A, A[⍳⍴A], A[⍳-⍴A], and even A[⍳¯1 1[?(⍴⍴A)⍴2]×⍴A] are all identical for an arbitrary array A in either origin.


This last extension is implemented via an internal magic function due to Carl M. Cheney:

    ∇ Z←#MonIota V
[1]   Z←⊃∘.,/⍳¨V
    ∇