Hot answers tagged

34 votes

How to compile effectively?

Leonid Shifrin has already given an excellent answer for the question but it's so… long and may be frustrating for someone just beginning to learn the usage of ...
user avatar
  • 54.2k
34 votes
Accepted

Has this implementation of FDM touched the speed limit of Mathematica?

Okay, this is a bit of an embarassment. Here is a very small modification of the original code. I simply made explicit option settings, made a denominator to Sin ...
user avatar
32 votes

Strange behavior of Table

This is because Table automatically compiles its argument above a certain length limit. ...
user avatar
  • 227k
28 votes
Accepted

Use Compile to improve performance

First off, your function is very simple without any hard number-crunching, so it will always be hard to get a large speedup for the compiled version. Secondly, your ...
user avatar
  • 111k
27 votes

What does Compile[] do to make code run so much faster?

One of the biggest differences between main kernel evaluation and compiled evaluation in the "Wolfram Virtual Machine" (WVM) is that in the kernel, arbitrary expressions are allowed that are ...
user avatar
  • 220k
26 votes
Accepted

Sudden increase in timing when summing over 250 entries

The default SumCompileLength is 250. You can increase this number for example to 500 using ...
user avatar
  • 27.1k
26 votes

Why can Mathematica not use the compiled code?

It is important to Compile that it has always the same return type, no matter what happens at runtime. Note that Which returns <...
user avatar
21 votes
Accepted

Save a C compiled function without losing the blessing of C compiler

Yes, there is! Mathematica creates a LibraryFunction when compiling to C, but puts it in a temporary directory. If you can recover the library, you can load it as ...
user avatar
  • 8,628
20 votes

Which Distributions can be Compiled using RandomVariate

Another option to the answer posted by Andy Ross cropped up in a recent question of mine about corrupting an image with Poisson noise. In my own answer, I made use of ...
user avatar
  • 8,628
18 votes
Accepted

Is there any strategy to have a compiled version of FindFit or NonlinearModelFit?

No, it is not possible. With code converted to a LibraryLink library by way of Compile you are limited to using functions that either can be expressed directly in ...
user avatar
  • 22.6k
18 votes

Why is CompilationTarget -> C slower than directly writing with C?

Using Compile with CompilationTarget->"C" does generate C-Code to be compiled in a generalized way, the resulting code will ...
user avatar
  • 23.1k
18 votes
Accepted

Writing compiled functions as fast as Python's Numba

Based on the experience obtained here: ...
user avatar
  • 54.2k
17 votes

What does Compile[] do to make code run so much faster?

Extended comment.. I've never come across specifics of what Compile[] specifically does. That said, a definition re: programming languages in general provides some ...
user avatar
  • 13.8k
16 votes

Compilation of Total with compensated summation

Compilation of Total As pointed out in a comment, it seems that the compensated summation form of Total can't be compiled. You can check this using ...
user avatar
  • 8,628
16 votes

Why is this compiled function 50x slower?

Here is the original code. logisticMap[x0_, μ_, n_] := Module[{i}, RecurrenceTable[{x[i + 1] == μ x[i] (1 - x[i]), x[1] == x0}, x, {i, 1, n}]] We'll ...
user avatar
16 votes

Substitute for Association inside Compile?

For what it's worth, you can work with a HashTable as long as you're willing to put in a bit of effort ...
user avatar
  • 45.6k
15 votes
Accepted

Performance regression for Fold?

The reason for this behavior is that autocompilation always uses settings equivalent to "RuntimeOptions" -> {"Quality", "WarningMessages" -> False}. As ...
user avatar
  • 25.1k
15 votes
Accepted

CompiledFunctionCall vs. LibraryFunction

It appears that LibraryFunction occurs if the function being called inside the other compiled function is a function that has been compiled to C, provided this ...
user avatar
15 votes
Accepted

Is it possible for LibraryLink function to be Listable like that in Compile?

Simple solution There is an easier solution than the one I gave almost 2 years ago. In principle, you wrap your library function inside another CompiledFunction ...
user avatar
  • 111k
15 votes

Compile with a list as an argument

I think this is because a in your code represents a rank 10 tensor. If you want to use a as a vector, then I think it would be ...
user avatar
15 votes
Accepted

Implementing a compilable Faddeeva function of complex argument

Preface I've put a FaddeevaM package on my GitHub account that will do all that follows automatically. It is a full package that exposes all (and not only the Faddeeva $w$) functions for Mathematica ...
user avatar
  • 111k
15 votes
Accepted

Why can't I inject expressions in Compile using (only) With

Compile is considered a scoping construct by the outer With, and its bindings are protected. This will work: ...
user avatar
15 votes
Accepted

How to use CompilerOptions?

These are accepted as valid rules for CompilerOptions -> { rules }: ...
user avatar
  • 220k
15 votes
Accepted

LLVM compilation in version 12.3

No expert on this, but will share what little I know about this. This is based on my understanding of the video Wolfram Language Version 12.3 Sneak Peek with Jon McLoone Here is a link What ...
user avatar
  • 112k
15 votes

How to convert the ListVector into PackedArray in FunctionCompile

Edit Regarding the direct question in OP, i.e. how to flatten a "ragged" array inside FunctionCompile, I have to say there might be ready-to-use method ...
user avatar
  • 26.6k
14 votes
Accepted

MinGW-64 and CompilationTarget -> "C": can't make library

Figured it out. The key was working out that if I included "ShellOutputFunction"->Print in the $CCompiler list, compilation ...
user avatar
  • 1,302
14 votes
Accepted

Goto and Compile to C

Almost 3 years later.. The problem lies in the Label instruction. What happens when you have code that contains labels and gotos is that the ...
user avatar
  • 111k
14 votes
Accepted

What function generates random numbers in a compiled function?

This is not a full answer, but too long for a comment. We can try to look at the C code that Mathematica generates. ...
user avatar
  • 227k
14 votes

Compile and uncompilable function bug?

If you declare the type of DuplicateFreeQ, it works consistently (in V11.1.1). ...
user avatar
  • 220k
14 votes
Accepted

How to compile matrix product?

Compiling such linear algebra operatations does make some sense because we can give the compiler valuable information, e.g., that we use only $3 \times 3$ matrices. This allows the compiler to ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible