Questions tagged [compile]

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

Filter by
Sorted by
Tagged with
1
vote
0answers
30 views

Problem with the return type of Compile

Can I return anything other than a real number with a compiled function ? In the example below, I use Compile on a toy function to illustrate my problem, the real ...
0
votes
0answers
33 views
3
votes
2answers
241 views

Using compile to speed up evaluation of a While loop

I want to calculate a loop. For speed, I compiled my code. Even after the compilation, it is still very slow in getting the results. Are there any further improvements that can be made to my code? <...
2
votes
0answers
83 views

Repeated calling of a ParametricNDSolve result in a faster way?

I recently learned of ParametricNDSolve and found that I need to compute it once and then call its result sol at different ...
1
vote
1answer
131 views

How to speed up by Compile?

I need to NDSolve a system many times by scanning some of its parameters and do some matrix calculation with the (discretized) solutions. The example is the ...
1
vote
2answers
48 views

Compile function with only some variables [closed]

I made the simple example below for explaining the problem. How can I compile only some variables? For example, in the example only a and ...
6
votes
1answer
68 views

Compile - Optimization of function calls - does it matter?

I was surprised to see that, in the results of CompilePrint for a function made with Compile, calls to ...
0
votes
0answers
81 views

Why mathematica is returning error when computing correlation under Compile?

Can someone tell me what am I doing wrong here .. ...
2
votes
1answer
40 views

Downvalues for compiled functions

I'm a noob when it comes to DownValues, UpValues, OwnValues, etc. but I figured I would give ...
4
votes
2answers
61 views

Functions within modules within Compile

I've noticed that if I try to define a Function within a Module within Compile, I get errors ...
5
votes
1answer
112 views

'Block' with 'Compile' gives an error

Here is a minimal example to the problem I face when using Compile with Block: ...
19
votes
4answers
2k views

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

I am looking for an ELI5 explanation of what Compile[] in the Wolfram Language context does and why it works so much faster than uncompiled code in certain cases. I am trying to get more insight to ...
4
votes
1answer
120 views

What exactly prevents this code from compiling?

I am trying to compile a function that operates on an initial array (doing some sequential operation) to produce a matrix (which consists of N iterations of the initial array). Below is a minimal ...
7
votes
2answers
112 views

Can I improve performance of compiled deleteDuplicates?

I'm working on a project to compute pairs of complex numbers and need to delete the duplicates (within some tolerance, 10^-5 below). I was wondering if the performance of my compiled version can be ...
2
votes
1answer
90 views

k-subsets of several sets?

Problem: Let A and B be lists of lists of integers. I wish to find every k-element set, ...
1
vote
1answer
42 views

How to collect results from compiled function in ParallelEvaluate?

I am using Mathematica 12.x and have a compiled function, returning many things. I would like to run several instances of this compiled function, one for each core of my CPU, and then collect all of ...
1
vote
1answer
50 views

How to inline a variable in function definition

I need to compile a function g that calls an external function f. f and ...
5
votes
2answers
59 views

Are arbitrary expressions allowed as input arguments in Compile?

I made a typo when entering code for Compile. I thought it should have resulted in an error when the code was compiled, but it didn't. It did give an error when ...
2
votes
2answers
237 views

Speed improvement for root finding

I'm wondering whether it is possible to speed up the following code that I'm using to find points on the intersection between a line and the zero locus of an equation. The idea is the following. First,...
1
vote
0answers
60 views

Create Compiled Version of Function

I am trying to speed up the following function by compilation: ...
2
votes
0answers
114 views

How can I use Compile to Evalaute a trace of a sympolic Matrix?

I would like to evaluate a trace of a matrix of size 4Wn×4Wn at different point (x,y). with <...
5
votes
0answers
54 views

Effectivelly using Compile for calculate a Unitary transformation

I am new to Mathematica, and this is my first post, so if my question is not clear enough, I would be glad to read the comments and edit my question to add more information. The problem I need to ...
1
vote
0answers
63 views

LTemplate and external library Armadillo

As a great fan of the simplicity of the LTemplate library for the end user I am now faced with a problem when apparently everything compiles correctly but the functions are not loaded from the library....
0
votes
1answer
39 views

Compiling RiccatiSolve LQRegulator gains

Given some specific matricies, numA, numB, numP, q and r to calculate LQR gains, one can use simply LQRegulatorGains or solve the same via ...
2
votes
3answers
83 views

Strange Behavior of Compile[] inside With[]

Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
6
votes
1answer
107 views

Mathematica does not recognize c compiler

I have Mathematica 11.1 and Windows 10 OS. I need to use c based compilation inside Mathematica, like ...
3
votes
1answer
96 views

Compiled Function is slower than non-compiled version?

I need to maximize a function numerically, thus the speed of this function is very important. Here is the most time consuming part of this function. ...
1
vote
1answer
37 views

