Laminate: Difference between revisions
(Created page with "{{Built-in|Laminate|,[0.5]}} is a case of the Catenate function with axis that joins its argument arrays along a new length-2 axis. It applies whenever the function axis is non-integral, but is typically written with a half-integer axis. Possible choices of axis range from <syntaxhighlight lang=apl inline>,[⎕IO-0.5]</syntaxhighlight>, which places the new axis before any argument axis, to <syntaxhighlight lang=apl inline>,[r+⎕IO-0.5]</syntax...") |
(History) |
||
Line 1: | Line 1: | ||
{{Built-in|Laminate|,[0.5]}} is a case of the [[Catenate]] function [[function axis|with axis]] that joins its argument arrays along a new length-2 [[axis]]. It applies whenever the function axis is non-integral, but is typically written with a half-integer axis. Possible choices of axis range from <syntaxhighlight lang=apl inline>,[⎕IO-0.5]</syntaxhighlight>, which places the new axis before any argument axis, to <syntaxhighlight lang=apl inline>,[r+⎕IO-0.5]</syntaxhighlight>, where <syntaxhighlight lang=apl inline>r</syntaxhighlight> is the shared argument [[rank]], which places it after all argument axes. Laminate appears as a stand-alone function in some languages, with the name Laminate in [[A+]] (<syntaxhighlight lang=apl inline>~</syntaxhighlight>) and [[J]] (<syntaxhighlight lang=j inline>,:</syntaxhighlight>), and Couple in [[BQN]] (<code>≍</code>) and [[Uiua]] (<code>⊟</code>). These languages implement the <syntaxhighlight lang=apl inline>,[⎕IO-0.5]</syntaxhighlight> case only, as the [[Rank operator]] can be used to add the axis in a later position, in accordance with [[leading axis theory]]. | {{Built-in|Laminate|,[0.5]}} is a case of the [[Catenate]] function [[function axis|with axis]] that joins its argument arrays along a new length-2 [[axis]]. It applies whenever the function axis is non-integral, but is typically written with a half-integer axis. Possible choices of axis range from <syntaxhighlight lang=apl inline>,[⎕IO-0.5]</syntaxhighlight>, which places the new axis before any argument axis, to <syntaxhighlight lang=apl inline>,[r+⎕IO-0.5]</syntaxhighlight>, where <syntaxhighlight lang=apl inline>r</syntaxhighlight> is the shared argument [[rank]], which places it after all argument axes. Laminate appears as a stand-alone function in some languages, with the name Laminate in [[A+]] (<syntaxhighlight lang=apl inline>~</syntaxhighlight>) and [[J]] (<syntaxhighlight lang=j inline>,:</syntaxhighlight>), and Couple in [[BQN]] (<code>≍</code>) and [[Uiua]] (<code>⊟</code>). These languages implement the <syntaxhighlight lang=apl inline>,[⎕IO-0.5]</syntaxhighlight> case only, as the [[Rank operator]] can be used to add the axis in a later position, in accordance with [[leading axis theory]]. | ||
Laminate was defined as an extension to Catenate in [[APL\360]] in 1970.<ref>"Report of the APL SHARE conference" ([https://dl.acm.org/action/showBmPdf?doi=10.1145%2F987461 pdf]). [[APL Quote-Quad]] Volume 2, Number 3. 1970-09.</ref> | |||
== Examples == | == Examples == | ||
Line 63: | Line 65: | ||
* [https://www.uiua.org/docs/couple Uiua] | * [https://www.uiua.org/docs/couple Uiua] | ||
== References == | |||
<references/> | |||
{{APL built-ins}}[[Category:Primitive functions]][[Category:Leading axis theory]] | {{APL built-ins}}[[Category:Primitive functions]][[Category:Leading axis theory]] |
Latest revision as of 01:30, 18 March 2024
,[0.5]
|
Laminate (,[0.5]
) is a case of the Catenate function with axis that joins its argument arrays along a new length-2 axis. It applies whenever the function axis is non-integral, but is typically written with a half-integer axis. Possible choices of axis range from ,[⎕IO-0.5]
, which places the new axis before any argument axis, to ,[r+⎕IO-0.5]
, where r
is the shared argument rank, which places it after all argument axes. Laminate appears as a stand-alone function in some languages, with the name Laminate in A+ (~
) and J (,:
), and Couple in BQN (≍
) and Uiua (⊟
). These languages implement the ,[⎕IO-0.5]
case only, as the Rank operator can be used to add the axis in a later position, in accordance with leading axis theory.
Laminate was defined as an extension to Catenate in APL\360 in 1970.[1]
Examples
A typical use of Laminate is to form a matrix from two vectors, using them as rows (examples use ⎕IO←1
).
'abcd' ,[0.5] 'efgh' abcd efgh
However, Laminate can be used more generally to pair up cells of the arguments, for example, by laminating along the last axis to pair elements of two shape 3 3
arrays.
(3 3⍴⍳9) ,[2.5] 3 3⍴'abcdefghi' 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i
As with Catenate, a scalar argument is subject to scalar extension: its rank is brought up to match that of the other argument by repeating its value.
'x' ,[0.5] 'efgh' xxxx efgh
Extension support
APL's scalar extension is retained in A+ and J, but removed in BQN, which instead requires argument shapes to match exactly. Since J extends scalar extension to leading axis agreement for arithmetic, Laminate is one of a fairly small number of cases where scalars are treated specially. J extends Laminate further to handle any combination of argument shapes by padding a lower-rank argument with leading 1s in the shape and then padding any short axes with fills. This matches the padding behavior used by Rank and other operators to merge result cells into a single array.
Language | Syntax | Conformability |
---|---|---|
APL | ,[0.5] |
Possibly scalar or singleton extension |
A+ | ~ |
Scalar extension |
J | ,: |
Scalar extension; pads to conform rank and axes |
BQN | ≍ |
Strict |
Uiua | ⊟ |
Strict |
Additionally, in J, laminating two scalars gives a result of shape 2 1
rather than 2
.
Documentation
- In APL: see Catenate
- J NuVoc, Dictionary
- BQN
- Uiua
References
- ↑ "Report of the APL SHARE conference" (pdf). APL Quote-Quad Volume 2, Number 3. 1970-09.