Abstract
The problem of inferring array shapes ahead of time in languages that exhibit both implicit and dynamic typing is a critical one because the ramifications of its solution are the better organization of array storage through compaction and reuse, and the generation of high-performance code through specialization by shape. This article addresses the problem in a prototypical implicitly and dynamically typed array language called MATLAB. The approach involves modeling the language's shape semantics using an algebraic system, and applying term rewriting techniques to evaluate expressions under this algebra. Unlike prior efforts at array shape determination, this enables the deduction of valuable shape information even when array extents are compile-time unknowns. Furthermore, unlike some previous methods, our approach doesn't impose monotonicity requirements on an operator's shape semantics. The work also describes an inference methodology and reports measurements from a type inference engine called MAGICA. In a benchmark suite of 17 programs, the shape inference subsystem in MAGICA detected the equivalence of over 61% of the symbolic shapes in six programs, and over 57% and 37% of the symbolic shapes in two others. In the remaining nine programs, all array shapes were inferred to be compile-time constants.
- Adams, J. C., Brainerd, W. S., Martin, J. T., Smith, B. T., and Wagener, J. L. 1992. FORTRAN 90 Handbook. McGraw-Hill, New York.]]Google Scholar
- Almási, G. 2001. MaJIC: A MATLAB Just-In-Time Compiler. Ph.D. thesis, University of Illinois at Urbana-Champaign.]]Google Scholar
- Almási, G. and Padua, D. A. 2002. MAJIC: Compiling MATLAB for speed and responsiveness. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, New York, 294--303.]] Google Scholar
- Ancourt, C. and Nguyen, T. V. N. 2001. Array resizing for scientific code debugging, maintenance and reuse. In Proceedings of the ACM SIGPLAN/SIGSOFT Workshop on Program Analysis for Software Tools and Engineering. ACM, New York, 32--37.]] Google Scholar
- Banerjee, U. 1993. Loop Transformations for Restructuring Compilers: The Foundations. Kluwer Academic, Norwell, MA.]] Google Scholar
- Budd, T. 1988. An APL Compiler. Springer Verlag, New York City.]] Google Scholar
- Chauveau, S. and Bodin, F. 1998. Menhir: An Environment for high performance MATLAB. In Proceedings of the 4th International Workshop on Languages, Compilers, and Runtime Systems. LNCS, vol. 1511. Springer Verlag, 27--40.]] Google Scholar
- Ching, W.-M. 1986. Program analysis and code generation in an APL/370 compiler. IBM J. Res. Dev. 30, 6 (Nov.), 594--602.]] Google Scholar
- Cytron, R., Ferrante, J., Rosen, B. K., and Wegman, M. N. 1991. Efficiently computing static single assignment form and the control dependence graph. ACM Trans. Program. Lang. Syst. 13, 4 (Oct.), 451--490.]] Google Scholar
- De Rose, L. A. 1996. Compiler techniques for MATLAB programs. Ph.D. thesis, University of Illinois at Urbana-Champaign.]] Google Scholar
- De Rose, L. A. and Padua, D. A. 1999. Techniques for the translation of MATLAB programs into FORTRAN 90. ACM Trans. Program. Lang. Syst. 21, 2 (Mar.), 286--323.]] Google Scholar
- Dershowitz, N. and Plaisted, D. A. 2001. Rewriting. In Handbook of Automated Reasoning, A. Robinson and A. Voronkov, eds. vol. 1. Elsevier, Amsterdam, The Netherlands.]]Google Scholar
- Gupta, R. 1993. Optimizing array bounds checks using flow analysis. ACM Lett. Program. Lang. Syst. 2, 1--4, 135--150.]] Google Scholar
- Hindley, J. R. 1969. The principal type-scheme of an object in combinatory logic. Trans. American Math. Society 146, 29--60.]]Google Scholar
- Jay, B. C. and Steckler, P. A. 1998. The functional imperative: Shape! In Proceedings of the 7th European Symposium On Programming. LNCS, vol. 1381. Springer Verlag, 139--153.]] Google Scholar
- Joisha, P. G. 2003. A type inference system for MATLAB with applications to code optimization. Ph.D. thesis, Northwestern University.]] Google Scholar
- Joisha, P. G. and Banerjee, P. 2001a. Computing array shapes in MATLAB. In Proceedings of the 14th International Workshop on Languages and Compilers for Parallel Computing. Lecture Notes in Computer Science, vol. 2624. Springer Verlag.]]Google Scholar
- Joisha, P. G. and Banerjee, P. 2001b. Correctly detecting intrinsic type errors in typeless languages such as MATLAB. In Proceedings of the ACM SIGAPL Conference on Array Processing Languages. ACM, New York, 6--21.]] Google Scholar
- Joisha, P. G. and Banerjee, P. 2002. Implementing an array shape inference system for MATLAB using Mathematica. Tech. Rep. CPDC--TR--2002--10--003, Northwestern University.]]Google Scholar
- Joisha, P. G. and Banerjee, P. 2003a. Static array storage optimization in MATLAB. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, New York, 294--303.]] Google Scholar
- Joisha, P. G. and Banerjee, P. 2003b. The MAGICA type inference engine for MATLAB. In Proceedings of the 12th International Conference on Compiler Construction. Lecture Notes in Computer Science, vol. 2622. Springer Verlag, 121--125.]]Google Scholar
- Joisha, P. G., Shenoy, U. N., and Banerjee, P. 2000. An approach to array shape determination in MATLAB. Tech. Rep. CPDC--TR--2000--10--010, Northwestern University.]]Google Scholar
- Kaplan, M. A. and Ullman, J. D. 1978. A general scheme for the automatic inference of variable types. In Proceedings of the 5th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, New York, 60--75.]] Google Scholar
- Knight, K. 1989. Unification: A multidisciplinary survey. ACM Comput. Surv. 21, 1, 93--124.]] Google Scholar
- Malishevsky, A. 1998. Implementing a runtime library for a parallel MATLAB compiler. M.S. thesis, Oregon State University.]]Google Scholar
- McCosh, C. 2003. Type-Based specialization in a telescoping compiler for MATLAB. Tech. Rep. TR03--412, Rice University.]]Google Scholar
- Milner, R. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 3 (Dec.), 348--375.]]Google Scholar
- Mitchell, J. C. 1996. Foundations for Programming Languages. The MIT Press, Cambridge, MA.]] Google Scholar
- Muchnick, S. S. 1997. Advanced Compiler Design and Implementation. Morgan Kaufmann, San Francisco, CA.]] Google Scholar
- Quinn, M. J., Malishevsky, A., Seelam, N., and Zhao, Y. 1998. Preliminary results from a parallel MATLAB compiler. In Proceedings of the 12th International Parallel Processing Symposium and 9th Symposium on Parallel and Distributed Processing, S. Sahni, Ed. IEEE Computer Society Press, 81--87.]] Google Scholar
- Robinson, J. A. 1965. A machine-oriented logic based on the resolution principle. J. Association Comput. Mach. 12, 1 (Jan.), 23--41.]] Google Scholar
- Tenenbaum, A. M. 1974. Type determination in very high-level languages. Ph.D. thesis, Rep. NSO-3, New York University.]] Google Scholar
- The MathWorks, Inc. 1997. MATLAB: The Language of Technical Computing. The MathWorks, Inc. Using MATLAB (Version 5).]]Google Scholar
- The MathWorks, Inc. 2002a. Accelerating MATLAB: The MATLAB JIT-Accelerator. At http://www.mathworks.com/company/newsletters/digest/sept02/accel_matlab.pdf.]]Google Scholar
- The MathWorks, Inc. 2002b. The MathWorks announces release 13 with major new versions of MATLAB and Simulink. At http://www.mathworks.com/company/pressroom/index.shtml/article/332.]]Google Scholar
- Tremblay, J. P. and Manohar, R. 1975. Discrete Mathematical Structures with Applications to Computer Science. Computer Science Series. McGraw-Hill, New York.]] Google Scholar
- Walther, C. 1988. Many-Sorted unification. J. Assoc. Comput. Mach. 35, 1, 1--17.]] Google Scholar
- Weisstein, E. W. 2005. Hilbert matrix; From MathWorld---A Wolfram web resource. At http://mathworld.wolfram.com/HilbertMatrix.html.]]Google Scholar
- Wiedmann, C. 1979. Steps toward an APL compiler. In Proceedings of the ACM SIGAPL Conference on Array Processing Languages, A. Anger, Ed. ACM, New York, 321--328.]] Google Scholar
- Wolfram, S. 1999. The Mathematica Book, 4th ed. Wolfram Media, Champaign, IL.]] Google Scholar
- Xi, H. and Pfenning, F. 1998. Eliminating array bound checking through dependent types. In Proceedings of the ACM SIGPLAN Conference on Programming Language, Design, and Implementation. ACM, New York, 249--257.]] Google Scholar
Index Terms
An algebraic array shape inference system for MATLAB®
Recommendations
Just-in-time shape inference for array-based languages
ARRAY'14: Proceedings of ACM SIGPLAN International Workshop on Libraries, Languages, and Compilers for Array ProgrammingIn dynamic array-based languages, the most computationally intensive parts of the program often involve either explicit loops or vector operations. These loops and vector operations can be better optimized if the compiler has accurate information about ...
Computing array shapes in MATLAB
LCPC'01: Proceedings of the 14th international conference on Languages and compilers for parallel computingThis paper deals with the problem of statically inferring the shape of an array in languages such as MATLAB. Inferring an array's shape is desirable because it empowers better compilation and interpretation; specifically, knowing an array's shape could ...
Coarse-to-fine statistical shape model by Bayesian inference
ACCV'07: Proceedings of the 8th Asian conference on Computer vision - Volume Part IIn this paper, we take a predefined geometry shape as a constraint for accurate shape alignment. A shape model is divided in two parts: fixed shape and active shape. The fixed shape is a user-predefined simple shape with only a few landmarks which can ...






Comments