Array arguments

I started last week by setting up a page on the wiki to write down and publish my thoughts about how to implement code generation with array expressions. The intention was to flesh out some details and I also hoped to get some feedback.  It turned out to be a really good investment as I got both suggestions about implementation and questions that helped me clarify my thoughts.  (Thanks to Aaron, Andy and Mark!)

I spent a few days reading (GiNaC, distutils, numpy, fwrap, f2py, swig) and thinking before I set down to code on Thursday.  By then I had reached the conclusion that I would need to implement Indexed objects.  These will represent arrays in the Sympy expressions before code generation.  Indexed expressions, e.g. a matrix-vector product denoted as A(i,j)x(j), contain information that is not explicit in the corresponding  abstract notation Ax. In order to generate the code unambiguously, all relevant information must be explicit.

Having a specialized Sympy object that correspond to arrays in the code means that the user gets access to all the available expression manipulation functionality before the code is generated.  The downside is that you need to work with indexed expressions, instead of abstract symbols.  However, to translate non-indexed expressions to the corresponding indexed expression is just a call to Expr.subs, so it can be done just in time before code generation.

Over the weekend I managed to implement array argument handling in the fortran code printer, and FCodeGen, but I have not yet tested how the code compiles.  This week hope to get the fortran to compile and also to implement everything in the C code generator.  Maybe I can also refactor a little and move language agnostic code to the CodeGen super class.

[oy@ubuntulaptop sympy (fortran_codegen3)]$ git shortlog --since=1.weeks --author=Øyvind
Øyvind Jensen (21):
 Fix issue 1920: SymTuple doesn't rebuild itself
 Moved SymTuple to sympy/core/ +  imported in core/
 First implementation of Indexed and Idx Added example with matrix-vector product to module docstring
 move function wrap_fortran() to FCodePrinter._wrap_fortran()
 Implemented optional free-form source format for Fortran code printer
 Added tests for free-form fortran code + fix bug in comment line wrapping
 Created codegenerator FCodeGen for generating compilable fortran code
 Fixed double space after '=' in generated free form code
 fix fortran line wrapping for human=False
 FCodeGen should should use printer object, not fcode
 Added loop functionality to FCodeGen
 FCodePrinter:  implemented code indentation for fortran free-form
 Fixes failing test due to AttributeError in matplotlib version 0.91.2 (Is
 Implemented Fortran declarations of array input arguments
 Added property `dimensions' to Indexed
 Implemented OutputArgument and InOutArgument in FCodeGen
 Move loop generation into FCodePrinter + add declaration of local variabl
 Fix leading blank in fortran codegen
 Added test for FCodeGen with array arguments (matrix-vector product)
 Added debug helper function for string comparison
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Array arguments

  1. Pingback: A Weeklog « Aaron Meurer's SymPy Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s