This would probably be a better solution to the problem in my previous mail, if it can be done. I've posted the same text as a question on Stack Overflow at https://stackoverflow.com/questions/52638892/using-assignment-with-autowrap-in-sympy.
I am writing some code that uses sympy to construct a complicated mathematical expression, then uses the autowrap function to compile it and evaluate it repeatedly. Unfortunately, my expressions are becoming exponentially large in some cases. To prevent this, I want to generate expressions that contain assignment statements. That is, I want to end up with something like (pseudocode) x1 = f(a,a); x2 = f(x1,x1); x3 = f(x2,x2); x4 = f(x3,x3); instead of f(f(f(a,a),f(a,a)),f(f(a,a),f(a,a))),f(f(a,a),f(a,a)),f(f(a,a),f(a,a)))) in which every subexpression has been substituted twice. There seems to be a mechanism for this, in the form of sympy.codegen.ast.CodeBlock <https://docs.sympy.org/latest/modules/codegen.html#sympy.codegen.ast.CodeBlock>. However, I can't seem to work out how to get this to work with autowrap, if indeed it can. If I attempt to do >>> f = autowrap(ast.CodeBlock(ast.Assignment(y,sym.sin(x))),backend='cython') then I get a long stack trace ending with wrapped_code_12.c:5:22: error: use of undeclared identifier 'y' autofunc_result = y = sin(x); ^1 error generated. error: command '/usr/bin/clang' failed with exit status 1 which suggests to me that using a CodeBlock directly inside autowrap isn't the right way to do it. (I get a similar error using the Fortran backend.) The question is, is there a right way to do it? Can I use CodeBlock in autowrap, or is there some other way that I can generate intermediate variables with autowrap rather than always having my sympy expressions fully expanded out? Best regards Nathaniel -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/265d7681-3377-4dbe-8997-7d12fd662b19%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
