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
0answers
7 views

Round-off error

Assuming $0<q<1$. I built these two functions A[k_,q_]:=Sum[PDF[BinomialDistribution[i, q], k]*PDF[ZipfDistribution[n], i], {i, k, Infinity}] and ...
2
votes
0answers
17 views

Why does it take so long to Quit?

Running Quit is a core task repeated many times in any debugging/development cycle. Its efficiency is therefore important and yet in my set-up it always seems to ...
2
votes
2answers
47 views

Dynamically set several values in a list at once

I am attempting to create a threshold which can be manually adjusted when necessary, but otherwise is assumed to be constant. This corresponds to a list of values, wherein all later values are set ...
3
votes
0answers
59 views

Why is ContainsOnly so slow for checking a list is full of zeros?

I'm on Windows 10 Mathematica 12.1.1. I would expect allocating a big ConstantArray and comparing would be slower but apparently it is not: ...
2
votes
2answers
74 views

Computational efficient way to find a SL(2,Z) matrix between two set of vectors [closed]

Suppose I have two sets of vectors (let's say it 2d, but it would be nice to generalize it to arbitrary dimensions): $(v_1,v_2,\ldots,v_n)$ and $(v'_1,v'_2,\ldots,v'_n)$ and they have integer entries, ...
0
votes
0answers
54 views

Looking for way to improve performance of a maximization problem

I am dealing with the following piece of code, to study a problem in quantum mechanics: ...
0
votes
3answers
61 views

Slow Integrate of a product of Boolean functions

I have ...
11
votes
1answer
229 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
39 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
79 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
0answers
44 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? [closed]

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 ...
4
votes
1answer
128 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 ...
4
votes
1answer
87 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) ...
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 ...
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 ...
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
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{...
8
votes
1answer
355 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 ...
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 ...
5
votes
1answer
130 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): ...
10
votes
1answer
418 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 ...
0
votes
1answer
73 views

Optimization for plotting

I would like to know if there is any way to improve the speed of the following program: ...
3
votes
2answers
259 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: <...
0
votes
1answer
59 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 ...
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
33 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
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 ...
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 ...
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 ...
5
votes
2answers
129 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? ...
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 ...
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 ...
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
1answer
99 views

LeastSquares vs ArgMin

From the documentation, we learn that: LeastSquares[m,b], when b is a vector, is equivalent to ...
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
208 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 ...
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 ...
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
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/...
6
votes
2answers
308 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 ...
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 ...
8
votes
3answers
662 views

How can I replace a set of Nested For Loops with a Functional Code Alternative?

Despite having looked over various posts concerning optimizing nested For loop expressions into a functional programming equivalent I still can not figure out how to actually to do this. Such ...
5
votes
1answer
116 views

Identify flipped data

Edit I'll try to reformulate my problem to make it more clear. Consider association with elements of the form {x,y} -> {f(x,y),g(x,y),...}, where keys are ...
7
votes
1answer
145 views

Efficiently populate sparse matrix with band structure

I'm trying to efficiently populate elements of a very large (2^20 x 2^20) symmetric matrix with 1s - luckily the matrix is very sparse, <0.1% filling. Further, the matrix has a very well defined ...
0
votes
0answers
42 views

Memory stored with `Trace`

When I inspect the details of a long computation using Trace, is there a way to know when a certain intermediate result is stored in the memory and, more ...

1
2 3 4 5
45