Skip to main content

Questions tagged [compile]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
89 views

Way to run the script faster

I have a mathematica code, which is running fine, but it takes long time to evaluate.I have already modified the code with compilation and vectorization as you can see from my code. May be its a ...
user100023's user avatar
1 vote
1 answer
427 views

Use of Compile[] to optimize the code to run faster

I am working on a code that takes long time to evaluate, So I come to know that use of Compile[] function can speed up significantly. Here is my original code. ...
P Pyne's user avatar
  • 473
0 votes
0 answers
50 views

Qualitative question: can the code matching the given patterns be made significantly faster if being written in pure C?

I made some code in Mathematica that I compiled in C. It involves operations such as looping inside While, custom random sampling from particular distributions, and ...
John Taylor's user avatar
  • 5,877
1 vote
1 answer
190 views

Parallelization with compile gives an error

I have this uncompiled code with MMA14, win10,64 ...
MMA13's user avatar
  • 4,644
0 votes
0 answers
42 views

Compilation error for multidimensional lists [duplicate]

Dear Mathematica users, I have a code as: ...
Kazim Ahmet Hasim's user avatar
2 votes
0 answers
87 views

How to push the performance of this compiled function

I have the function optvals solving for two variables. For the given example of variables, I need the program to run atmost in a millisecond. The main part of the ...
Dotman's user avatar
  • 486
1 vote
1 answer
87 views

How to speed up generating and filtering large lists of numbers?

I have the following code where I brute force search for two variables. list gives a list of 3 dimensional vectors, say {x,y,z}. ...
Dotman's user avatar
  • 486
1 vote
1 answer
82 views

Why using compiled code inside compiled code may slow things down?

I made some code that I compiled. The snippet looks as follows: ...
John Taylor's user avatar
  • 5,877
2 votes
1 answer
60 views

Why is random sampling with ordinary and compiled code so different?

Consider the following code: ...
John Taylor's user avatar
  • 5,877
0 votes
0 answers
24 views

Compilation of the function that should return vector along with matrix [duplicate]

I am looking for the way how to compile the function that is supposed to return vectors along with matrices. The simplified example looks next: ...
Oleksii Semenov's user avatar
2 votes
1 answer
102 views

Fast sampling from Fermi-Dirac distribution under specific conditions

This question is a continuation of the following one. Let us assume a Fermi-Dirac (FD) distribution (times $p^{2}$): ...
John Taylor's user avatar
  • 5,877
1 vote
0 answers
41 views

How to quickly check if compiled code calls MainEvaluate?

Consider the following test compiled code: ...
John Taylor's user avatar
  • 5,877
1 vote
1 answer
92 views

How to compile the following code (sampling from a distribution)?

Consider the following code: ...
John Taylor's user avatar
  • 5,877
3 votes
2 answers
91 views

Problem compiling derivative of expression

I need to compile functions for an expression and its derivative and then pass these on to a precompiled worker loop for further processing. An If statment detects when the expression parameter expr ...
Mikl's user avatar
  • 101
3 votes
0 answers
35 views

Mathematica call CompiledFunction from Python with Listable and Parrallelization attributes

I have a CompiledFunction e.g. this: ...
Okarin's user avatar
  • 31
3 votes
0 answers
66 views

GSL multiroot finding mode Hybrid function load with Mathematica : Crash

Hi everyone I work on a Mac M1 Sonoma 14.3 with Mathematica 12.3.1 and 14.0 I have an issue when using a C++ multiroot finding from GSL library. I used this example : https://www.gnu.org/software/gsl/...
Alex's user avatar
  • 51
0 votes
0 answers
30 views

Compiling an ItoProcess

I am a new mathematica user. I am trying to use the Compile command to speed up my RandomFunction output. The code looks like this: ...
rahman62's user avatar
2 votes
2 answers
167 views

Compile does not boost the speed

I have these functions that are used to defineMyFun below ...
MMA13's user avatar
  • 4,644
4 votes
1 answer
150 views

How can we improve performance when passing data to a function?

I have a defined function $F(x,y,z)$ and data of $(x,y)$ and would like to evaluate the sum of F over data and at different z values. Here is a minimal example: ...
MMA13's user avatar
  • 4,644
0 votes
0 answers
48 views

Tensors of arbitrary rank inside compiler

I want to create a compiled function that executes operations with lists of tensors. It has two arguments, two lists of tensors, and takes the tensor products between tensors of both lists. Is it ...
Felipe's user avatar
  • 609
0 votes
0 answers
37 views

Compile constraints for NMinimize

I use complicated constraints for optimisation, something like Table[ EuclideanDistance[pts[[i]], pts[[j]]] >= 1 , {i, numPts - 1}, {j, i + 1, numPts}] ...
lesobrod's user avatar
  • 1,819
4 votes
2 answers
173 views

How to compile inverse error function?

I have the following code: ...
John Taylor's user avatar
  • 5,877
0 votes
0 answers
20 views

Issue with ReplaceAll resulting in Null function return

I am trying to modify some code of mine to change where the final evaluation of a function is performed, as a way to not generate massive tables of data. The code is working fine, until I have started ...
D. Brown's user avatar
  • 304
2 votes
1 answer
109 views

How to Compile functions to C in parallel?

I need to Compile functions for use on parallel kernels. There are many such functions, so compiling in parallel is desirable. When compiling functions with ...
Kuba hasn't forgotten Monica's user avatar
3 votes
0 answers
46 views

Strategies and practical advice for using saved compiled functions in a package

I want to use a compiled function in a package without having to rebuild it each time. This slows down unit testing and loading of the package. I have used the example in the link as my starting point:...
IntroductionToProbability's user avatar
14 votes
1 answer
777 views

When to use WVM instead of C for CompilationTarget?

In which cases is it advantageous to compile using the Wolfram Virtual Machine ("WVM") option rather than the C Code (...
anonymous's user avatar
  • 453
3 votes
0 answers
112 views

Optimizing memoization in compiled Mathematica code

Consider the following two codes - compiledcode and compiledcode1: ...
John Taylor's user avatar
  • 5,877
3 votes
0 answers
66 views

Making speed of MemberQ comparable with explicit If?

Consider the following two lists: listtest = {11, 13, 22, 221, 1, 3} // Sort // N; pdglisttest = RandomInteger[{-222, 222}, 10^6] // N; For the given element of <...
John Taylor's user avatar
  • 5,877
0 votes
0 answers
62 views

Problem using Compile together with Eigensystem

I have been trying to understand what is wrong with this piece of Mathematica code: ...
dbrane's user avatar
  • 101
0 votes
0 answers
129 views

How to quickly generate the values satisfying the given condition?

Consider some domains in variables th, z and some condition cond defining the domain of a ...
John Taylor's user avatar
  • 5,877
2 votes
1 answer
142 views

What can be improved in the following custom bilinear interpolation?

Consider some test data: a grid of x, y, and values of some function on this grid: ...
John Taylor's user avatar
  • 5,877
0 votes
0 answers
70 views

Compilable analog of Nearest?

Is there any analog of Nearest that is compilable? ...
John Taylor's user avatar
  • 5,877
4 votes
1 answer
225 views

How to quickly sample points from the given PDF data?

Consider some data (distr.dat). It is a tabulated PDF: x, y, z, PDF[x,y,z], where x is some parameter (and the integral of ...
John Taylor's user avatar
  • 5,877
0 votes
1 answer
102 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
9 votes
3 answers
295 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
  • 25.6k
5 votes
5 answers
514 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.6k
2 votes
0 answers
98 views

How to speed up compilation of some functions?

...
Yilin Cheng's user avatar
1 vote
0 answers
63 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
83 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 ...
მამუკა ჯიბლაძე's user avatar
24 votes
1 answer
624 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
  • 959
3 votes
0 answers
44 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
  • 959
1 vote
1 answer
187 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
153 views

How to compile this function to speed up operation?

...
miss's user avatar
  • 874
0 votes
0 answers
40 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
223 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
  • 486
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 ...
QFTheorist's user avatar
4 votes
1 answer
106 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
  • 4,625
0 votes
0 answers
79 views

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

Consider the following table: ...
John Taylor's user avatar
  • 5,877
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
  • 486
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 ...
Dotman's user avatar
  • 486

1
2 3 4 5
15