Questions tagged [compile]

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

Filter by
Sorted by
Tagged with
168
votes
8answers
20k views

List of compilable functions

Is there somewhere a list on the functions that Compile can compile, or the cases in which a particular function can be compiled that I haven't found? I'd be glad ...
175
votes
6answers
22k 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 ...
77
votes
2answers
5k views

Internal`Bag inside Compile

Since Internal`Bag, Internal`StuffBag and Internal`BagPart can be compiled down, it is a ...
42
votes
4answers
3k views

Compiling more functions that don't call MainEvaluate

I would like to use Compile with functions defined outside Compile. For example if I have the two basic functions ...
33
votes
1answer
2k views

Has this implementation of FDM touched the speed limit of Mathematica?

Still, I'll use the implementation of the 1D FDTD method (you can simply understand it as a kind of explicit finite difference scheme for the Maxwell's equation) as the example. Just for completeness, ...
25
votes
2answers
3k views

Using a compiled function inside NIntegrate gives "CompiledFunction::cfsa" message

The following function is defined for Real input: ...
35
votes
4answers
2k views

Which Distributions can be Compiled using RandomVariate

Recently, Oleksandr kindly showed a list of Mathematica commands that can be compiled. RandomVariate was part of that list. However, whether this can be compiled depends upon the distribution that is ...
13
votes
1answer
6k views

Creating a standalone (executable) from mathematica code

I have written a small mathematica code to input a ".csv" file and output the data in a specific format, in a ".txt" file. I would like to give this program as an executable to my friend as she doesn'...
33
votes
2answers
828 views

Why is CompilationTarget -> C slower than directly writing with C?

Probably a hard question, but I think it's better to cry out loud. I've hesitated for a while about whether I should post this in StackOverflow with a c tag or not, ...
48
votes
4answers
6k views

How well does Mathematica code exported to C compare to code directly written for C?

Essentially what it says in the title. Mathematica can export its code to C. How much overhead does that inflict on the code, as compared to writing it from scratch in C?
26
votes
4answers
3k views

How to force Compile to return multiple results?

I would like to return two separate values from a compiled function, but Mathematica refuses to use the compiled version. Here is a narrowed-down example: ...
14
votes
2answers
3k views

MinGW-64 and CompilationTarget -> "C": can't make library

I'm trying to set up my new Windows 8.1 tablet to compile Mathematica (9.0.1) functions to C, using the MinGW-64 compiler. I have it set up so that the following works: ...
24
votes
3answers
571 views

Sudden increase in timing when summing over 250 entries

I see a sudden increase of Timing by a factor of thousands when I sum over 250 elements of a matrix rather than over 249. So for instance, this table contains sums ...
-1
votes
3answers
3k views

Problem with Compile Function

I am attempting to Compile this function which is used to calculate a elastic collision in two dimensions. The two first coordinates of each list are the position ...
2
votes
1answer
231 views

How to make the code inside Compile conciser without hurting performance?

Consider the following sample: ...
63
votes
4answers
4k views

Speeding up this fractal-generating code

I used the code below (which is a sample from this gist containing more similar code) in my answer to my own question about Mandelbrot-like sets for functions other than the simple quadratic on Math....
10
votes
0answers
897 views

Compile recursive function modifying global variables

How to compile recursive formula when it relies on more than a few global variables (global to the topmost compiled function)? It is unreasonable to pass on all such variables to each recursive ...
22
votes
3answers
3k views

Fastest way to measure Hamming distance of integers

I am looking for a fast and robust way to calculate the Hamming distance of integers. The Hamming distance of two integers is the number of matching bits in their binary representations. I expect that ...
6
votes
1answer
505 views

Precompiling a Whittaker function

Is there a way to speed up the evaluation of special functions in Mathematica? I am particularly interested in the Whittaker W function. For instance, the following piece of code: ...
13
votes
1answer
668 views

My introduction to Compile

I am reading Fractals from the Newton-Raphson method from Peter Young's page. I've tried: ...
23
votes
2answers
1k views

Efficiently collecting results inside a compiled function

When we don't know the number of results that will be generated, the usual way to collect results is Reap/Sow. Another ...
29
votes
1answer
6k views

How do I get Mathematica to recognize a C compiler on a 64-bit Windows machine?

Mathematica does not recognize any C compiler on my computer. I run Mathematica 8.0.4.0 on Windows 7. I've tried to make sure various C compilers are installed on my computer, but I'm not sure how to ...
11
votes
1answer
2k views

Example program for calling Mathematica from C

I want to call Mathematica from a C program. Suppose I have two numbers x = 2 and y = 3. I want to define ...
11
votes
1answer
370 views

Fine tuning compiled code that computes dilogarithm function

As an exercise in writing a good Compile function, I want to do the simple task of coding a routine that outputs the real part of the dilogarithm function ...
10
votes
3answers
706 views

Can I use Compile to speed up InverseCDF?

I'm repeatedly issuing the command P = InverseCDF[NormalDistribution[0, 1], T] where T is either a 36- or 64-vector of real numbers (points in the unit ...
14
votes
2answers
868 views

