Impressum/Kontakt parent nodes: implemented functions

Compress


testAplCompress
| marks pass table result |
"http://www.microapl.co.uk/apl_help/ch_020_020_840.htm"

"When used with a simple numeric scalar or vector operand the aplCompress: operator is used to perform the compression or replication functions. The context in which aplCompress is used will make the type of operation apparent."

"Compression data aplCompress: compress"

"The compress argument is a vector of 1's and 0's. The data must conform in length. With a matrix data the dimension on which the operator works must be of the same length as the compress argument. For each 1 in the compress argument, the corresponding data element is selected. For each 0, the corresponding data element is ignored. If a single 1 or 0 is used as the compress argument, scalar extension ensures that none (0) or all (1) of the data is selected."


"The letters in the same positions as the 1's are selected"
self assert: 'BD' asApl = ('ABCD' asApl aplCompress:#(0 1 0 1)).

"20 corresponds with the only 0 and is ignored"
self assert: #(12 14 16 18) asApl = (#(12 14 16 18 20) asApl aplCompress:#(1 1 1 1 0)).


"Each mark greater than or equal to 50 puts a 1 in PASS. Those less than 50 produce 0's. The numbers corresponding to 1's are selected"
marks := #(45 60 33 50 66 19) asApl.
pass := marks >= 50.
self assert: #(60 50 66) asApl = (marks aplCompress: pass).


"Which members of MARK were 50? The fourth. Note the AplVector result"
self assert:#(4) asApl = ((marks aplShape aplInterval) aplCompress:(marks aplEqual:50)).

"The 1 or 0 compress argument to aplCompress: can be used to select whether the text is selected or not. Note that a string is allways an AplVector."
self assert:'FREDERIC' asApl = ('FREDERIC' asApl aplCompress:1).
self assert:'' asApl = ('FREDERIC' asApl aplCompress:0).

"Select on the last dimension-columns"
table := 6 aplInterval aplReshape:#(2 3).
result := #(2 5) aplReshape: #(2 1).
self assert: result = (table aplCompress:#(0 1 0)).

"Select on the first dimension-rows."
self assert: (#(1 2 3) aplReshape:#(1 3))= (table aplCompress:#(1 0) onAxis:1).

"The compression operation, aplCompress:, applies by default to the last dimension, although it may be used in conjunction with the axis operator, onAxis: "