Impressum/Kontaktparent nodes: implemented functions

⌷ Index

testAplIndex
| table result |
"http://www.microapl.co.uk/apl_help/ch_020_020_620.htm"

"data aplIndex: indexArray"

"The aplIndex: function selects from the data according to the index. The index cannot be of depth greater than 2. Each element in the index addresses successive dimensions of datas and multiple index selections may be formed by creating a suitably nested vector. The dimensions specified in the index are used in the same order as with the aplShape function, that is columns last, preceded by rows and so on."

"Scalar for vector indexing - only one dimension"
self assert: 2 asApl = (#(1 2 3 4 5) asApl aplIndex:2).

"Nested scalar for multiple index"
self assert: #(3 4) asApl = (#(1 2 3 4 5) asApl aplIndex:#(3 4) asApl aplEnclose).

table := 10 aplInterval aplReshape:#(2 5).
self assert: 8 asApl = (table aplIndex:#(2 3)).

"Second element of the indexing vector is the enclosed vector 2 3"
self assert: #(7 8) asApl = (table aplIndex:#(2 #(2 3))).

"Nested 2 element vector for multiple index. Result is rows 1 2 and columns 2 3"
result := #(2 3 7 8) aplReshape:#(2 2).
self assert: result = (table aplIndex:#( #(1 2) #(2 3))).

"If the index function is given an empty index Array on a scalar, it will return the scalar as the result."
self assert: 37 asApl = (37 asApl aplIndex:0 aplInterval).

"Index with axis"
"data aplIndex:index onAxis:axis"

"Index can be used with an axis specification. In this case the index array only applies to those axes specified. Other axes are not indexed."

"Select the second member of the first dimension - the rows"
self assert: #(6 7 8 9 10) asApl = (table aplIndex:2 onAxis:1).

"Select the second and third members of the second dimension - the columns"
result := #(2 3 7 8) aplReshape:#(2 2).
self assert: result = (table aplIndex: #(2 3) asApl aplEnclose onAxis:2).