skip to main content
article
Free Access

An algebraic array shape inference system for MATLAB®

Published:01 September 2006Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle Scholar
  2. Almási, G. 2001. MaJIC: A MATLAB Just-In-Time Compiler. Ph.D. thesis, University of Illinois at Urbana-Champaign.]]Google ScholarGoogle Scholar
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle Scholar
  5. Banerjee, U. 1993. Loop Transformations for Restructuring Compilers: The Foundations. Kluwer Academic, Norwell, MA.]] Google ScholarGoogle Scholar
  6. Budd, T. 1988. An APL Compiler. Springer Verlag, New York City.]] Google ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. Ching, W.-M. 1986. Program analysis and code generation in an APL/370 compiler. IBM J. Res. Dev. 30, 6 (Nov.), 594--602.]] Google ScholarGoogle Scholar
  9. 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 ScholarGoogle Scholar
  10. De Rose, L. A. 1996. Compiler techniques for MATLAB programs. Ph.D. thesis, University of Illinois at Urbana-Champaign.]] Google ScholarGoogle Scholar
  11. 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 ScholarGoogle Scholar
  12. 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 ScholarGoogle Scholar
  13. Gupta, R. 1993. Optimizing array bounds checks using flow analysis. ACM Lett. Program. Lang. Syst. 2, 1--4, 135--150.]] Google ScholarGoogle Scholar
  14. Hindley, J. R. 1969. The principal type-scheme of an object in combinatory logic. Trans. American Math. Society 146, 29--60.]]Google ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. Joisha, P. G. 2003. A type inference system for MATLAB with applications to code optimization. Ph.D. thesis, Northwestern University.]] Google ScholarGoogle Scholar
  17. 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 ScholarGoogle Scholar
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle Scholar
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle Scholar
  23. 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 ScholarGoogle Scholar
  24. Knight, K. 1989. Unification: A multidisciplinary survey. ACM Comput. Surv. 21, 1, 93--124.]] Google ScholarGoogle Scholar
  25. Malishevsky, A. 1998. Implementing a runtime library for a parallel MATLAB compiler. M.S. thesis, Oregon State University.]]Google ScholarGoogle Scholar
  26. McCosh, C. 2003. Type-Based specialization in a telescoping compiler for MATLAB. Tech. Rep. TR03--412, Rice University.]]Google ScholarGoogle Scholar
  27. Milner, R. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17, 3 (Dec.), 348--375.]]Google ScholarGoogle Scholar
  28. Mitchell, J. C. 1996. Foundations for Programming Languages. The MIT Press, Cambridge, MA.]] Google ScholarGoogle Scholar
  29. Muchnick, S. S. 1997. Advanced Compiler Design and Implementation. Morgan Kaufmann, San Francisco, CA.]] Google ScholarGoogle Scholar
  30. 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 ScholarGoogle Scholar
  31. Robinson, J. A. 1965. A machine-oriented logic based on the resolution principle. J. Association Comput. Mach. 12, 1 (Jan.), 23--41.]] Google ScholarGoogle Scholar
  32. Tenenbaum, A. M. 1974. Type determination in very high-level languages. Ph.D. thesis, Rep. NSO-3, New York University.]] Google ScholarGoogle Scholar
  33. The MathWorks, Inc. 1997. MATLAB: The Language of Technical Computing. The MathWorks, Inc. Using MATLAB (Version 5).]]Google ScholarGoogle Scholar
  34. The MathWorks, Inc. 2002a. Accelerating MATLAB: The MATLAB JIT-Accelerator. At http://www.mathworks.com/company/newsletters/digest/sept02/accel_matlab.pdf.]]Google ScholarGoogle Scholar
  35. 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 ScholarGoogle Scholar
  36. Tremblay, J. P. and Manohar, R. 1975. Discrete Mathematical Structures with Applications to Computer Science. Computer Science Series. McGraw-Hill, New York.]] Google ScholarGoogle Scholar
  37. Walther, C. 1988. Many-Sorted unification. J. Assoc. Comput. Mach. 35, 1, 1--17.]] Google ScholarGoogle Scholar
  38. Weisstein, E. W. 2005. Hilbert matrix; From MathWorld---A Wolfram web resource. At http://mathworld.wolfram.com/HilbertMatrix.html.]]Google ScholarGoogle Scholar
  39. 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 ScholarGoogle Scholar
  40. Wolfram, S. 1999. The Mathematica Book, 4th ed. Wolfram Media, Champaign, IL.]] Google ScholarGoogle Scholar
  41. 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 ScholarGoogle Scholar

Index Terms

  1. An algebraic array shape inference system for MATLAB®

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM Transactions on Programming Languages and Systems
              ACM Transactions on Programming Languages and Systems  Volume 28, Issue 5
              September 2006
              171 pages
              ISSN:0164-0925
              EISSN:1558-4593
              DOI:10.1145/1152649
              Issue’s Table of Contents

              Copyright © 2006 ACM

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 1 September 2006
              Published in toplas Volume 28, Issue 5

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!