skip to main content
article

Efficiently implementing the copy semantics of MATLAB's arrays in JavaScript

Published:01 November 2016Publication History
Skip Abstract Section

Abstract

Compiling MATLAB---a dynamic, array-based language---to JavaScript is an attractive proposal: the output code can be deployed on a platform used by billions and can leverage the countless hours that have gone into making JavaScript JIT engines fast. But before that can happen, the original MATLAB code must be properly translated, making sure to bridge the semantic gaps of the two languages.

An important area where MATLAB and JavaScript differ is in their handling of arrays: for example, in MATLAB, arrays are one-indexed and writing at an index beyond the end of an array extends it; in JavaScript, typed arrays are zero-indexed and writing out of bounds is a no-op. A MATLAB-to-JavaScript compiler must address these mismatches. Another salient and pervasive difference between the two languages is the assignment of arrays to variables: in MATLAB, this operation has value semantics, while in JavaScript is has reference semantics.

In this paper, we present MatJuice --- a source-to-source, ahead-of-time compiler back-end for MATLAB --- and how it deals efficiently with this last issue. We present an intra-procedural data-flow analysis to track where each array variable may point to and which variables are possibly aliased. We also present the associated copy insertion transformation that uses the points-to information to insert explicit copies when necessary. The resulting JavaScript program respects the MATLAB value semantics and we show that it performs fewer run-time copies than some alternative approaches.

References

  1. A. Casey et al. McLab: an extensible compiler toolkit for MATLAB and related languages. In Proceedings of the Third C* Conference on Computer Science and Software Engineering, C3S2E ’10, pages 114–117, New York, NY, USA, 2010. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. J. Doherty. McSaf: An Extensible Static Analysis Framework For The MATLAB Language. Master’s thesis, August 2011.Google ScholarGoogle Scholar
  3. A. W. Dubrau and L. J. Hendren. Taming MATLAB. In Proceedings of the ACM international conference on Object oriented programming systems languages and applications, OOPSLA ’12, pages 503–522, New York, NY, USA, 2012. ACM. ISBN 978-1-4503-1561-6. doi: 10. 1145/2384616.2384653. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Faiz Khan et al. Using JavaScript and WebCL for Numerical Computations: A Comparative Study of Native and Web Technologies.Google ScholarGoogle Scholar
  5. GNU. Octave: Miscellaneous Techniques. https://www. gnu.org/software/octave/doc/interpreter/ Miscellaneous-Techniques.html.Google ScholarGoogle Scholar
  6. T. K. Group. Typed Array Specification v1.0. https: //www.khronos.org/registry/typedarray/ specs/1.0.Google ScholarGoogle Scholar
  7. V. Kumar. Mix10: Compiling matlab to x10 for high performance. Master’s thesis, April 2014.Google ScholarGoogle Scholar
  8. N. Lameed and L. Hendren. Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. In Proceedings of the 20th International Conference on Compiler Construction. Springer Berlin / Heidelberg, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. N. Lameed and L. Hendren. Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. In ETAPS 2011. Springer Berlin / Heidelberg, Mar 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Lecoq. Matlabtips: Copy on Write. http://www. matlabtips.com/copy-on-write/.Google ScholarGoogle Scholar
  11. X. Li. Mc2for: A tool for automatically translating matlab to fortran 95. pages 234–243. IEEE, 2014.Google ScholarGoogle Scholar
  12. R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria,.Google ScholarGoogle Scholar
  13. R Core Team. R Internals: Rest of header. https://cran.r-project.org/doc/manuals/rpatched/R-ints.html#Rest-of-header,.Google ScholarGoogle Scholar
  14. L. Shure. MATLAB: Memory Management for Functions and Variables. http://blogs.mathworks.com/ loren/2006/05/10/memory-management-forfunctions-and-variables/.Google ScholarGoogle Scholar

Index Terms

  1. Efficiently implementing the copy semantics of MATLAB's arrays in JavaScript

    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

    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!