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

learn more… | top users | synonyms

6
votes
1answer
185 views

If doesn't compile if its output is the output of Compile?

The smallest sample I can find to reproduce this problem is: test = Compile[{}, If[True, 1]]; << CompiledFunctionTools` CompilePrint@test ...
10
votes
1answer
176 views

Bizarre behavior of With, Compile and Break

I'm guessing this is almost certainly a bug in Compile (because they're fairly common), but it's pretty weird and I spent about an hour tracking down the issue and ...
0
votes
1answer
97 views

Issue with Compile

The following code works fine with the the function f defined as a module, however, when I convert it to be a compiled function, it gives me errors. Can some one ...
1
vote
1answer
151 views

Compile with array operations

When I use the function f with only the Module ...
1
vote
0answers
34 views

Linear interpolation over 2 variables

I'm tuning a function to data over 4-5 variables using Differential Evolution. The objective function calls frequently interpolation function. I came to a point, where compiling the objective function ...
3
votes
1answer
169 views

Need help with C Code Generator

I'm trying to use the Mathematica C Code Generator package to generate code that is to be included in a web application by a developer. I don't know any C, and this seems to be the only way to ...
2
votes
0answers
48 views

Compiling/calling Mathematica-generated .so from C

I'm trying to call a compiled function from a C program. I am generating the static object ...
4
votes
3answers
141 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 ...
5
votes
1answer
99 views

How to speed up this TDSE code?

I'm trying to build a 1D time-dependent Schrodinger equation solver, using the Crank-Nicholson method. And I think the code is kind of working now, but the speed is still slow for me. Here is the ...
1
vote
0answers
42 views

Challenge: Creating Compilable Permutations Function

As Mathematica's implemented Permuations function is not compilable I tried to write my very own Permutations implementation, called ...
0
votes
1answer
178 views

Function won't compile. Is there a workaround?

Here's a simplified form of a function I would like to compile, but it produces errors ...
1
vote
1answer
120 views
0
votes
1answer
47 views

How to compile gather [duplicate]

First question,How to Compile this? gather[data_]:=Gather[data, Mod[#1, 3] == Mod[#2, 3] &] I dont know why this is wrong. ...
8
votes
1answer
327 views

Compile function which calls other functions to C

I have a function which calls other functions and I would like to compile it to C code. For example: ...
2
votes
1answer
43 views

Determine types of input, output and internal variables in compiled functions

I am trying to speedup the computation of a longer function using Compile. For illustration consider the following short example: ...
38
votes
2answers
2k views

Internal`Bag inside Compile

Since Internal`Bag, Internal`StuffBag and Internal`BagPart can be compiled down, it is a ...
13
votes
2answers
146 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. ...
4
votes
1answer
127 views

Can I compile a function containing ArcTanh?

Can I compile a function that contains ArcTanh[]? The following doesn't work Needs["CCodeGenerator`"] c = Compile[ {{x}}, ArcTanh[x]^2]; c[2.5] Mathematica gives ...
18
votes
0answers
156 views

M9 performance regression for Fold?

I noticed an over 10x performance drop on Mathematica v9.0.1 (as Oleksandr R. commented, also v8) compared with v7.01 for this code: ...
9
votes
1answer
120 views

How to avoid CopyTensor in CompiledFunctions?

In a reply here Leonid wrote, “Compile can handle a number of higher-level functions, such as Transpose, Partition, Map, MapThread, etc. Most of these functions return expressions, and even though ...
75
votes
5answers
5k 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 ...
24
votes
4answers
805 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 F and G F[x_] := x + 2 G[x_] := x And I want ...
40
votes
4answers
2k 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 ...
3
votes
2answers
134 views
5
votes
0answers
346 views

Having problems compiling Mathematica Cuda code

Ok I am trying to follow the examples of Cuda Code in the docummentation Run the CUDAQ[] and get back a True and run some of ...
4
votes
1answer
432 views

Catching and debugging numerical errors in compiled functions

I have a compiled function (that was created using the second method of this question). Basically it's using a compiled closure. The problem is that for some parameter values it does not evaluate. ...
3
votes
1answer
349 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 ...
4
votes
1answer
116 views

MapThread and Compile

After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of ...
8
votes
0answers
126 views

Check whether a working CCompiler is installed

Let me give a bit background: As many of my answers imply, I often use the auto-parallelization (meaning, that Mathematica distributes the calculation automatically over several cores when ...
1
vote
0answers
75 views

Compiled version of user-defined function

I have a function for parameter estimation with these codes: ...
10
votes
3answers
219 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: ...
0
votes
1answer
74 views

How can a function with an embedded function be compiled?

Compile fun continues today, and I'm trying to get the function below to compile. First the function: ...
32
votes
4answers
2k 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, IIRC, export it's code to C. How much overhead does that inflict on the code, as compared to writing it from scratch in C?
1
vote
1answer
94 views

How to apply compiled function on list

Compile function output error: How to apply compiled function on list? ...
1
vote
0answers
89 views

Using Part within a Compiled Command

I'm looking to define a multi-line function that makes use of the "Part" command. A toy example: ...
9
votes
3answers
364 views

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

Update  Multiple optimizations that were suggested by members "ssch" and Simon Woods have in aggregate yielded a ~5X code-speedup; and these optimizations now are incorporated in the example ...
13
votes
1answer
134 views

CompiledFunction returns machine numbers smaller than $MinMachineNumber

When thinking on the workaround for this LogLogPlot bug suggested by halirutan I noticed that CompiledFunction actually can ...
8
votes
3answers
367 views

What is wrong with my expression for compiling?

Following code was translated from a snippet matlab code. Without compiling it worked slowly. I want to compile it, but am getting a numerical error. How do I compile this in a correct way? ...
5
votes
4answers
566 views

Compile and “True should be a machine-size real number…” Error

I am trying to compile a little summation function. As far as I understand, because the built-in Sum function can also return ...
3
votes
2answers
173 views

My code for solving n queens problem Compile Failed

I want to make my code for solving n-queens problem faster, but it seems that MapIndexed can't be compiled. Mathematica return CompiledFunction::cfse: Compiled ...
1
vote
1answer
195 views

CompiledFunction::cfse: "Compiled expression X should be a machine-size integer

I am trying to use a compiled function in order to save time... LegrendeTransform = Compile[{y}, MaxValue[Sin[x] - x *y , x]] Now I want to to evaluate and ...
5
votes
1answer
161 views

How to use Compile to efficiently apply a function to every element of a list

Let's say I have a list of random numbers; list = Table[Random[], {100000}]; I want to apply a function f in every element of ...
8
votes
2answers
253 views
0
votes
1answer
101 views
0
votes
1answer
95 views

No Speedup Compiled Function in FindMinimum

The problem: I would like to minimize an objective function with respect to 12 variables. Minimization should be executed as fast as possible. Compiling the objective function increases the execution ...
5
votes
1answer
59 views
9
votes
1answer
210 views

error when defining a compiled function with ReplacePart

I always have difficulty in writing a non-trivial compiled function. I'm using Mathematica 9. Please see the following code ...
9
votes
1answer
329 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 the x, y in a C program and call Mathematica and I want Mathematica to do the sum and return me ...
2
votes
1answer
108 views

Can Map operations be compiled or otherwise sped up for large lists?

I'm performing a series of Map operations in the following script: ...