Initial codegen implementation

0 views
Skip to first unread message

Toon Verstraelen

unread,
Jun 8, 2009, 10:26:09 AM6/8/09
to sympy-...@googlegroups.com
Hi,

This is my first attempt to use the sympy-patches list. The attached patch is a
proposal for the code generator for sympy, and includes working tests. The
current possibilities are intentionally very limited, but the code should be
extensible with future patches to handle the more complex cases of interest.

The friendly interface is the codegen function, and works like this:

xyz = symbols("xyz")
codegen([("fn",(x+y)*z)], "C", "codegen")

This writes two files:


codegen.h:

/******************************************************************************
* Code generated with sympy 0.6.5-git *
* *
* See http://www.sympy.org/ for more information. *
* *
* This file is part of 'project' *
******************************************************************************/

#ifndef PROJECT__CODEGEN__H
#define PROJECT__CODEGEN__H

double test(double x, double y, double z);

#endif

codegen.c:

/******************************************************************************
* Code generated with sympy 0.6.5-git *
* *
* See http://www.sympy.org/ for more information. *
* *
* This file is part of 'project' *
******************************************************************************/

#include "codegen.h"
#include <math.h>

double test(double x, double y, double z) {
return z*(x + y);
}

The codegen function is based a more complex api with more possibilities. More
info can be found as comments and the doc strings. Any comments are appreciated.
(coding style, typo's, code design, milestones, ...)

cheers,

Toon


--
ir. Toon Verstraelen
Center for Molecular Modeling
Ghent University
Proeftuinstraat 86
B9000 Gent
Belgium
Tel: +32 9 264 65 56
E-mail: Toon.Ver...@UGent.be
http://molmod.UGent.be/
http://molmod.UGent.be/code/

toon_verstraelen.vcf
0001-Initial-codegen-implementation.patch.gz
Reply all
Reply to author
Forward
0 new messages