Questions tagged [performance-tuning]

Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

Filter by
Sorted by
Tagged with
0
votes
1answer
55 views

Import and export a list of SparseArrays efficiently?

I have a list of integers dims and a list of SparseArrays bdrs (representing a chain complex ...
57
votes
1answer
974 views

New Compiler Technology in V12

I am wondering whether the speed of compilation for the new compiler can be improved. Here are the results from my test. Consider the following function for generating a random draw from a gamma ...
39
votes
5answers
6k views

Efficiently generating n-D Gaussian random fields

I am interested in an efficient code to generate an $n$-D Gaussian random field (sometimes called processes in other fields of research), which has applications in cosmology. Attempt I wrote the ...
0
votes
3answers
60 views
11
votes
1answer
222 views

How can I avoid performance losses from ResourceFunction?

It seems like there is some sort of evaluation overhead related to the ResourceFunction wrapper that I'd like to avoid. This is especially pronounced for functions ...
1
vote
0answers
38 views

Improve NIntegrate + fit

I need to improve the performance of my fit. Below you can find the data I am using ...
3
votes
1answer
76 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. ...
5
votes
1answer
129 views

Avoiding CopyTensor of large array in Compiled functions

After reading about how to avoid the CopyTensor in various cases I still do not understand the optimal answer for the Fast-Hadamard transform below (CopyTensor appears in line 4 of the code): ...
1
vote
0answers
43 views

FileNames becomes extremely slow when there are large number of files under a directory

I have a directory on my portable hard drive, with around 350000 files under it (there is no subdirectory, only files). I want to get all the file dirs so use ...
0
votes
1answer
98 views

How do we use mathematica to apply my average to this example?

I have defined a set function and an average. If you need help understanding my definitions, let me know. I will do my best to explain. Question How do I use Mathematica to apply my definition of ...
5
votes
2answers
200 views

Function arguments are taking way too much RAM

I have to compute a function "func" with 24 arguments. Unfortunately when I apply the arguments the RAM fills up immediately. I even change the swap size of my Linux system to 100 G. I hope somebody ...
4
votes
1answer
124 views

Why Does Parallelization Not Speed Up these Seemingly Well-Parallelizable, Simple Functions?

Original Example Consider function f, a parallelized version fPar, and a coarsest-grained parallelized version ...
48
votes
1answer
4k views

Why won't Parallelize speed up my code?

What reasons are there that can cause parallelized Mathematica code not to run with full performance?
4
votes
1answer
85 views

Efficiently removing elements from list of permutations

I'm looking for an efficient way to remove entries from a list of permutations. I have a list of variables from which I calculate all possible permutations. I then want to remove those permutations ...
1
vote
0answers
38 views

CUDA and sparse arrays

Is there a way to use the CUDA functions (like CUDADot and so on) when we are dealing with SparseArrays? I found some answers to similar questions but they are extremely old (around five years ago) ...
1
vote
2answers
56 views

Optimize certian list over permutations, perhaps using recursions?

I am trying to improve my code for computing products of monomial symmetric functions. It boils down to the following. Let lam and ...
5
votes
1answer
131 views

How can I reduce timing to solve this equation?

I am tring to solve equation $$\frac{2 \log (x y+2021)}{\log (2)}+4^{x+1}=2^{x y+2022}+\frac{2 \log (2 x+1)}{\log (2)},$$ where $x$, $y$ are integer numbers. I tried ...
8
votes
1answer
353 views

Why are more highly nested lists often not more memory and time-intensive?

I would expect more highly nested lists, being deeper and more complex than flatter lists, to take up more space (bytecount) and take more time and memory to operate on in general. Consider the ...
0
votes
1answer
33 views

Generalizing previous question: Partition $[a,b]$ into $m$ sub-intervals and count number of sub-interval intersecting $A_1\subseteq[a,b]$?

In my previous question, How to partition $[a,b]$ into $m$ equal sub-intervals and count the number of sub-intervals that intersect with a subset of $[a,b]$?, I was given an answer to my specific ...
1
vote
1answer
77 views

How to partition $[a,b]$ into $m$ equal sub-intervals and count the number of sub-intervals that intersect with a subset of $[a,b]$?

Suppose we have a subset of $[a,b]$, where $a=0$ and $b=1$, such as $$A_1=\left\{\frac{1}{2^x}+\frac{1}{2^y}+\frac{1}{2^z}:x,y,z\in\mathbb{Z}\right\}\cap[0,1]$$ Which is a subset of $[0,1]$ If we ...
-1
votes
1answer
35 views

Using coding to calculate my average for functions defined on countable sets?

Suppose we have a function $f:A\to\mathbb{R}$ where $A\subseteq[a,b]$, $a,b\in\mathbb{R}$ and $S\subseteq A$. Now suppose $f$ is $$f(x)=\begin{cases} x^2+1 & x\in S_1\\ x & x\in S_2\\ \end{...
13
votes
2answers
778 views

Is there a faster way to calculate Abs[z]^2 numerically?

Here I'm not interested in accuracy (see 13614) but rather in raw speed. You'd think that for a complex machine-precision number z, calculating ...
2
votes
1answer
99 views

LeastSquares vs ArgMin

From the documentation, we learn that: LeastSquares[m,b], when b is a vector, is equivalent to ...
3
votes
2answers
258 views

Code that produces plot in V5 doesn't work in later versions

I have problem in plotting Integral function. I can compute/plot the graph of this integration below in Mathematica 5.0, but it is not possible to plot it in higher Mathematica versions. My code is: <...
10
votes
1answer
410 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
2answers
51 views

Is it possible to interrupt a computation and give partial results?

Is it possible to interrupt a computation and Mathematica shows the result obtained so far? Or alternatively the program starts a new computation (in my case very long lists) and the program ends ...
1
vote
0answers
46 views

Optimization for plotting

I would like to know if there is any way to improve the speed of the following program: ...
2
votes
1answer
189 views

Poor performance when evaluating double integral of hat functions

I am trying to evaluate a double integral but am having performance issues. First a bit of math I am using a Galerkin like scheme to discretize operators in an equation I am working with. The ...
6
votes
1answer
49 views

Default compiler optimization flag used by LibraryLink (CreateLibrary)?

What's the default optimization level (e.g. -O2, -O3) used by the function CreateLibrary, which invokes the system compiler to compile C/C++ code for use in LibraryLink?
4
votes
0answers
32 views

Difference in computation speed of Eigensystem not to expectation for ParallelTable and Table

I was trying to compute the time it takes for Eigensystem to evaluate while being inside a ParallelTable, as it is well-known LAPACK subroutine has an inbuilt Parallelization to it. And the difference ...
1
vote
1answer
77 views

Fast method for numerical integral (Fouriertransform?)

I want to numerically compute following integral (as fast as possible): \begin{equation} f(x) = \left| \int e^{ \mathrm{i} p x / 2} f(p) \ \mathrm{d}p\right|^2 , \end{equation} where $f(p)$ is given ...
5
votes
2answers
127 views

population density and incidence of COVID-19

I am trying to find the correlation between county population density and total COVID-19 cases in that county. This has been running for four hours so far. What's going wrong? ...
26
votes
4answers
1k views

Fractal basins of attraction in a Magnetic Pendulum

I am trying to write a Mathematica program that realizes a graphical approximation of the basins of attraction in a Magnetic pendulum subject to friction and gravity, in which the three magnets are ...
1
vote
1answer
35 views

$q$-multinomial series

I have the following code, which produces a $q$-multinomial coefficient, but selected randomly according to a Poisson distribution. Consider a 3D lattice path selected uniformly at random from a ...
1
vote
2answers
94 views

Systematically Optimizing Code for Better Runtime

Can someone please tell me how can I learn to systematically optimize my Mathematica code to be faster? I have seen a blog about the same but have no idea where to ...
2
votes
0answers
35 views

What built-in functions have bad time/space complexity and their alternatives?

It's surprising that Join is $\mathcal{O}(n)$ (due to copy) while I've been using it as a convenient way to join lists together. It also reminds me of suggestions ...
19
votes
3answers
429 views

Generate coefficient array from general formula of linear equation system

This is a problem coming out in the implementation of finite difference method (FDM). Here is a toy example. Suppose we want to solve the boundary value problem (BVP) $$y''(x)=\sin(x),\ y(0)=0,\ y(1)=...
4
votes
0answers
75 views

AppellF1 unevaluated [duplicate]

I have very long symbolic expressions, which I have to evaluate numerically later on. They contain the AppellF1 function, which stays unevaluated for the specific ...
3
votes
2answers
57 views

Better way for constant expressions in functions than storing as global variables?

For example, I wrote a function like this: inversions[list_] := Complement[ Subsets[{1, 2, 3, 8, 4, 7, 6, 5}, {2}], Subsets[list, {2}] ] But as you see, ...
2
votes
2answers
80 views

Slow replacement rule while combining symbolic summands

Edit: I attempted to use the method of repeatedly using Replace instead of ReplaceRepeated as suggested by Mr.Wizard, but the ...
0
votes
0answers
36 views

How to make Minimize[] work better?

I am trying to solve a relatively simple minimization problem where I can add numerical values to a bunch of my inputs to guess the minimum values: ...
7
votes
2answers
203 views

Best way to insert element into an ordered list at the correct position?

Suppose I have an ordered list orderedList and I want to write some code that will involve regularly inserting new elements into ...
4
votes
0answers
67 views

DateInterval Min/Max performance issue

Bug introduced in 12.1 and persisting through 12.1.1 Update WRI has confirmed that this is a bug. CASE:4521676 The performance of Min and ...
3
votes
0answers
44 views

Slow import of tif images

Importing a 900 MB tif file (~1800 frames) in Python takes ~9 seconds. The same file takes ~50 seconds to import in Mathematica. If the file size is ~150 MB then for Python takes ~2.5 s while MMA ...
1
vote
1answer
53 views
1
vote
1answer
60 views

How to efficiently animate changing mesh on a fixed 3D plot?

Say I'd like to visualise a height function of a torus by animating a plane going upwards, and highlighting the intersection via Mesh/...
11
votes
7answers
1k views

Find if there are consecutive 1s in a binary representation of a number

Given a list of numbers in decimal form, what is the most efficient way to determine if there are any consecutive 1s in the binary forms of those numbers? My solution so far: ...
1
vote
1answer
121 views

Determinant of 11x11 Matrix consumes immense amount of memory

I'm trying to take the determinant of an 11x11 matrix, constructed out of some functions I've defined ...
6
votes
2answers
307 views

Fast multiplication of high dimensional matrix

I am very new to Mathematica. I am dealing with the multiplication of matrix as the following code ...

1
2 3 4 5
45