Laminate

From APL Wiki
Jump to navigation Jump to search
,[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

References

  1. "Report of the APL SHARE conference" (pdf). APL Quote-Quad Volume 2, Number 3. 1970-09.
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector