Questions tagged [compile]

Questions about the generation and use of compiled functions using Compile.

Filter by
Sorted by
Tagged with
1 vote
1 answer
78 views

How to make the function compile into C faster, and how to determine which portion of the code occupies more memory?

If changing the value of 'n' from 2 to 3 in the above code increases the compilation time from one minute to ten minutes, is there a way to speed it up? Also, the code consumes too much memory during ...
Yilin Cheng's user avatar
0 votes
0 answers
52 views

FunctionCompile get IR source code

A new fancy option to compile WL's function using LLVM is amazing. Is there any way to get the IR's (intermediate representation) representation of it? According to specification there are two forms ...
Kirill Vasin's user avatar
  • 1,177
9 votes
3 answers
281 views

Is there a faster way to compose a large number of random Gaussians?

I'm looking for a more efficient way to generate an image with a large number of randomly coloured Gaussians. Here's the code I'm using: ...
flinty's user avatar
  • 23.7k
5 votes
5 answers
501 views

How to use Compile to optimize the performance of a function calculating the distance between two points?

I want to create a function that finds the real space distance between two three-dimensional points. Each point is a list of three real numbers. I can create functions ...
Andrew's user avatar
  • 10.4k
2 votes
0 answers
90 views

How to speed up compilation of some functions?

...
Yilin Cheng's user avatar
1 vote
0 answers
62 views

Weird slowdown on data returned by compiled function (bug?)

Mathematica 13.1 - I was cleaning up some computations and I got a x3 time increase when I reduced things to loop over. Full context is a bit convoluted, I stripped the most I could but the problem ...
Domenico Modica's user avatar
0 votes
1 answer
69 views

Can I use a C compiler from behind WSL?

I've got 13.3 on Windows 11 (22H2) and a gnu compiler suite under WSL2 (Arch). Seems it is possible to compile in Windows with VS Code (which I also have). Do I still need to install another C ...
21 votes
1 answer
553 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. ...
Ted Ersek's user avatar
  • 884
2 votes
0 answers
40 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 ...
Ted Ersek's user avatar
  • 884
1 vote
1 answer
153 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 (...
mmen's user avatar
  • 163
0 votes
1 answer
149 views

How to compile this function to speed up operation?

...
miss's user avatar
  • 449
0 votes
0 answers
39 views

CompiledFunction fails for Variance with a rank 3 input

Why does compiling Variance for a rank 3 input fail but Mean works? ...
IntroductionToProbability's user avatar
3 votes
1 answer
192 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 ...
Dotman's user avatar
  • 414
0 votes
0 answers
57 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 ...
QFTheorist's user avatar
4 votes
1 answer
98 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 ...
Craig Carter's user avatar
  • 3,968
0 votes
0 answers
51 views

How to compile a code with a table having varying number of columns?

Consider the following table: ...
John Taylor's user avatar
  • 4,642
1 vote
0 answers
65 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 ...
Dotman's user avatar
  • 414
2 votes
1 answer
50 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 ...
Dotman's user avatar
  • 414
0 votes
1 answer
110 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 ...
Dotman's user avatar
  • 414
1 vote
0 answers
46 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 ...
Per Alexandersson's user avatar
2 votes
0 answers
72 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 ...
Michael Haring's user avatar
3 votes
1 answer
149 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 ...
John Taylor's user avatar
  • 4,642
0 votes
0 answers
29 views

Omit multiple calculations of the same thing inside a compiled code?

Toy problem This question arises from the more complicated question involving it as a part. Assume a 2D table tab. We need to iterate over its rows ...
John Taylor's user avatar
  • 4,642
0 votes
0 answers
101 views

Why is the following code not compilable?

The code below should replace particular elements of some table acccolumns if some condition is satisfied: ...
John Taylor's user avatar
  • 4,642
0 votes
1 answer
60 views

Why does the following code not change the table?

Consider the following code: ...
John Taylor's user avatar
  • 4,642
0 votes
1 answer
273 views

Why are the results of these codes different?

I apologize for the very long question with a relatively complicated code. I am dealing with a real problem, and the question below appeared from my attempt to simplify this problem to ask about it ...
John Taylor's user avatar
  • 4,642
2 votes
0 answers
73 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 ...
dzsoga's user avatar
  • 341
1 vote
1 answer
87 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)....
IntroductionToProbability's user avatar
3 votes
1 answer
213 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 ...
DarkBulle's user avatar
  • 964
0 votes
0 answers
68 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 ...
John Taylor's user avatar
  • 4,642
1 vote
0 answers
105 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 ...
Kohei's user avatar
  • 11
0 votes
1 answer
78 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 ...
IntroductionToProbability's user avatar
1 vote
1 answer
67 views

Evaluate the function once in the following compiled code, or optimize it?

Consider the following Switch function for two variables: ...
John Taylor's user avatar
  • 4,642
2 votes
3 answers
196 views

A simple question about syntax: how to shorten [email protected]@

Consider the following function: ...
John Taylor's user avatar
  • 4,642
0 votes
0 answers
101 views

How to use Switch for more than one switchable arguments (in a compilable way)?

Consider some example of usage of the function Switch: ...
John Taylor's user avatar
  • 4,642
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 ...
John Taylor's user avatar
  • 4,642
3 votes
1 answer
100 views

Compile`GetElement for tensors of rank 1 and 2

Consider some data momvals, mzvals and functions phVal, ...
John Taylor's user avatar
  • 4,642
1 vote
1 answer
84 views

Why is this function not compilable?

Consider some functions ...
John Taylor's user avatar
  • 4,642
2 votes
1 answer
95 views

Why is the variable inside the compiled code a tensor but not a scalar?

Consider the data data0, data1: ...
John Taylor's user avatar
  • 4,642
1 vote
0 answers
46 views

Why returning the counter takes much time in the following example?

Consider the following data and analytic expressions: ...
John Taylor's user avatar
  • 4,642
2 votes
1 answer
72 views

Why the following formula slows down the compiled code?

I made a routine code CodeComp2 that performs algebraic evaluations using some data TablexgridWithEx, ...
John Taylor's user avatar
  • 4,642
4 votes
2 answers
283 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 ...
John Taylor's user avatar
  • 4,642
2 votes
1 answer
86 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? <...
Vsevolod A.'s user avatar
1 vote
1 answer
58 views

Compiled module error

I have a simple module that I want to compile to potentially speed up. ...
flyingmind's user avatar
3 votes
2 answers
460 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 ...
John Taylor's user avatar
  • 4,642
3 votes
1 answer
128 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 ...
Yaroslav Bulatov's user avatar
2 votes
0 answers
69 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 ...
Michael Haring's user avatar
1 vote
1 answer
74 views

How to speedup calling the interpolation function? [duplicate]

Consider the following data: ...
John Taylor's user avatar
  • 4,642
3 votes
1 answer
101 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)....
Laff70's user avatar
  • 171
2 votes
1 answer
118 views

Compile a code evaluating a condition only if another condition is positive

Consider the following three tables: ...
John Taylor's user avatar
  • 4,642

1
2 3 4 5
14