Questions tagged [compile]

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

Filter by
Sorted by
Tagged with
3 votes
0 answers
47 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/...
0 votes
0 answers
28 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: ...
2 votes
2 answers
138 views

Compile does not boost the speed

I have these functions that are used to defineMyFun below ...
4 votes
1 answer
141 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: ...
8 votes
2 answers
202 views

Determine return type of CompiledFunction expression

Is there a way to extract the types of the arguments and the return type from a CompiledFunction expression? I am writing a package for code generation (basically a wrapper around CCodeGenerate) where ...
0 votes
0 answers
44 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 ...
0 votes
0 answers
35 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}] ...
4 votes
2 answers
165 views

How to compile inverse error function?

I have the following code: ...
0 votes
0 answers
18 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 ...
2 votes
1 answer
102 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 ...
3 votes
0 answers
45 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:...
14 votes
1 answer
770 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 (...
3 votes
0 answers
108 views

Optimizing memoization in compiled Mathematica code

Consider the following two codes - compiledcode and compiledcode1: ...
0 votes
0 answers
78 views

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

Consider the following table: ...
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 <...
0 votes
0 answers
60 views

Problem using Compile together with Eigensystem

I have been trying to understand what is wrong with this piece of Mathematica code: ...
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 ...
1 vote
0 answers
67 views

What can be improved in the following custom interpolation?

Consider some test data: a grid of x, y, and values of some function on this grid: ...
4 votes
1 answer
218 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 ...
0 votes
0 answers
65 views

Compilable analog of Nearest?

Is there any analog of Nearest that is compilable? ...
12 votes
2 answers
1k views

Using Goto and Label in compiled function?

Bug introduced in 9.0 or earlier, persisting through 13.2 or later Below I post some rudimentary code to show that there is something wrong using Goto and Label commands in compiled functions (or I ...
0 votes
1 answer
99 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 ...
9 votes
3 answers
288 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: ...
5 votes
5 answers
511 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 ...
2 votes
0 answers
94 views

How to speed up compilation of some functions?

...
183 votes
6 answers
24k views

How to compile effectively?

What are the best practices of compiling functions? I understand that this is a vague question, but let me list some aspects that might trigger useful answers. Some of these have already been answered ...
0 votes
1 answer
134 views

Trying to speed up finding solutions of quadratic form related to the weight of a matrix

Say I have an integer matrix of size $5 \times 5$ - I am trying to find the solutions to the equation $n^4 wtM = n w^2 + x1^2 + x2^2 +x3^2 +x4^2 + x5^2$ subject to the constraints $x1+x2+x3+x4+x5 = 0$ ...
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 ...
0 votes
1 answer
150 views

How to compile this function to speed up operation?

...
12 votes
2 answers
399 views

Using DataStructures in FunctionCompile

This is a follow up to this StackExchange question I am trying to do the equivalent of Select on a "FixedArray" data structure. Here is what I have tried so far: ...
0 votes
1 answer
76 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 ...
22 votes
1 answer
592 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. ...
2 votes
0 answers
41 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
174 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
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? ...
3 votes
1 answer
207 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 ...
4 votes
1 answer
104 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 ...
0 votes
0 answers
60 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 ...
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 ...
2 votes
1 answer
52 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
113 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
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 ...
3 votes
1 answer
165 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 ...
2 votes
0 answers
79 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 ...
2 votes
0 answers
75 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 ...
0 votes
1 answer
62 views

Why does the following code not change the table?

Consider the following code: ...
0 votes
0 answers
136 views

Why is the following code not compilable?

The code below should replace particular elements of some table acccolumns if some condition is satisfied: ...
1 vote
1 answer
98 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
224 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
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
2 3 4 5
14