ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Dec 2022 22:16:12 +0100SageMath Version 9.5: codegen function does not exist in Jupyter notebookshttps://ask.sagemath.org/question/65440/sagemath-version-95-codegen-function-does-not-exist-in-jupyter-notebooks/Hello,
I get the following error when I try the example given by benjaminfjones at ask.sagemath.org_question_7922_export-to-c-code. (Replace _ with / to get the link)
NameError: name 'codegen' is not defined.
I am using the jupyter notebooks version of SageMath. The version of SageMath is 9.5.
Here's what the command window shows:
SageMath version 9.5, Release Date: 2022-01-30
Using Python 3.10.6. Type "Help()" for help.
The OS is Linux Mint 21 Cinnamon Version 5.4.12. Linux Kernel Version 5.19.0-051900-generic.
StephenSt1255Wed, 21 Dec 2022 22:16:12 +0100https://ask.sagemath.org/question/65440/sympy codegen with indiceshttps://ask.sagemath.org/question/8678/sympy-codegen-with-indices/I am doing a symbolic calculation in sage and I need a C-code of the output. I found an example in sympy documentation that does this.
from sympy import symbols
from sympy.utilities.codegen import codegen
from sympy.abc import x, y, z
[(c_name, c_code), (h_name, c_header)] = \
codegen(("f", x+y*z), "C", "test", header=False, empty=False)
print c_code,
However, this does not work when the variables I am passing to f have indices for example,
from sympy import symbols
from sympy.utilities.codegen import codegen
from sympy.abc import x[0], x[1], x[2]
[(c_name, c_code), (h_name, c_header)] = \
codegen(("f", x[0]+x[1]*x[2]), "C", "test", header=False, empty=False)
print c_code,
This results in an error. Is there a way to generate a C-code with indices in them?ShashankSat, 28 Jan 2012 17:42:55 +0100https://ask.sagemath.org/question/8678/