Replicate: Difference between revisions

Jump to navigation Jump to search
1,264 bytes added ,  14:08, 13 March 2020
Outside of APL
(Extension support)
(Outside of APL)
Line 107: Line 107:


In each language without axis specification, there is only one form of Replicate, which always applies to the first axis or [[major cell]]s—the last-axis form is discarded.
In each language without axis specification, there is only one form of Replicate, which always applies to the first axis or [[major cell]]s—the last-axis form is discarded.
== Outside of APL ==
While Replicate is rarely used in non-array programming languages, Compress is sometimes seen. Usually the same functionality is provided by the higher-order function [[wikipedia:filter (higher-order function)|filter]], which an APLer might define as the [[monadic operator]] <source lang=apl inline>filter←{(⍺⍺¨ ⍵) / ⍵}</source> on a [[vector]] argument.
While filter is similar to Compress, some extensions to the [[wikipedia:x86|x86]] instruction set are exactly equivalent to Compress on particular data types. In [[wikipedia:BMI2|BMI2]], the PEXT and PDEP instructions (parallel bit extract and deposit) are identical to Compress and [[Expand]] on the bits of a register argument. Indeed, [[Dyalog APL]] uses these instructions to implement those primitives (see [[Dyalog APL#Instruction set usage]]). The [[wikipedia:AVX-512|AVX-512]] instructions VPCOMPRESSQ and VPEXPANDQ (and variations) are not only equivalent to Compress and Expand using a mask register for the [[Boolean]] argument and a vector register for the other argument, but are named after the APL functions. These instructions allow compression of 4-byte and 8-byte elements, and with AVX-512_VBMI2 support was added for 1-byte and 2-byte elements as well.


== External Links ==
== External Links ==

Navigation menu