Mask: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "{| class=vertical-navbox style="float:right; font-size:500%; margin:0 1ex;" |<math>/a,u,b/</math> |} In Iverson notation, '''Mask''' (<math>/a,u,b/</math>) is a three-argument operation which merges two arguments according to a Boolean array, all with matching shape. The relationship between Mask and Mesh is similar to that between Compress and Expand. The Case function can also be seen as a generalization of Mask. A related function also name...")
 
mNo edit summary
 
Line 16: Line 16:
For numeric arrays, Mask <math>/A,U,B/</math> can be defined algebraically as <syntaxhighlight lang=apl inline>(A×1-U)+B×U</syntaxhighlight> or <syntaxhighlight lang=apl inline>A+U×B-A</syntaxhighlight>, that is, a special case of [[wikipedia:linear interpolation|linear interpolation]]. Similarly, possible implementations for [[Boolean]] arrays include <syntaxhighlight lang=apl inline>(A∧~U)∨B∧U</syntaxhighlight> and <syntaxhighlight lang=apl inline>A≠U∧B≠A</syntaxhighlight>.
For numeric arrays, Mask <math>/A,U,B/</math> can be defined algebraically as <syntaxhighlight lang=apl inline>(A×1-U)+B×U</syntaxhighlight> or <syntaxhighlight lang=apl inline>A+U×B-A</syntaxhighlight>, that is, a special case of [[wikipedia:linear interpolation|linear interpolation]]. Similarly, possible implementations for [[Boolean]] arrays include <syntaxhighlight lang=apl inline>(A∧~U)∨B∧U</syntaxhighlight> and <syntaxhighlight lang=apl inline>A≠U∧B≠A</syntaxhighlight>.


The operation performed by Mask is often supported by dedicated instructions in [[wikipedia:SIMD|SIMD]] programming, often called "blend" instructions.
The operation performed by Mask may be supported by dedicated instructions in [[wikipedia:SIMD|SIMD]] programming, often called "blend" instructions.


=== Documentation ===
== Documentation ==


* [http://wiki.nars2000.org/index.php/Compose#Mask NARS2000]
* [http://wiki.nars2000.org/index.php/Compose#Mask NARS2000]
== References ==
<references />


[[Category:APL primitives]][[Category:Iverson notation]]
[[Category:APL primitives]][[Category:Iverson notation]]

Latest revision as of 02:43, 9 March 2024

In Iverson notation, Mask () is a three-argument operation which merges two arguments according to a Boolean array, all with matching shape. The relationship between Mask and Mesh is similar to that between Compress and Expand. The Case function can also be seen as a generalization of Mask. A related function also named Mask is implemented in NARS and NARS2000 as a case of Compose: L(a∘/)R combines L and R along one axis using an integer vector, which is negative to indicate values from the left argument and positive to indicate values from the right, with absolute value giving the number of repetitions.

A Programming Language defines the Mask for vectors and and Boolean vector , all of the same length, to be the vector whose compressions by and its negation match the compressions of the other arguments: and . The definition of Mesh differs from this in that it doesn't compress and , so that all elements from these arguments are used, while Mask discards half of the total elements. Various extensions are defined using compression on matrices, including and , which are identical because (for example) and select the same elements, only arranging them in a different order.

Iverson notes the following relationships between Mask, Mesh, Compress, and Expand:

For numeric arrays, Mask can be defined algebraically as (A×1-U)+B×U or A+U×B-A, that is, a special case of linear interpolation. Similarly, possible implementations for Boolean arrays include (A∧~U)∨B∧U and A≠U∧B≠A.

The operation performed by Mask may be supported by dedicated instructions in SIMD programming, often called "blend" instructions.

Documentation