Questions tagged [code-generation]
91 questions
29
votes
7 answers
What kinds of uses of SymbolicC (introduced in Mathematica 8) do you foresee? Are there any neat examples already?
Mathematica 8 introduced SymbolicC, a set of Mathematica functions that capture C language constructions in the familiar Mathematica tree-like fashion. Additionally, there are functions to write SymbolicC trees as straight C code to a file. The…
Sjoerd C. de Vries
- 65,815
- 14
- 188
- 323
19
votes
3 answers
Generating assignments and transforming code inside held forms when generating code
I have been playing with slightly above trivial code manipulations in Mathematica. I thought Mathematica would be great for this kind of work because of rule replacement and expression manipulation, but I have been running in a lot of issues (I am…
Manuel Odendahl
- 423
- 2
- 7
13
votes
0 answers
Bug: Library functions from older versions of Mathematica may crash in Mathematica 11.1 and conversely
The following is a confirmed bug [CASE:3846875] that turned up in the prerelease 11.1.0 and is not solved in the official release.
This is a small example. Execute the following commands in Mathematica 11.0 or…
Fred Simons
- 10,181
- 18
- 49
9
votes
1 answer
How to prevent SymbolicC constructs from using the semicolon (;) as the separator?
When putting several SymbolicC expressions in a list, they will usually be joined together with semicolons in the final generated code:
<< SymbolicC`
{CCall["g", 2], CCall["h", 3]} // ToCCodeString
g(2);
h(3);
This is true when pieces of code are…
Szabolcs
- 234,956
- 30
- 623
- 1,263
7
votes
1 answer
How do I create a function pointer typedef using SymbolicC
I am just getting started with the SymbolicC package, and am trying to figure out how to handle function pointer typedefs, like, say:
typedef double (*rhs)(double, double);
The problem is that the CTypedef function expects its arguments to be…
Pillsy
- 18,498
- 2
- 46
- 92
5
votes
1 answer
Generate FORTRAN77 code from Mathematica
I need to transform a function from Mathematica to Fortran77. An internal program FortranForm gives some result, but it works incorrectly in Fortran77. The string must start a 7th column and finish at 72th, ArcTan and Log must be transformed to ATAN…
IgorPy
- 51
- 4
4
votes
0 answers
Why are Parenthesis not added to CExpression in Package SymbolicC?
The documentation of SymbolicC, more specifically of COperator, states that Parentheses are added as necessary together with the following example:
In[1]:= Needs["SymbolicC`"]
In[2]:= COperator[Times, {COperator[Plus, {a, b}], c}] //…
Sunday
- 413
- 5
- 7
3
votes
1 answer
Easy code help about matrix. How to change the elements in a given matrix?
For example I have a matrix
A[1,1]={1,2,3,4};
Now I want to change the second element of A[1,1] to 5,so my code is
A[1,1][[2]]=5;
but there will be some error messages.
what I want to get is
A[1,1]={1,5,3,4};
What needs to be noted in particular…
郑新然
- 47
- 4
3
votes
1 answer
SymbolicC`: Is there a CChar, i.e. a way to generate a single character constant?
I am aware of CConstant and CString, but neither can output the single-char literal
'a'
masterxilo
- 5,739
- 17
- 39
2
votes
3 answers
SymbolicC Simplified Displayed
How might I display a simplified SymbolicC below.
For example in the following example
Needs["SymbolicC`"]
CWhile[COperator[Less, {i, j}],
CAssign[i, CCall[ fun, {i}]]
] // ToCCodeString[#1, "Indent" -> 1] &
Is it possible to display it like…
William
- 7,595
- 2
- 22
- 70
1
vote
1 answer
SymbolicC namespace?
What is the equivalent for C++'s using namespace ...; in SymbolicC package of mathematica and are there any good resources like video tutorial or lecture or books covering this package?
user13892
- 9,375
- 1
- 13
- 41
0
votes
0 answers
Generate effective C/Java code (minimizing operations)
Is it possible to generate C/Java code with Mathematica so that it minimizes number of operations performed? For example, for matrix inverse or determinant? With good caching variables?
Suzan Cioc
- 2,023
- 1
- 16
- 21
0
votes
0 answers
How to create a file that runs without displaying the code (similar to an .exe)
I am writting a code that could be useful for some people. The program will be free but I would like to protect the code. As I am not good at explaining myself I will simply illustrate my question with an example:
Let's say that I make the following…
neuron
- 1