Questions tagged [compile]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
307 views

Sum acting weird for large values [duplicate]

I have the following functions: T = Compile[{n}, Boole[Sum[RandomReal[]^2, {n}] <= 1]]; Monte[d_, n_] := Sum[T[d], {n}]/n*2^d T is a function that generates a ...
6
votes
2answers
439 views

OptimizeExpression to C code

Is there a function which turns optimized expression to C code? Calling Experimental`OptimizeExpression[ Sin[x] + Cos[Sin[x]]] returns ...
4
votes
0answers
85 views

Can this code be compiled? [closed]

The following code reads all gray scale png images inside of a folder and then calculates the maximum intensity for each pixel and finally export the resulting image. This is until now the fastest ...
1
vote
1answer
79 views

Compilation without MainEvaluate

I'm trying to avoid MainEvaluate in CompiledFunction. I've tried below but I couldn't get rid of it. I'd appreciate any help!! Here f1 and f2 will be rank 1 list with real type. ...
4
votes
2answers
93 views

Modified FrontEnd to parse & highlight function definitions for compilability?

I suspect this would require advanced MMA skills, but it would be very useful if one could modify the front end so that any MMA defined function calls in a Compile[] could be flagged if they are not ...
0
votes
0answers
102 views

Compile function for NMinimize

I have a the following script, which essentially minimizes the function $h$ with respect to all the variables $a[\alpha][s][j][n]$, where $\alpha,s\in\lbrace0,1\rbrace$, $j \in \lbrace ,\ldots,\text{...
4
votes
1answer
250 views

The option Parallelization for Compile

When during the compilation of a function of one argument we use the option RuntimeAttributes->{Listable}, the resulting function is automatically threaded over ...
4
votes
1answer
117 views

Does the RuntimeOptions -> “EvaluateSymbolically” -> False work for “1-x”

I would like to pass a CompiledFunction to a FindRoot algorithm and therefore I use the option ...
8
votes
2answers
1k views

Why is this compiled function 50x slower?

Why is the compiled function so slow? I have seen question 41344 but don't understand any potential relevance. Here are the two functions for comparison ...
4
votes
1answer
585 views

Can one compile the Switch function?

I am aware that one can compile Which, e.g.: ff = Compile[x, Which @@ {x < 0, 2, x >= 0, 3} ff[1.] ...
5
votes
1answer
169 views

How to avoid AppendTo when computing similarities

I need to make the calculation of the HammingDistance for strings faster. The background is that I want to be able to compare the similarity of images of a textual ...
9
votes
0answers
108 views

Fast Destructuring

This might be a XY problem. I first post my immediate question and some background below. Question: What's the fastest way to pass arguments matching ...
1
vote
1answer
80 views

How can I speed up this compile code with four variables

I would like to caculate the following codes with four variables. When the dimension is 10*10*10*10, the complile time is about 2 seconds. (just for estimate the time). When the dimension the 50*...
3
votes
0answers
95 views

How to deal with “Compile::cset” in Compile

When compiling below code Compile[{{data, _Integer, 2}}, Fold[Flatten /@ Flatten[Outer[List, ##, 1], 1] &, data]] I encountered error messages Compile::...
7
votes
0answers
78 views

Mathematica 9 can't compile Increment Part with C

Why can't Mathematica 9 compile this code? x = {1}; Compile[{}, x[[1]]++;, {{x[[1]]++, _Integer}, {x[[1]], _Integer}}, CompilationTarget :> "C"][] After ...
0
votes
0answers
193 views

Compiling matrix multiplication using a list of matrices

I'm trying to create compiled function which computes a list of Gamma matrices named GammaM and multiply them within the compiled code. ...
0
votes
0answers
49 views

Compiling a function while dealing with symmetries

I have the following function that I would like to compile: ...
12
votes
1answer
164 views

Bug with Compile and Log2?

It seems that Log2 in Compile gives numerical errors (CompiledFunction::cfn) if the input is ...
9
votes
2answers
208 views

Efficiently checking whether a number is a perfect power

Goal The goal is to efficiently check whether a number is a perfect power. Attempts It is possible to check whether a number is a perfect power using ...
8
votes
1answer
189 views

Replace nested external definitions in Compile

f = #^2 &; Compile[{{x, _Real, 1}}, f /@ x, CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint works fine. ...
4
votes
2answers
564 views

Compile with function definition inside

How can I compile a code with target C containing function definition inside? I saw post using With. But this just inserts the function in the appropriate place ...
2
votes
0answers
155 views

How to use Compile? Bivariate Gibbs Sampler

I am trying to use compile to speed up my Gibbs sampler. I know I can use Reap and Sow to speed up tremendously. I have a more complicated Bayesian posterior that I want to speed up with compile so I ...
0
votes
0answers
77 views

Compiling LinearSolve with 2 complex matrices, possible bug

Take two complex matrices depending on one variable, for example: ...
2
votes
1answer
229 views

Compiling in mathematica

I'm trying to compile what I think is a pretty simple function that does matrix multilplications in a loop (see below). But Mathematica issues the message: Could not complete external evaluation ...
3
votes
1answer
134 views

Table with programmatically specified number of iterators in Compile

Compare two ways of computing a table of values of a multivariable Gaussian: ...
7
votes
1answer
289 views

How to boost the performance of my own BSplineFunction

In my CAGD package, I implemented a CAGDBSplineFunction[] like built-in BSplineFunction[]. ...
8
votes
1answer
635 views

Create a Mathematica function that can be called from R or Matlab

I would like to export a function from Mathematica to allow it to be accessed from R and/or Matlab. Is there a way to do this? As an example, suppose I want to export the following (albeit ...
1
vote
0answers
132 views

How to speedup Plot3D with precompiled argument

I have a huge problem with my code: I estimate it to take hours to run. The scheme of the code is the following (I left the steps the same, but took much simpler functions): ...
6
votes
1answer
1k views

Compile with a list as an argument

This is probably trivial, but I couldnt make it work: safeConv = Compile[{{a, _Complex, 10}, {b, _Real}}, If[b > 1, a[[1]], 0] ]; I get a rank-error ...
0
votes
0answers
361 views

How to compile code that involve sparse array?

I have the following code ...
0
votes
0answers
50 views

Compiled funtion don't understand internal compiled function [duplicate]

I work a lot on Mathematica and sometimes I need to optimize my computations by using compiled functions. Now I'm making numerical integrations and I'm trying to compile the functions involved to make ...
1
vote
1answer
121 views

What's the syntax to compile these functions, whose arguments are nested lists? [closed]

In some case the Compile's syntax is quite straightforward. Es. for rank 1 e rank 2 tensors: ...
12
votes
2answers
360 views

Has compilation of big programs become excessively sluggish in v 10.4?

Bug introduced in 10.4 and fixed in 11.0 After updating to 10.4, many of my heavily numerical functions defined by Compile takes a huge amount of time to compile ...
2
votes
2answers
245 views

Compile function - error but correct calculation

I am investigating Compile lately and I came across the following problem. I define a 2-variable function ...
4
votes
1answer
196 views

Why does Compile not make my function faster?

I need to speed up a large program that repeatedly calls the module below (I've not trimmed the code for this question to ensure there is enough calculation to show a speed improvement.) The obvious ...
2
votes
3answers
215 views

Compile error with MapThread

I have the following code: ...
3
votes
1answer
177 views

List of compiled functions and then plot them 1 by 1.

I would like to create a list of compiled functions and then plot them 1 by 1. To illustrate the problem (In reality the functions I want to compile are of course not x^j but some complicated ...
7
votes
2answers
601 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 ...
3
votes
0answers
82 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
145 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
vote
0answers
275 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 ...
12
votes
1answer
189 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 ...
2
votes
1answer
304 views

Speeding up this recursive function

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

How to do this Function with compile

There is 4 lists, 3 of them are at same length (l0, l1 and l3). ...
1
vote
1answer
109 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
108 views
3
votes
1answer
128 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
145 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: <...
4
votes
0answers
177 views

Is it possible to prohibit unnecessary CopyTensor in Compile? Just like .noalias() in Eigen library?

Turn on Needs["CompiledFunctionTools`"] First example ...
3
votes
1answer
229 views

different situations with Compilation of ConstantArray

First, we load some tools related to Compile for analysis. ...