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

learn more… | top users | synonyms

36
votes
4answers
2k 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 ...
5
votes
2answers
56 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 ...
2
votes
0answers
19 views

weird behaviour of Listable fortran Librarylink function: different result each evaluation

I am working with fotran librarylink function currently. In this post, I will show some weird result of Listable fortran librarylink generated by intel compiler under windows (I tried gcc on linux the ...
1
vote
1answer
27 views

Length in Compile encounter “type Integer encountered in assignment of Type Real ”

Compile[{}, Module[{n}, n = Length[{1, 2, 3, 4}]; n = n/2]] The above code will emit errors Compile::cset: Variable n of type _Integer encountered in ...
-1
votes
0answers
19 views

Compile function with array argument and Listable runtime attribute [closed]

How to create a compiled function with an array argument and listable runtime attribute? I've tried ...
1
vote
0answers
52 views

Compiled function and integration

I'm using the recursive functions defined here: MyFnc and myFncC (compiled version). I want to call this functions in the ...
2
votes
1answer
216 views

Speeding up this recursive function

I have a recursive function defined like this: ...
1
vote
1answer
89 views

Manipulating Some Lists in Compile

Consider a list of lists, such as: Z={{1,4,3},{2,1,3},{3,1,4}} Z is an $n \times n$ matrix (here $3 \times 3$) which ...
1
vote
1answer
89 views

How to do this Function with compile

There is 4 lists, 3 of them are at same length (l0, l1 and l3). ...
116
votes
6answers
10k 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 ...
1
vote
1answer
100 views

Why doesn't Compile work on the Permutations function with second arguments?

Here is a narrowed-down example, the first case works, but the second one refuses to use the compiled version: ...
3
votes
1answer
72 views

Compile::cplist: error from MapThread [duplicate]

What is the cause of this error? Compile[{{r, _Integer, 2}, {d, _Integer, 2}}, pos = Position[MapThread[#1 > #2 &, {r, d}, 2], x_ /; x == True]] ...
1
vote
0answers
43 views

Compilation error: “Could not complete external evaluation at…”

I'm pretty new to trying to use Compile[], and I just can't see why I'm getting this error. I have two functions to define beforehand; one of them is a bit odd: ...
2
votes
1answer
127 views

different situations with Compilation of ConstantArray

First, we load some tools related to Compile for analysis. ...
18
votes
0answers
253 views

Compile not correctly initializing a variable defined inside Module

Bug introduced in 8.0 and persisting through 10.3.1 or later In the following example, inside the minimumX's Module, ...
23
votes
5answers
880 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 ...
5
votes
1answer
93 views

Compilation, square roots, and integers

After looking at this question, particularly this answer, I wrote my own performance test, using the two functions ...
0
votes
0answers
57 views

Error message when using a compiled function in NSum [duplicate]

Below is a simple example to illustrate the problem test = Compile[{{n, _Integer}}, n] Now, Table works fine ...
3
votes
3answers
97 views

about Compile and return type

In the mathematica document "tutorial/CompilingWolframLanguageExpressions" 1 It says about how to set return type of a called function you used in Compile. ...
6
votes
1answer
58 views

Compile Select returns “Null tensor with rank > 1 encountered at instruction 24”

This is the problematic part of one long function, wich should applyied many times to the list ...
5
votes
1answer
180 views

How to compile this code?

Could somebody teach me how to compile this code? ...
5
votes
1answer
130 views

Is it possible to change the precision in Compile?

I'm using Compile to do some numerical calculation and I need high Precision. I was wondering if it is possible to change the ...
3
votes
1answer
77 views

Is there any way to use compile and still maintain high precision in Mathematica? [duplicate]

Is there any way to use compile and still maintain Arbitrary-precision like 50 in Mathematica?
0
votes
1answer
50 views

Compile decreases the number of returned list elements

I have: LogisticMap = Compile[{μ}, ({μ, #} &) /@ Union[Drop[NestList[μ # (1 - #) &, .2, 300], 100]]]; Then: ...
0
votes
0answers
76 views

Nestlist inside Compile

My question is a continuation of question1 and question2, but I think it may be considered as a self-contained one. I am interested to make the following code faster ...
10
votes
1answer
301 views

Using Compile to speed up Function with PermutationProduct [closed]

I have the following fairly simple routine dot involving PermutationProduct that I wish to speed up using ...
5
votes
1answer
182 views

My introduction to Compile

I am reading Fractals from the Newton-Raphson method from Peter Young's page [http://young.physics.ucsc.edu/115/]{http://young.physics.ucsc.edu/115/}. I've tried: ...
5
votes
2answers
113 views

Escaping out of (or exiting) a Compiled Function

How do I manually escape out of a compiled function without forcing an error and compromising its speed? Here is an example: ...
10
votes
2answers
442 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 ...
6
votes
2answers
185 views

Challenge: Creating Compilable Permutations Function

As Mathematica's implemented Permutations function is not compilable I tried to write my very own Permutations implementation, called ...
5
votes
1answer
180 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: ...
20
votes
3answers
2k 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 ...
1
vote
0answers
101 views

integration of a list of gaussian type orbitals (GTO)

I am currently trying to integrate various components of a current density (j={jx,jy,jz}) over space. The problem is that the current j is extracted from a quantum chemical computation and is a sum of ...
4
votes
1answer
68 views
4
votes
2answers
221 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 ...
15
votes
2answers
198 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 ...
3
votes
0answers
67 views

Improving the speed of an optimization algorithm via compilation and parallellization

I have written an implementation of eight variants of the PSO-algorithm and I want to test them over a set of test functions. I am using parallelization as it improves the speed a lot and I have also, ...
11
votes
0answers
192 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 ...
24
votes
2answers
213 views

Listable compiled function crashes the kernel with “no more memory available”

Bug introduced in 9.0.0 and fixed in 10.3 I am trying to speed up a function that involves continued fractions. Since ContinuedFraction cannot be compiled and ...
7
votes
4answers
385 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 ...
9
votes
1answer
619 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: ...
2
votes
0answers
29 views

Unable to set up Mingw-64 compiler to get CompilationTarget-“C” working [duplicate]

I am unable to set up the C compiler on my computer, thus can't not make the option CompilationTarget-"C" work in Compile. I am ...
5
votes
1answer
87 views

Fast 1D BinCounts Alternative

I have lots of data which looks like this example: ...
7
votes
2answers
233 views

How to compile self-referencing functions (to perform recursive a task)

How do I compile a self-referencing function to perform iterative tasks? The naive approach doesn't seem to work. Here is a simple example to illustrate the problem: ...
5
votes
0answers
62 views
7
votes
1answer
149 views

Why does this simple sum function fail to compile?

Consider the following compiled function, which takes a $12 \times 5$ array $x_{ij}$ of real numbers and computes the triple sum $$ \sum_{k=1}^5 \sum_{i=1}^{12} \sum_{j=i+1}^{12} x_{ik} x_{jk}. $$ ...
1
vote
1answer
98 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 ...
7
votes
1answer
170 views

Compiled function crashes kernel when trying to list over different length arguments

Bug introduced in 8.0 and fixed in 10.0 I'm trying to speed up a tally/binning operation that I have to run many times. I have many lists of between 1 and 10 numbers from the range [1,5] and I ...