Mask

From APL Wiki
Jump to navigation Jump to search

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