0

I am creating a series of parametric sympy functions dependent on x,y variables. Some of the functions turn out to be only dependent on some of the variables. therefore, when I call 'codegen', the interface of the created functions varies (sometimes it includes all variables, sometimes not). However, I want to be able to call the functions in a uniform manner in C.

To make a long story short, here's the example:

x,y = sympy.symbols("x,y")
S1 = x + y
S2 = x
d = {'S1':S1,'S2':S2}
for k in d.keys():
    [(c_name, c_code), (h_name, c_header)] = codegen((k, d[k]),  ...\
    "C",func_name,header=False, empty=False)
print(c_code)

which outputs:

#include "S2.h"
#include <math.h>
double S2(double x) {
   double S2_result;
   S2_result = x;
   return S2_result;
}

#include "S1.h"
#include <math.h>
double S1(double x, double y) {
   double S1_result;
   S1_result = x + y;
   return S1_result;
}

My Question is: How do I make codegen create both function with an equal signature?

zuuz
  • 859
  • 1
  • 12
  • 23

1 Answers1

1

I think you are looking for the argument_sequence argument to codegen(). It allows you to specify a fixed order, and it will also accept redundant arguments.

It is documented here.

Ø. Jensen
  • 943
  • 6
  • 10
  • cool, thanks - the link looks promising! It's been a while, but I'll give it a try next time :-) – zuuz Sep 01 '15 at 08:13