Skip to main content

The Impact of Dynamic Data Reshaping on Adjoint Code Generation for Weakly-Typed Languages Such as Matlab

  • Conference paper
  • First Online:
Recent Advances in Algorithmic Differentiation

Abstract

Productivity-oriented programming languages typically emphasize convenience over syntactic rigor. A well-known example is Matlab, which employs a weak type system to allow the user to assign arbitrary types and shapes to a variable, and it provides various shortcuts in programming that result in implicit data reshapings. Examples are scalar expansion, where a scalar is implicitly expanded to a matrix of the appropriate size filled with copies of the scalar value, the use of row vectors in place of column vectors and vice versa, and the automatic expansion of arrays when indices outside of the previously allocated range are referenced. These features need to be addressed at runtime when generating adjoint code, as Matlab does not provide required information about types, shapes and conversions at compile time. This fact, and the greater scope of reshaping possible, is a main distinguishing feature of Matlab compared to traditional programming languages, some of which, e.g. Fortran 90, also support vector expressions. In this paper, in the context of the AdiMAT source transformation tool for Matlab, we develop techniques generally applicable for adjoint code generation in the face of dynamic data reshapings occurring both on the left- and right-hand side of assignments. Experiments show that in this fashion correct adjoint code can be generated also for very dynamic language scenarios at moderate additional cost.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 84.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 109.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Bischof, C.H., Bücker, H.M., Hovland, P.D., Naumann, U., Utke, J. (eds.): Advances in Automatic Differentiation, Lecture Notes in Computational Science and Engineering, vol. 64. Springer, Berlin (2008). DOI 10.1007/978-3-540-68942-3

  2. Bischof, C.H., Bücker, H.M., Lang, B., Rasch, A., Vehreschild, A.: Combining source transformation and operator overloading techniques to compute derivatives for MATLAB programs. In: Proceedings of the Second IEEE International Workshop on Source Code Analysis and Manipulation (SCAM 2002), pp. 65–72. IEEE Computer Society, Los Alamitos, CA, USA (2002). DOI 10.1109/SCAM.2002.1134106

  3. Bücker, H.M., Petera, M., Vehreschild, A.: Code optimization techniques in source transformations for interpreted languages. In: Bischof et al. [1], pp. 223–233. DOI 10.1007/978-3-540-68942-3_20

    Google Scholar 

  4. Giles, M.B.: Collected matrix derivative results for forward and reverse mode algorithmic differentiation. In: Bischof et al. [1], pp. 35–44. DOI 10. 1007/978-3-540-68942-3{ _}4

    Google Scholar 

  5. Kharche, R.V., Forth, S.A.: Source transformation for MATLAB automatic differentiation. In: V.N. Alexandrov, G.D. van Albada, P.M.A. Sloot, J. Dongarra (eds.) Computational Science – ICCS 2006, Lecture Notes in Computer Science, vol. 3994, pp. 558–565. Springer, Heidelberg (2006). DOI 10.1007/11758549{ _}77

    Google Scholar 

  6. MathWorks: Code vectorization guide (2009). URL http://www.mathworks.com/support/tech-notes/1100/1109.html

  7. Pascual, V., Hascoët, L.: Extension of TAPENADE toward Fortran 95. In: H.M. Bücker, G. Corliss, P. Hovland, U. Naumann, B. Norris (eds.) Automatic Differentiation: Applications, Theory, and Implementations, Lecture Notes in Computational Science and Engineering, vol. 50, pp. 171–179. Springer, New York, NY (2005). DOI 10.1007/3-540-28438-9{ _} 15

    Google Scholar 

  8. Vehreschild, A.: Automatisches Differenzieren für MATLAB. Dissertation, Department of Computer Science, RWTH Aachen University (2009). URL http://darwin.bth.rwth-aachen.de/opus3/volltexte/2009/2680/

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Johannes Willkomm .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Willkomm, J., Bischof, C.H., Bücker, H.M. (2012). The Impact of Dynamic Data Reshaping on Adjoint Code Generation for Weakly-Typed Languages Such as Matlab. In: Forth, S., Hovland, P., Phipps, E., Utke, J., Walther, A. (eds) Recent Advances in Algorithmic Differentiation. Lecture Notes in Computational Science and Engineering, vol 87. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-30023-3_12

Download citation

Publish with us

Policies and ethics