New answers tagged performance-tuning
2
votes
Improve performance of DeleteDuplicates for list of matrices
Depends on the dimension of the matrix class. The fastest way of deleting without deleting for small matrices is to use Union. The EqualTest may be streamlined eg by comparing simple features like ...
- 135
1
vote
Accepted
Compiling a function that uses MapThread
It appears MapThread is so optimized that there's no point in using compilation in this case. Every modification I tried makes code slower.
...
- 6,857
3
votes
How to express the argument through the function?
No chance for mix of exponentials and powers:
Solve[a==f[d,B],d]
This one is working at least with implicit roots
...
- 135
0
votes
How to produce the following table faster?
Have you checked if the RAM memory is sufficient large to hold the complete imported data sets?
In windows start the task manager via Ctrl+Alt+Del and check the performance tab for storage access.
...
5
votes
6
votes
Accepted
How can I speed up calculation of the integral?
Using for general:
$$\text{Psi1}(r,z)=\exp \left(-a z^2\right) \left(\exp \left(-b r^2\right)+\exp \left(-c r^2\right)+\exp \left(-d r^2\right)\right)$$
then we have:
...
- 12.7k
0
votes
Values of counting functions
You can use Sort with Split. This method works for both positive and negative integers.
With
...
- 40.7k
3
votes
Values of counting functions
accumulatedBinCounts = Rest @ Accumulate @ BinCounts[#, 1] &;
Using Daniel's input examples:
...
- 356k
3
votes
Minimizing computational time for a quantum walk problem
With inclusion of changes based on earlier comments, and Normalization of state, and few changes, rapid computational time is noted. The amended code is as follows:
...
- 3,128
3
votes
Values of counting functions
Here is an alternative method which should work well even if negative numbers are present.
Let's generate some input data. Note this is about 8GB of data just for the starting list, so if you have ...
- 9,243
5
votes
Values of counting functions
Here is another way to go if the list is only nonnegative integers.
...
- 57.3k
7
votes
Values of counting functions
You can use SparseArray and Accumulate to assemble a vector cvec so that ...
- 101k
3
votes
4
votes
Accepted
How to speedup integration of interpolated function with logarithmized data?
I suggest that you try to use the substitution formula:
$$
\int_a^b \int_c^d f( \varphi(x),\psi(y)) \, \varphi'(x) \, \psi'(y) \, \mathrm{d}x \, \mathrm{d}y
=
\int_{\varphi(a)}^{\varphi(a)} \int_{\psi(...
- 101k
10
votes
Accepted
Why does Mathematica take so long to produce this sound?
Creating the audio signal as a vector first allows us to use more efficient ways to sample the function:
...
- 101k
9
votes
Why does Mathematica take so long to produce this sound?
The way you have created the function you are forcing MMA to keep evaluating your expression, which although lightweight on its own, is rather heavy when it needs to be repeated for different values ...
- 1,019
9
votes
Speeding up Gaussian sampling
This is my LibraryLink take on this. I use one of the random number generators of the standard library in conjunction with OpenMP.
This will only work on Apple Silicon with OpenMP installed via ...
- 101k
13
votes
Accepted
Speeding up Gaussian sampling
We can achieve noticeable speedup with Intel's MKL random number generator, which leverages hardware accelerated code.
m = 1000000;
d = 100;
Default behavior:
<...
- 34.5k
16
votes
Speeding up Gaussian sampling
Watching Activity Monitor, I don't think RandomVariate is multithreaded.
Luckily random samples from a normal distribution can be compiled. We can exploit ...
- 34.5k
1
vote
Fastest way to check if array is zero
You can try the following
AA = {{0, 0}, {0, 0}};
AllTrue[Flatten[AA], PossibleZeroQ]
- 11
1
vote
How to speedup calling the interpolation function?
Try purefunctionas Interpolation object
...
- 43.1k
0
votes
What is the fastest way to count square-free words?
This has come round again. The latest would appear to be https://arxiv.org/pdf/2012.03926v2.pdf
Community wiki
3
votes
Arrange 1-n^2 in n×n grid satisfy products of rows equal to products columns
The brute-force method you used works great for $n=3$ but there are too many permutations for values of $n$ greater than 3. Because you've stated that you don't necessarily need all solutions, another ...
- 37.1k
3
votes
Accepted
How to assign a new value to the table inside Compile?
Not sure if this is a toy example, but here's a way:
...
- 226k
7
votes
Accepted
Why the ugly code is faster than the pretty code?
The issue seems to be that you use
coordx1 = coordx[Tab1[[i]][[indexE]], M, Tab2[[j]][[indexE1]]];
instead of
...
- 101k
3
votes
Accepted
Solving $\sum_i a_i p_i^k=b_0$ for $k$
Writing your own "Newton's Method" is even faster (although that likely has fewer guardrails than FindRoot).
...
- 37.1k
5
votes
Solving $\sum_i a_i p_i^k=b_0$ for $k$
Taking advantage of @BobHanlon 's comment and using interpolation, one can determine the minimum and maximium possible values of $k$ to get a quicker approximation (maybe 15 to 20 times faster).
Basic ...
- 37.1k
Top 50 recent answers are included
Related Tags
performance-tuning × 2812list-manipulation × 512
matrix × 226
compile × 168
numerical-integration × 157
parallelization × 156
plotting × 145
differential-equations × 122
mathematical-optimization × 122
equation-solving × 119
programming × 109
linear-algebra × 104
numerics × 98
functions × 95
memory × 91
graphs-and-networks × 85
code-review × 76
sparse-arrays × 70
function-construction × 67
image-processing × 67
calculus-and-analysis × 61
probability-or-statistics × 59
graphics × 54
random × 53
evaluation × 48