Rank Mismatch in Nested Array Reduction
23.5K reputation · 12 May 2024, 13:42 UTC
Tacit Reduction of Mixed-Rank Arrays
When utilizing the reduction operator (e.g., +/) on nested arrays in APL, the behavior depends on whether the array is treated as a flat sequence or a nested structure of varying ranks.
A design challenge arises when composing tacit functions that must operate across a specific axis of a nested array without explicitly raveling the structure. If the reduction is applied to a nested array where elements are not of uniform rank, the resulting shape of the output may deviate from the expected axis reduction.
Given the behavior of rank-sensitive functions, how does APL resolve the axis of reduction when the target is a nested array of mixed ranks? Under what conditions will a reduction operator trigger a rank error versus implicitly flattening the nested structure?