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

learn more… | top users | synonyms

6
votes
2answers
145 views

How can I prevent a compiled function from using uncompiled evaluation?

I write a code that creates a compiled function, and then call that function over and over to generate a list. I run this code on a remote server via a batch job, and will run several instances of ...
4
votes
1answer
84 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: ...
1
vote
2answers
53 views

How to speed up recursive compiled functions?

I'm trying to speed up the recursive function that calculates Rotation numbers: ...
12
votes
1answer
142 views

In Compile “InlineExternalDefinitions” doesn't work anymore in Mma v10 like in v9

In Mma 9 using CompilationOptions -> {"InlineExternalDefinitions" -> True} inside of Compile inlined the values of the ...
1
vote
1answer
48 views

Warning and Errors during Compile

I defined a compiled function cf = Compile[{{x, _Integer}, {n, _Integer}}, z = (n^x); Binomial[n, #]* StirlingS2[x, #] *(#!)/z & /@ Range[x]]; and I ...
4
votes
3answers
178 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 ...
0
votes
0answers
51 views

Regarding CompilationTarget->“C”

Recently I have read some interesting things about CompilationTarget->"C" on SE, e.g. in http://mathematica.stackexchange.com/a/54459/11116 where @MichaelE2 ...
5
votes
1answer
285 views

CompilationTarget->“C” crashes the kernel

Major deviation from my original post I realize that the long code I originally had was very discouraging to debug and did not attract any answers. So I have decided to revamp this question ...
0
votes
0answers
64 views

Compile without hardcoding

My question is how to pre-compile the rules1, rules2 and result parts of the following Module code without hard-coding the many (and changing number of) variables and rather complicated equations: ...
1
vote
0answers
51 views

Why isn't Compile working for me? [closed]

I cannot get what's the problem with Compile function in my program. If I simply use the Abs function, I get this answer: ...
0
votes
0answers
31 views

Get rid of external library dependency

I am trying to generate C code for some functions, which I do not post in full because they are a few hundred lines long. The functions do nothing too fancy: a bunch of dot products, powers and roots. ...
0
votes
1answer
44 views

Alternatives to indexed variables in Compile

According to the excellent answer given here by @Leonid Shifrin: How to compile effectively?, You can not really use indexed variables in Compile, although it ...
1
vote
2answers
39 views

Compiling function with predefined expression

I'm using the Compile function in Mathematica to compute say the following : f=Compile[{x,_Real},Cos[x]] Then I can compute f[x] for x taking any real value. Ok, ...
1
vote
1answer
79 views

Mathematica Compiled Functions - additional functions

Mathematica supports an exact list of compilable functions: They are listed here: List of compilable functions. However, I would need to add the following functions: ToExpression, StringFreeQ, ...
3
votes
1answer
71 views

Usage of Block in Compile

When is there an advantage to using Block in Compile? For instance, if I have a multiple-step code, how do I decide which ...
1
vote
2answers
200 views

A fast way to compare interval

I have a list of intervall. Some of these intervals are disjoint, some are overlapped and some are included in others. To leave no ambiguity about my explanation, you can see the following examples: ...
14
votes
2answers
191 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. ...
1
vote
0answers
66 views

When to use Compile

I am new to Mathematica and have a general question: Working with matrices I have the impression that Compile can only be used if the elements of a matrix are ONLY Integers or ONLY Reals. No mixed ...
2
votes
1answer
61 views
7
votes
1answer
196 views

make mathematica recognize CCompiler and compile CUDA code on remote Windows machine

I have set up a Mathematica remote kernel on a Windows 7 64 bit machine, which has Microsoft Visual Studio 2010 installed. When I start Mathematica on the windows machine Mathematica recognizes the ...
0
votes
0answers
46 views

How to compile a function whose arguments are list?

I'm unsuccessfully trying to compile this function check[argA_, argB_] := argA[[1]] == argB[[1]]; assuming that both arguments argA and argB are of the form ...
0
votes
1answer
198 views

Function won't compile. Is there a workaround? [duplicate]

Here's a simplified form of a function I would like to compile, but it produces errors ...
20
votes
1answer
214 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: ...
6
votes
1answer
209 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
233 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
126 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
203 views

Compile with array operations

When I use the function f with only the Module ...
1
vote
0answers
56 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
204 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
58 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 ...
5
votes
1answer
115 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
54 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 ...
1
vote
1answer
181 views
0
votes
1answer
56 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. ...
9
votes
1answer
363 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
66 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: ...
40
votes
2answers
2k views

Internal`Bag inside Compile

Since Internal`Bag, Internal`StuffBag and Internal`BagPart can be compiled down, it is a ...
4
votes
1answer
141 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 ...
9
votes
1answer
141 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 ...
80
votes
5answers
6k 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
945 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 ...
41
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
151 views
5
votes
0answers
374 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
497 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. ...
4
votes
1answer
625 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
135 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
141 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
81 views

Compiled version of user-defined function

I have a function for parameter estimation with these codes: ...