Questions tagged [compile]
Questions about the generation and use of compiled functions using Compile.
717 questions
25
votes
1
answer
690
views
Compile vs FunctionCompile
I wanted to look at the pros & cons of Compile & FunctionCompile. This code below is from Neat Examples in FunctionCompile documentation.
...
3
votes
0
answers
47
views
How can I know what prevents efficient lower level code when using FunctionCompile?
When using the old Compile, I can use CompilePrint and ensure the resulting CompiledFunction doesn't use MainEvaluate. If MainEvaluate isn't used, the CompiledFunction is efficient. How do we know if ...
1
vote
1
answer
223
views
Performance of polynomial functions in Mathematica vs Python [closed]
I am trying to compare the performance of Mathematica vs Python for vectorized operations involving polynomials. The data is floatMatrix which has dimensions (...
0
votes
1
answer
158
views
0
votes
0
answers
41
views
CompiledFunction fails for Variance with a rank 3 input
Why does compiling Variance for a rank 3 input fail but Mean works?
...
3
votes
1
answer
245
views
Improve performance of Linear Optimization
EDIT
I am reframing the question here by pulling out the relevant part about linear optimization, you can find the original question and the entire code down below.
I am trying to increase the ...
0
votes
0
answers
63
views
Using compile with indexed variables
I have the following piece of code which I made faster by using compile. I make the following definitions
...
4
votes
1
answer
109
views
Using Indexed variables in Compile?
This follows a: useful post about Compile from about 10 years ago
In that post there is a comment:
You can not really use indexed variables in Compile, although it may appear that you can.
For ...
1
vote
0
answers
66
views
Numerical Error using compile
I'm trying to compile a function and I'm running into the following error
CompiledFunction::cfne : Numerical error encountered; proceeding with uncompiled evaluation.
I think I have succeeded in ...
2
votes
1
answer
54
views
Defining a function using just compilable functions
I need to define a function that takes an input and if and only if its a positive real, outputs the input. If not, the output should be 0. The input could be complex valued or indeterminate.
Heres ...
0
votes
1
answer
123
views
Performance improvements using Table and Compile
I'm converting a code from MatLab to Mathematica. It takes MatLab less than a second to compute it while its more than ten minutes in Mathematica. I was hoping to improve the performance.
Here's a ...
1
vote
0
answers
49
views
Make a recursive function for computing a matrix faster
I have a function below called inverseKostkaHelper (see belos) which
I want to make faster.
It takes two integer partitions as arguments, (both with the same total ...
2
votes
0
answers
89
views
Large Structured Programming with Compile
Is it possible or wise to build a large program structure with only Compile?
With FunctionCompile it is possible to create ...
3
votes
1
answer
174
views
Why is the code with multiple Do slower than the one without them, and why is For faster than Do?
For some table tab having N rows and n columns, I need to go over all its rows $j$ and ...
0
votes
0
answers
140
views
Why is the following code not compilable?
The code below should replace particular elements of some table acccolumns if some condition is satisfied:
...
0
votes
1
answer
62
views
Why does the following code not change the table?
Consider the following code:
...
2
votes
0
answers
81
views
Memory leak with pure function and in the listable option of compiled function?
I'm using
13.0.0 for Microsoft Windows (64-bit) (December 3, 2021)
When I repeatedly run the command
...
1
vote
1
answer
150
views
How to improve performance of making an Exponentially Weighted Correlation Matrix?
I would like to make an Exponentially Weighted version of Correlation (similar to https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.ewmcov.html)....
3
votes
1
answer
232
views
Memoize a compiled function
Let f be some function, I know that i can memoize a function so that it does not compute again previously calculated values, I can also compile the function to speed up the calculations. But how can I ...
0
votes
0
answers
70
views
May the runtime of a code compiled in C depend on the C compiler used?
I have a Windows machine with installed Mathematica. I compile the code in C. The compiler I use is CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler from ...
1
vote
0
answers
115
views
Random Seed and Parallelization in Compiled Functions
I am having trouble reproducing a random number from a compiled function with parallelization even with the random seed being set.
Specifically, running the following script should give the same value ...
0
votes
1
answer
80
views
Speed up compoundReturn across an array
I am trying to calculate a moving-window of compounded returns on a large 2D-array. (ie some kind of MovingMap on geometric returns)
The Rows are time-steps and the Columns are different financial ...
1
vote
1
answer
71
views
Evaluate the function once in the following compiled code, or optimize it?
Consider the following Switch function for two variables:
...
2
votes
3
answers
200
views
A simple question about syntax: how to shorten [email protected]@
Consider the following function:
...
0
votes
0
answers
137
views
How to use Switch for more than one switchable arguments (in a compilable way)?
Consider some example of usage of the function Switch:
...
0
votes
0
answers
66
views
Why is the slowdown of the compiled code evaluation so significant?
Edit
I have reduced the powers of trigonometric functions entering formula1, formula2 to make the problem clearer. It seems that ...
3
votes
1
answer
148
views
Compile`GetElement for tensors of rank 1 and 2
Consider some data momvals, mzvals and functions phVal, ...
1
vote
1
answer
90
views
Why is this function not compilable?
Consider some functions
...
2
votes
1
answer
99
views
Why is the variable inside the compiled code a tensor but not a scalar?
Consider the data data0, data1:
...
1
vote
0
answers
46
views
Why returning the counter takes much time in the following example?
Consider the following data and analytic expressions:
...
2
votes
1
answer
82
views
Why the following formula slows down the compiled code?
I made a routine code CodeComp2 that performs algebraic evaluations using some data TablexgridWithEx, ...
4
votes
2
answers
291
views
How to speedup the integration of a tabulated function?
The problem
Consider some pre-generated list with coordinates x1,x2,x3,x4 and values of some function ...
2
votes
1
answer
136
views
Speed up Interpolation
I have to calculate a lot of values using interpolation function. I think it could be faster, but I wasn't able to speed it up any way using Compile/Parallel computations. Am I missing something?
<...
1
vote
1
answer
71
views
Compiled module error
I have a simple module that I want to compile to potentially speed up.
...
3
votes
2
answers
512
views
How to produce the following table faster?
Question
Consider a toy function func[x1,x2,x3,x4] and a toy grid gridTot of the coordinates ...
3
votes
1
answer
151
views
Compiling a function that uses MapThread
I'm looking for tips on quickly applying the following update to $B$ pairs of $(w_i,x_i)$
$$\text{step}(w_i,x_i)=w_i-a x_i \langle w_i, x_i \rangle$$
Below is a readable but very slow version ...
2
votes
0
answers
73
views
Argument value loss using Listable C-Compiled Function
In my recent studies, I have come across a very strange anomaly with C compiled functions. When I call a function that has the 'Listable' attribute while global variables are accessed through ...
1
vote
1
answer
129
views
How to speedup calling the interpolation function? [duplicate]
Consider the following data:
...
3
votes
1
answer
114
views
Can I efficiently use a compiled function as an input to another compiled function?
I have a compiled function(such as $f\left(z,c\right)=z^2+c$) which will get replaced by different equations as the code runs. I'm using this compiled function(#1) inside another compiled function(#2)....
2
votes
1
answer
119
views
Compile a code evaluating a condition only if another condition is positive
Consider the following three tables:
...
2
votes
1
answer
60
views
How to assign a new value to the table inside Compile?
Consider some tables and function func:
phivals=RandomReal[{-Pi,Pi},10^5];
func[phi_]=phi^5*Exp[-phi];
acc=Table[0,10^5];
I ...
3
votes
1
answer
170
views
Why the ugly code is faster than the pretty code?
The task
Consider two tables, Tab1,Tab2, that include some real-number data. I need to evaluate the product of some boolean conditions on the value of some function ...
0
votes
0
answers
74
views
How to generate points belonging to some region very fast?
Consider two variables Ex,th. th ranges within
thmin=10^-5;
thmax=Pi/2;
while ...
4
votes
3
answers
195
views
Compile code involving two matrix multiplications
Consider the following simple matrix operation ($a_j, b_j, z, w$ are matrices)
$$ w=\sum_j a_j\cdot z\cdot b_j$$
For performance reasons I am compiling the code
...
3
votes
1
answer
84
views
How to keep the code compact in the following case?
Consider the following code:
...
2
votes
3
answers
201
views
Compile integer functions
I need to speed up a function that uses Binomial and QuotientRemainder. I used Compile, but ...
2
votes
0
answers
77
views
SymbolicGPU documentation
I found an interesting files there
$CUDALinkPath -> ../GPUTools
here
...
2
votes
0
answers
55
views
Can NumericArray be Compiled?
I've have a big block of code written under Compile. Some other part of the code which receives data from shared Q useing ...
1
vote
0
answers
81
views
How to use FunctionCompile and Compile as external definition?
Let's consider the following functions (in $Version: 12.3.0 for Linux x86 (64-bit) (May 10, 2021))
...
11
votes
1
answer
1k
views
Why CompilationTarget->"C" doesn't improve computation time
I wrote a simple code to test the computation time under CompilationTarget->"C". I get barely any improvement on the computation time from ...