How can I compile this function

I want to simplify my function f1 to f2, but f2 can't be compiled. How can I make it ...
18
votes
1answer
581 views

Removing calls to MainEvalute when using inlined compiled closures

This question is tightly related to the answer Shaving the last 50 ms off NMinimize. There @OleksandR shows how inlined closures can be used to eliminate calls to ...
15
votes
3answers
545 views

Quick multiple selections from a list

What is the fastest way to make multiple selections from a list? Compiled methods included. For example, here are two methods for selecting a subset, compared:- ...
13
votes
3answers
1k views

Function does not compile with Greater in it

I have to speed up a matrix-calculation and would like to use Compile for it, though it fails and produces an unknown error message: ...
15
votes
1answer
615 views

Why is MainEvaluate being used when LinearSolve can be compiled?

According to this question LinearSolve can be compiled. However, CompilePrint[] shows a call to ...
9
votes
1answer
1k views

Compiling a recursive formula

My question is related to computing what is called "invariant measure" for a particular well known fractal - the Sierpinski triangle. We have an array m of four two by two matrices, say ...
9
votes
3answers
2k views

NIntegrate-ing a compiled function

I'm trying to integrate numerically in 6 dimensions a very long expression and I read about the option to NIntegrate a compiled function which should be faster. ...
5
votes
3answers
354 views

How to compile a diagonal array efficiently?

For example, if we use some functions defined prior to Compile, we usually have the main evaluators in the compiled codes, pointing to the definition of the ...
11
votes
3answers
787 views

How to define a complicated function inside the body of Compile?

I want to compile a function in a way to keep its memory footprint down. In the example below, I am trying to compile a function f that makes three calls to ...
31
votes
5answers
1k views

Can (compiled) matrix permanent evaluation be further sped-up?

Update III  Mathematica 10.2.0 now ships with a predefined System`Permanent function, which the PermanentCode package ...
21
votes
2answers
522 views

Third argument of Compile

In his last comment on this answer, halirutan shows an example in which the third argument of Compile does not have any effect. The example is as follows. ...
17
votes
3answers
909 views

Compiling LinearSolve[] or creating a compilable procedural version of it

Earlier today I had a discussion with a representative at Premier Support about the 2 questions I've asked here over the past couple of days: Seeking strategies to deploy a function securely ...
24
votes
2answers
515 views

What can be inlined by "InlineExternalDefinitions" -> True?

This not-well-documented option of Compile has been used quite a bit in this site, and based on these examples, I used to think ...
14
votes
1answer
504 views

Using Apply inside Compile

In this great answer a compiled version of the Nelder-Mead algorithm is presented. Since it works on arbitrary dimensions (i.e. arbitrary number of arguments), it has to use apply on the objective ...
15
votes
2answers
326 views

How do you determine the optimal autocompilation length on your system

When you pack lists there is an overhead therefore packing a list with, say, 2 elements is likely to cost more than you get back in efficiency. Mathematica has default list lengths for which functions ...
13
votes
1answer
228 views

Is it possible for LibraryLink function to be Listable like that in Compile?

We know in Compile, there is an Option RuntimeAttributes -> {Listable} which can let the compiled function easily explore the ...
9
votes
5answers
1k views

How to compile the code for generate Pythagorean_triple?

I am finding Pythagorean_triple, it worked slowly. I tried to compile, but it gives some warnings. I also use "Case" or "Do" ,both of them failed.I'm sure my CCompiler has been set correctly. How can ...
19
votes
1answer
447 views

Memory usage of compiled function: C vs WVM

Reported to WRI [CASE:3406803] Why does generating an array in "C"-compiled function uses 50% more memory than doing same thing in ...
11
votes
3answers
361 views

Can I return lists with different dimensions from a compiled function?

Sometimes I'll need several lists with different dimensions to be returned by a compiled function, but compiled function will fail if an irregular list contained: ...
14
votes
2answers
583 views

How to define a function inside a Compile?

I want to compile a variety of commands, including a function. I need to map this function, inside the compilation, and I can't include the function without facing errors such as "CompiledFunction::...
11
votes
1answer
565 views

Compilation of Total with compensated summation

I sometimes obtain an unexpected error when trying to call a compiled version of Total with compensated summation turned on. More specifically I define ...
14
votes
4answers
1k views

Implementing a compilable Faddeeva function of complex argument

For those, who are looking at Halirutan's answer and thinking "gee, I wish I was that good at LibraryLink, then I could really speed up my code!" I leave here the ...
6
votes
2answers
284 views

Challenge: Creating Compilable Permutations Function

As Mathematica's implemented Permutations function is not compilable, I tried to write my very own Permutations implementation, ...
5
votes
4answers
577 views

Findroot with a precompiled function with parameters

If I want to precompile a function that I intend to put into FindRoot many times, I could do it like this: ...
14
votes
2answers
1k views

Compiling the VoigtDistribution PDF

According to List of compilable functions, Erf and Erfc are compilable functions. However, I want to make a compiled version ...