How to have a common input for different nb file

I have a set of five files. Each file takes a common input. But I need to change the input and run the files. The output of some file are used in other files. So how to do this. And also is there any ...
1
vote
1answer
70 views

Error on using Compile[]

My code is below. ...
2
votes
0answers
112 views

Convert huge (10-100MB of plain text) Mathematica function for external use

I have a huge Mathematica function (plain text ranging 10-100MB) that I am trying to convert to Fortran for external use. I tried using FortranForm, which does most of the work, and cleaned the code ...
3
votes
1answer
85 views

How to do meta-programming inside Compile?

I'd like to do this: solve some linear systems, compiling the task of getting the building up the matrices from parameter values, and then I have a compiled implementation of LinearSolve. The problem ...
1
vote
2answers
49 views

How to compile a function that takes a list of arguments using InlineExternalDefinitions?

I can do this right now, but I'd love to make the argument a list. (I have a compiled implementation of Linear Solve from here https://mathematica.stackexchange.com/a/91881/73342). ...
3
votes
1answer
73 views

How to use a list inside Compile—it says it should be a machine-size real number?

Super simple question, but I'm lost here. f = Compile[{{a, _Real}, {b, _Real}, {c, _Real}}, x /. NSolve[a x^2 + b x + c == 0, {x}]] f[1., -4., -5.] gives the ...
10
votes
1answer
487 views

Writing compiled functions as fast as Python's Numba

I want to write some code to simulate a damped oscillator that is just as fast as code written using Numba's @njit decorator. I've written the mathematica code and ...
0
votes
0answers
50 views

Basic question of “good” habits during the evaluation of a notebook in mathematica

Suppose that I have notebook, call it Nb1. And I want to evaluate the notebook Nb1, next suppose that the process is slow, but I have to evaluate other notebooks, suppose Nb2, and Nb3. I see that ...
1
vote
0answers
54 views

Optimal code generation for evaluation of a fixed set of multivariate rational polynomials

Given a set of multivariate rational polynomials, is it possible to find the optimal (shortest or least expensive in some other sense) sequence of arithmetical operations, such that it results in ...
10
votes
1answer
116 views

How to use CompilerOptions?

The refpage for FunctionCompile's option CompilerOptions is empty of examples: Does anyone know what keys and values can be ...
2
votes
1answer
58 views

why this simple code is not giving the right answer under Compile

I have two sets of inputs that are to be fed to a simple function. The inputs are essentially a set of triangles and the normal for each triangle. The function will compute the gradient about the ...
4
votes
1answer
158 views
3
votes
1answer
65 views

Compile a function with undetermined number of variables

I have been wrapping my head about a question it may look simple to you. I want compile a function that depends on a number of undetermined variables as, ...
3
votes
1answer
31 views

How to handle numerical exception within a compiled function

I'm trying to evaluate a series of expressions, which, given a set of parameters, may be complex. Instead of throwing a CompiledFunction::cfn, I'm trying to catch ...
0
votes
0answers
23 views

Compiling generalized correlation doesn't lead to speedup

Mathematica is capable of calculating a generalized correlation of a list lst with a kernel ker. In my case, I'm interested in performing this, ...
1
vote
1answer
39 views

Issue with Compile for Complex Input/Output

I'm writing a Runge-Kutta algorithm for solving a system of coupled differential equations. My code works fine when defined as a module, but when I try to compile it, I get the following error: ...
1
vote
0answers
75 views

Faster methods for performing repeated list manipulations?

I've done my best to pore over the other posts on this site, and to the best of my ability I can't seem to find a good solution to my problem, so I apologize in advance if elements of my question are ...
5
votes
1answer
95 views

Compiling with Listable option and Parallelization

I have a bunch of triangles (200k) I need to calculate the normals of. Here are five of them below, each one with its vertices in CCW order. ...
5
votes
1answer
165 views

Table vs. ConstantArray efficiency with compilation

I've been trying to optimize a bit of code the past couple of days, but think I might be misunderstanding how compilation on certain target functions works. As a most barebones example, I've attached ...
16
votes
2answers
302 views

How to use DataStructure in FunctionCompile?

The official document said compile a function that can work with data structures but how to use it? There is no doubt that it is possible to use DataStructure as a function parameter: ...
5
votes
1answer
126 views

Compiling a function depending on an external function

Consider the simple case: g[x] := x^3; f[x] := x^2 + g[x]; cf = Compile[{{x, _Real}}, x^2 + g[x]] Evaluating the two functions, Mathematica complains that the ...
3
votes
1answer
115 views

How to use IntegerQ in FunctionCompile?

Seems like an easy request, but I've somehow gotten myself stuck again: ...
11
votes
0answers
177 views

How to use Bags in FunctionCompile?

I was reading this question and it wanted to know how to FunctionCompile this: ...

1
2 3 4 5
11