Case: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(No idea what to call this page)
 
(Reference Mask rather than SIMD blend)
 
Line 1: Line 1:
{{Built-in|Case|%}}, or '''Merge''', is a [[dyadic]] [[primitive]] function in [[Kap]] and [[dzaima/APL]] that forms an array by mixing [[element]]s taken from a [[vector]] of arrays according to an array of [[index|indices]]. It's closely related to the [[J]] adverb ([[monadic operator]]) Composite Item <syntaxhighlight lang=j inline>}</syntaxhighlight>, which differs in that the right argument is an array whose [[major cell]]s are mixed together. It can also be considered a generalization of a blend instruction in [[wikipedia:SIMD|SIMD]] programming, which chooses between two arguments based on a boolean mask, an operation that might be written <syntaxhighlight lang=apl inline>(A∧~M)∨(B∧M)</syntaxhighlight> in APL.
{{Built-in|Case|%}}, or '''Merge''', is a [[dyadic]] [[primitive]] function in [[Kap]] and [[dzaima/APL]] that forms an array by mixing [[element]]s taken from a [[vector]] of arrays according to an array of [[index|indices]]. It's closely related to the [[J]] adverb ([[monadic operator]]) Composite Item <syntaxhighlight lang=j inline>}</syntaxhighlight>, which differs in that the right argument is an array whose [[major cell]]s are mixed together. It can also be considered a generalization of [[Mask]], which chooses between two arguments based on a boolean mask and might be implemented as <syntaxhighlight lang=apl inline>(A∧~M)∨(B∧M)</syntaxhighlight>.


The following example shows how Case may be used to mix three vectors together:
The following example shows how Case may be used to mix three vectors together:

Latest revision as of 02:25, 9 March 2024

%

Case (%), or Merge, is a dyadic primitive function in Kap and dzaima/APL that forms an array by mixing elements taken from a vector of arrays according to an array of indices. It's closely related to the J adverb (monadic operator) Composite Item }, which differs in that the right argument is an array whose major cells are mixed together. It can also be considered a generalization of Mask, which chooses between two arguments based on a boolean mask and might be implemented as (A∧~M)∨(B∧M).

The following example shows how Case may be used to mix three vectors together:

      3 2 1 2 3 % 'abcde' 'ABCDE' '01234'
0BcD4
Works in: dzaima/APL

The right argument is a vector of arrays all of the same shape, and the left argument is a simple numeric array with the same shape as each element of the right argument as well as the result. The result value at a given position is taken from the same position in the i'th right argument array, where i is the index at that position in the left argument.

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
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 axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector