Questions tagged [compile]
Questions about the generation and use of compiled functions using Compile.
623
questions
2
votes
0
answers
32
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
40
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 ...
1
vote
0
answers
103
views
How can I set up Compile[] correctly on my Windows 11? I keep on getting an error that I have no compilers installed (but I do)
I'm trying to use Mathematica's Compile[] function to speed up some of my computations:
...
4
votes
1
answer
81
views
(Too) Slow Compiled Function To Sum Waves
I have some code that sums planar waves and outputs a graphical result, as per the mock up below :
...
1
vote
2
answers
124
views
Speed up calculation of recursively defined list
I have two lists $a$ and $b$ of length $n$ and $n-1$ respectively (typically I have $n \approx 1000$).
I have to compute a list $\theta$ of length $n$ which is defined recursively by the following ...
0
votes
1
answer
45
views
Why association slows down compiled function in the following example?
Consider the following code, which generates some data and performs some selections:
...
3
votes
1
answer
79
views
Is there any way to speedup the list selection further?
Consider some test data:
...
5
votes
0
answers
82
views
Warning from CompiledFunction is permanently off silently after generating for 3 times, bug or feature?
I've been vaguely aware of this behavior for a long time but never looked into it. Consider this sample:
...
2
votes
2
answers
76
views
How to speedup comparison in the following example?
I have the following problem: I would like to generate random values of some variable $z$ obeying some distribution, but simultaneously within the interval zmin<...
1
vote
1
answer
67
views
Speed up summation of many inverse matrices
Physical background
I am trying to write a code that computes the Green function of a system, given the Self energy $\hat{\Sigma}_n$, a list of Matsubara frequencies $z_n$ ($n=1,...,N_{Mats}$) and the ...
2
votes
1
answer
44
views
Error thrown by compiled expression
The following code is a minimal model of an error I am getting. It returns the error Compiled expression {{0,2},{2,0}} should be a machine-size real number. and <...
14
votes
1
answer
514
views
3D stable fluids algorithm based on FFT
This code is 3D extension of the code from my answer here. As well known the stably fluids algorithm is some kind of predictor corrector algorithm - see my answer here. This algorithm includes 3 steps ...
0
votes
1
answer
40
views
Set return type in compilation of a function of list
I hope to compile a complicated function with the process that create an complex list and sum over it. However, system always tell me the output should be a real number and I cannot change them. How ...
1
vote
2
answers
150
views
Using Compile with vector expressions
Consider a vector
vec[x_,y_,z_]={x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y};
I need to calculate, say, a table with vector values for the coordinates
...
1
vote
2
answers
81
views
How to use global variables in FunctionCompile?
In FunctionCompile, system does not recognize external functions and external global variables by default. But we can use ...
2
votes
0
answers
86
views
Fast value extraction for refreshing large data
I am trying to fine tune a procedure to reduce its running time. It involves two large arrays "data" and "positions":
...
2
votes
2
answers
116
views
Speed up counting of digits in binary number
I am writing a large numerical code where I care a lot about performance, so I am trying to write compiled functions that are as fast as possible.
I need to write a function that does the following. ...
2
votes
2
answers
97
views
Replacing symbolic variables inside of a compile
As the result of a symbolic integration, I have a very long array with symbolic variables u[i] which I would like to substitute for real number values. Moreover, I ...
4
votes
1
answer
83
views
Speed up functions using variable types but not Compile
I am writing a large numerical code and I have set up many functions that take several arguments as input. In the functions I am using several built in Mathematica functions, such as Sum[], Part[], ...
0
votes
0
answers
50
views
Getting symbolic form of `RotationMatrix`
Calling Compile seems to run into trouble compiling RotationMatrix, I'm guessing because it has type restriction to return ...
13
votes
1
answer
252
views
How can CompiledCodeFunctions be optimized and parallelized?
Fast generation of random variates as test case
The earlier question (195435) about performance tuning with regard to fast generation of random variates for a gamma distribution has stirred my ...
1
vote
0
answers
60
views
What do the Compile options" RuntimeAttributes -> {Listable}, Parallelization -> True" mean?
I am confused about what Compile's Listable and Parallelization options do.
(edit: This post is relevant: stack exchange "The option parallelization for compile")
My initial assumption was ...
1
vote
0
answers
33
views
Multi-NIntegral with a compiled function: Why not improved so much?
I want to compute the multi-dimensional integral by using NIntegral with the compiled function.
I have compiled an integrand function.
It made the computation time of the integrand about 100 times ...
10
votes
1
answer
181
views
How to programmatically construct a function or a compiled function?
I'd like to programmatically construct a function from a long expression with many duplicate terms. The objective is to programmatically create a set of compiled functions with expressions that were ...
0
votes
0
answers
43
views
How to compile a matrix with mixed values?
Consider some matrix
matrix = {{a,,...,b,...},...},
where a,b are some strings (like "Name"), ... inside the row corresponds to numbers, and ... are ...
0
votes
0
answers
58
views
Compile error in recursive code due to large integer
I am trying to implement a compiled version for the original algorithm that is supposed to run faster . It works fine for small iteration loop number when max=100. However, when loop number gets ...
13
votes
1
answer
264
views
How to convert the ListVector into PackedArray in FunctionCompile
Cross post here
I have a compile function cf to calculate the mean for a ragged list:
...
13
votes
3
answers
347
views
To accelerate FunctionCompile
I have a function value like this:
...
3
votes
0
answers
68
views
Using a compiled function in NMinimize
I can get NMinimize to work with compiled functions in simple cases.
This works with a constraint:
...
4
votes
1
answer
87
views
OptionValue not inserting correct option
I am using OptionsPattern and OptionValue to define some switches for my custom function. Here is a minimal example:
...
0
votes
0
answers
50
views
Compile and QPochhammer Function
I am running into trouble trying to make a listable function run in parallel. Arguably, the function that I am trying to compile is rather complicated.
Whenever I run the code below
...
7
votes
1
answer
125
views
Using Compile on Gradient within FindMinimum efficiently
This is an example from the documentation:
...
14
votes
2
answers
159
views
Help understanding a bug when FoldList using RandomChoice is Compiled
Bug introduced in 3.0, persisting through 13.1.
Preamble: I submitted this bug to support@wolfram.com and it was acknowledged. I assume it will be fixed eventually. In the meantime I'd like to ...
2
votes
0
answers
52
views
Using FunctionCompile to emulate DistanceMatrix with my own DistanceFunction
I'd like to create a distance matrix with an expensive distance function.
To explore how to do this for a simpler case, consider these three ways of creating a Euclidean distance matrix:
Using a ...
3
votes
1
answer
135
views
How to use Compile with list as argument [closed]
I want to use Compile for a function that takes 5 arguments (the function that is being compiled is not actually this one, but I am just using an example):
...
6
votes
1
answer
212
views
FunctionCompiling lists of things
I have a compiled function that works on a list of some atomic type e.g. strings, but also want it to work on lists of others (e.g. integers, reals, symbols, etc).
Moreover, nothing in the code has to ...
4
votes
0
answers
42
views
Can one have a ragged array as an intermediate step inside Compile? [closed]
I am aware that one should avoid (or be very careful) with ragged arrays as input or output of compiled functions. I, however, would like to be able to have a ragged array as an intermediate result ...
5
votes
3
answers
239
views
Implementing fast linear search for perfect vertical image alignment
After experimenting with image alignment aprroaches presented here and here and some other approaches involving ImageDistance and ...
0
votes
0
answers
32
views
Compiling functions with unit conversions
I have a numerical function that incorporates many units that I would like to speed up by using Compile. Here is a toy example of what I mean, doing it manually by ...
3
votes
0
answers
71
views
Free up used Memory
When using FunctionCompile[] to generate a large matrix of ranges there seems to be no way of recovering memory even though the variables are either out of scope or overwritten. I am aware that there ...
3
votes
1
answer
86
views
How To Compile The Computation Of Cumulative Returns
I'm trying to compile this function, specifically the second line which computes the cumulative return of 100 daily returns.
...
3
votes
1
answer
86
views
Compile function dynamically
To optimize a brute force algorithm on graphs I want to compile dynamically a list of functions for a list of graphs.
(The representation I'm using for a graph is a list of pairs of integers: integers ...
3
votes
1
answer
81
views
How to compile sum over the compiled expression?
Consider the following toy code:
...
5
votes
1
answer
89
views
Compile with arbitrary array argument
I need solve the task of classification of the points regarding their position. So I use such a function:
...
7
votes
1
answer
147
views
Pick with Unitize vs Pick with Clip vs Compiled Select speed - anything faster?
Given a large list of $n$ dimensional sublists where each sublist has integer elements I am trying to find the quickest way of finding all sublists that satisfy some constraint on their elements.
A ...
0
votes
1
answer
106
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
1
answer
52
views
Compiling an expression in a variable
I'm trying to compile a rather long (takes quite some time to scroll through) expression that is in a variable but I'm unsure how it would be done in mathematica. I've tried the obvious
...
0
votes
0
answers
60
views
How to speedup the following evaluation?
Consider the following function:
...
6
votes
1
answer
148
views
Mathematica never stop when running Needs["CCompilerDriver`"]
I am using Mathematica 12.2. I found that running
Needs["CCompilerDriver`"];
kind of freezes my Mathematica, it just never stop. Alt+. can not abort it ...