Pramod G. Joisha, U. Nagaraj Shenoy, Prithviraj Banerjee
Abstract
In this report, we address the problem of statically inferring the shape of an array in languages such as MATLAB. Inferred shapes are desirable from the standpoint of both program compilation and efficient interpretation because static knowledge of an array's shape could permit reductions in the number of run-time array conformability checks, enable memory preallocation optimizations, and facilitate efficient translations to ``scalar'' target languages such as C.
This report presents a framework for statically describing the shape of a MATLAB expression, using a methodology based on systematic matrix formulations. The representation exposes the algebraic properties that underlie MATLAB's shape semantics and exactly captures the shape that the expression assumes at run time. Some of the highlights of this framework are its applicability to a large class of MATLAB functions and the uniformity of its approach. We compare our methods with the traditional shadow variable scheme and demonstrate how the algebraic view permits powerful shape-related assertions and optimizations not possible in the conventional approach.