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

learn more… | top users | synonyms

5
votes
1answer
56 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 ...
2
votes
0answers
67 views

Compile issues, scoping and order of evaluation

I have a few questions about compiling functions, which I think are all related to scoping and order of evaluation. I will illustrate them by a minimal example of the problem I have. I'm sorry for ...
2
votes
0answers
29 views

Compiled DiagonalMatrix

The standard function DiagonalMatrix cannot be compiled, so I tried writing my own: ...
3
votes
0answers
35 views

CompiledFunction with multiple outputs of different ranks

Below is a simple compiled function f that gives multiple outputs. ...
4
votes
1answer
156 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: ...
3
votes
1answer
322 views

Using Compile Function Options efficiently

While this gives general pointers, I want inputs on ground rules for improved performance of nested/interdependent compiled functions. sample problem: a, ...
21
votes
3answers
587 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 ...
5
votes
4answers
226 views

Speed up Schwarz-Christoffel mapping

I would like to ask your advice how to speed up Contour and Parametric plots in the following example. Let as start by defining a function ...
6
votes
0answers
95 views

Exporting a compiled function for later use

I compiled a function then used it in NMinimize. The computation took 19 seconds. Then, I exported this compiled function and restarted MMA and imported this ...
1
vote
0answers
81 views

Compiler stack overflow

I tried to compile a huge function. I used these options: ...
6
votes
0answers
52 views

Listable compiled functions used in NMinimize

This is an example from MMA: cListable = Compile[{x}, (x-1)^2, RuntimeAttributes -> {Listable}] In case of single entry: ...
3
votes
2answers
78 views

Problem with machine number precision in compiled functions

When I compile a very big function and give it input the function returns error. I realized that this is because the value of the function becomes smaller than the smallest machine number. Is it ...
0
votes
0answers
59 views

Mathematica cannot find the c compiler

I installed Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 Then, I installed Mathematica 10 trial version. I did: ...
1
vote
2answers
106 views
-2
votes
1answer
47 views

Compile Determinant [closed]

I would like to determine the determinant of a 4x4 matrix with the entries a[i,j] being functions of $i$ and $j$. I used Compile with code: ...
2
votes
0answers
37 views

Is it possible to Compile the function with string argument?

As we can see from the Compile documentation, the typical arguments for Compile should be ...
2
votes
2answers
132 views

How to use Compile

Consider the code below: variable = Sin[x]; fun = Compile[{x}, variable ]; fun[1] When I do this I get the error: ...
27
votes
4answers
1k 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 ...
0
votes
0answers
42 views

Evaluation inside Compile

here's a simple question: I have a function: ...
3
votes
1answer
120 views

Why is my compiled code slower?

I am trying to make a Mathematica program run faster. Here is part of the original version. It takes as input the integers X (of order 100), J (of order 10000), and n (of order 100), the real number p ...
1
vote
0answers
133 views

Speeding Up Image Processing Functions

I am working with stacks of 1024x1024 timelapse microscopy images that I am performing a series of image processing functions on to help segment each image. These functions include ...
1
vote
1answer
224 views

Performance of compiled functions (Project Euler No14)

I was playing around with the project euler problem 14. The solution I came up with is listed below as cf1. The solution works fine but I get the compiler warning: ...
7
votes
2answers
169 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 ...
1
vote
2answers
64 views

How to speed up recursive compiled functions?

I'm trying to speed up the recursive function that calculates Rotation numbers: ...
13
votes
1answer
161 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
51 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
188 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
54 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 ...
6
votes
1answer
304 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
66 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
56 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
34 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
51 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
48 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
83 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
73 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
202 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: ...
15
votes
2answers
200 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
69 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
63 views
7
votes
1answer
230 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
52 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
200 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
220 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
216 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
234 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
137 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
215 views

Compile with array operations

When I use the function f with only the Module ...
1
vote
0answers
63 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
228 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 ...