Ravel: Difference between revisions

Jump to navigation Jump to search
391 bytes added ,  05:52, 9 June 2020
m
Text replacement - " ⊢( *[^∘])" to " ⎕←$1"
Miraheze>Marshall
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1")
Tags: Mobile edit Mobile web edit
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
In the APL [[array model]], an array's ravel is the [[vector]] containing all its [[elements]] in [[ravel order]]. The Ravel function, which was introduced in [[APL\360]] and is universally spelled <code>,</code>, returns the ravel of an array. It is equivalent to [[Reshape|reshaping]] an array using its [[bound]] for the new [[shape]]. Reshaping the ravel using the original array's shape restores that array.
{{Built-in|Ravel|,}} is a [[primitive function]] introduced in [[APL\360]] which returns the ''ravel'' of an array. In the APL [[array model]], an array's ravel is the [[vector]] containing all its [[elements]] in [[ravel order]]. It is equivalent to [[Reshape|reshaping]] an array using its [[bound]] for the new [[shape]]. Reshaping the ravel using the original array's shape restores that array.


In some APLs an [[Function axis|axis]] may be specified for Ravel in order to combine only some [[Axis|axes]] of an array, or insert a length-1 axis.
In some APLs an [[Function axis|axis]] may be specified for Ravel in order to combine only some [[Axis|axes]] of an array, or insert a length-1 axis.


The name "ravel" is references the process of undoing woven or knitted fabric, thus removing its structure and rendering it linear.
The name "ravel" references the process of undoing woven or knitted fabric, thus removing its structure and rendering it linear.


== Examples ==
== Examples ==


You can use ravel to squash a [[matrix]] down to one dimension. The elements are listed in reading order—left to right, top to bottom.
You can use ravel to squash a [[matrix]] down to one dimension. The elements are listed in reading order—left to right, top to bottom.
<source class=apl>
<source lang=apl>
       ⊢x ← 3 4⍴⍳12            ⍝ A matrix
       ⎕←x ← 3 4⍴⍳12            ⍝ A matrix
1  2  3  4
1  2  3  4
5  6  7  8
5  6  7  8
Line 22: Line 22:


Ravelling a [[scalar]] yields a [[singleton]] [[vector]].
Ravelling a [[scalar]] yields a [[singleton]] [[vector]].
<source class=apl>
<source lang=apl>
       ,3
       ,3
3
3
Line 32: Line 32:


[[String]] notation cannot produce a single-character string since it produces a [[scalar]] character instead. Using Ravel on a list of characters in quotes ensures it will be a [[vector]] of characters.
[[String]] notation cannot produce a single-character string since it produces a [[scalar]] character instead. Using Ravel on a list of characters in quotes ensures it will be a [[vector]] of characters.
<source class=apl>
<source lang=apl>
       ≢⍴ 'a'                  ⍝ Scalar character
       ≢⍴ 'a'                  ⍝ Scalar character
0
0
Line 40: Line 40:


[[Function axis|Axis specification]] may accept either a [[vector]] of two or more adjacent [[axis]] [[Index|indices]], or a single non-integer value. If multiple axes are given, they are merged into one axis whose length is the product of their lengths. If only one value is given, a new axis of length 1 is inserted in the indicated "gap" between axes.
[[Function axis|Axis specification]] may accept either a [[vector]] of two or more adjacent [[axis]] [[Index|indices]], or a single non-integer value. If multiple axes are given, they are merged into one axis whose length is the product of their lengths. If only one value is given, a new axis of length 1 is inserted in the indicated "gap" between axes.
<source class=apl>
<source lang=apl>
       ⍴ ,[2 3] 5 4 3 2⍴0
       ⍴ ,[2 3] 5 4 3 2⍴0
5 12 2
5 12 2
Line 50: Line 50:
== Description ==
== Description ==


The ravel of an array <code>A</code> has shape <code>,×/⍴A</code> and shares elements with <code>A</code>. Thus Ravel may be modelled as a [[Reshape|reshaping]] function <code>{(×/⍴⍵)⍴⍵}</code>. The [[element]] with [[index]] [[vector]] <code>I</code> is moved to index <code>(⍴A)⊥I</code> in [[index origin]] 0, or <code>⎕IO+(⍴A)⊥I-⎕IO</code> in arbitrary index origin.
The ravel of an array <source lang=apl inline>A</source> has shape <source lang=apl inline>,×/⍴A</source> and shares elements with <source lang=apl inline>A</source>. Thus Ravel may be modelled as a [[Reshape|reshaping]] function <source lang=apl inline>{(×/⍴⍵)⍴⍵}</source>. The [[element]] with [[index]] [[vector]] <source lang=apl inline>I</source> is moved to index <source lang=apl inline>(⍴A)⊥I</source> in [[index origin]] 0, or <source lang=apl inline>⎕IO+(⍴A)⊥I-⎕IO</source> in arbitrary index origin.
 
As with any reshaping, the result of Ravel has the same [[prototype]] as the argument.


== History ==
== History ==
Line 56: Line 58:
Ravel was present in the first version of [[APL\360]]<ref>Falkoff, A.D., and K.E. Iverson. [https://www.jsoftware.com/papers/APL360TerminalSystem.htm "The APL\360 Terminal System"]. Research Report RC-1922, IBM, 1967-10-16.</ref> and has been included in every APL since.
Ravel was present in the first version of [[APL\360]]<ref>Falkoff, A.D., and K.E. Iverson. [https://www.jsoftware.com/papers/APL360TerminalSystem.htm "The APL\360 Terminal System"]. Research Report RC-1922, IBM, 1967-10-16.</ref> and has been included in every APL since.


== Documentation ==
== External links ==
 
=== Lessons ===
 
* [https://chat.stackexchange.com/transcript/52405?m=41726592#41726592 APL Cultivation]
 
=== Documentation ===


[http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Ravel.htm Dyalog] [http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Ravel%20with%20Axes.htm with axis]
* [http://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Ravel.htm Dyalog] ([http://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Ravel%20with%20Axes.htm with axis]),


J [https://www.jsoftware.com/help/dictionary/d320.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/comma NuVoc]  
* [http://wiki.nars2000.org/index.php/Rho NARS2000]


== Other Resources ==
* [http://microapl.com/apl_help/ch_020_020_480.htm APLX]


[https://chat.stackexchange.com/transcript/52405?m=41726592#41726592 APL Cultivation]
* [https://www.jsoftware.com/help/dictionary/d320.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/comma J NuVoc]


== References ==
== References ==
Line 70: Line 78:
<references />
<references />


{{APL programming language}}
{{APL features}}
{{APL built-ins}}[[Category:Primitive functions]]

Navigation menu