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.

3,002 questions
Filter by
Sorted by
Tagged with
83 views

Best way to implement the "plus-distribution" for very long expressions?

I'm at my wits end here. Is there an efficient way to implement the following distribution into MMA: $$\int_0^y dx \frac{f(x)-f(y)}{y-x}$$ where $f/1-x$ can be analytically integrated. The difficulty ...
64 views

Optimize while loop with several conditions

I am trying to generate several random numbers according to some conditions, but the way I have it implemented, it won't run. The conditions are: ...
• 15
106 views

Techniques for NIntegrate on a 3D surface region

I'm looking for ways to speed up NIntegrate[] on a region. My application involves a humongous expression obtained from diagonalizing a 3x3 matrix (see Lattice ...
1 vote
70 views

Speed up definite integral of 1/x^(n/2)

I'm a bit buffled by how terribly slow this is: ...
• 1,441
45 views

Dot product between chosen indices for high-rank tensors

I am doing computations with multilinear maps and representing them with tensors. For example, I have an operator $O : V_1 \otimes V_2 \to W$, where $\dim(V_1) = \dim(V_2) = 5$ and $\dim(W)=3$ that I ...
32 views

Parallelization with Do and ParallelSubmit

I have quite a large expression that I need to integrate. My ansatz was to Expand the expression (easiest case results in ~5.5 million terms) and parallelize the ...
• 1,441
84 views

InternalMRealToString Gives Scientific Output From Large Inputs. How To Stop This?

The undocumented InternalMRealToString works just fine for reals up to 999999. For anything over it outputs scientific notation. I don't need scientific, I need simple decimal. ...
• 407
30 views

SmoothKernelDistribution only uses 1 core

I have a huge amount of datasets, each containing many elements, and trying to convert it to PDF using SmoothKernelDistribution. I see that applying it to 1 dataset ...
• 5,895
1 vote
103 views

Optimizing a function definition

I am using the following function to calculate A358497 as defined by OEIS: ...
• 13
1 vote
92 views

Way to run the script faster

I have a mathematica code, which is running fine, but it takes long time to evaluate.I have already modified the code with compilation and vectorization as you can see from my code. May be its a ...
302 views

Problem computing a limit

I have the following function in Mathematica: $\frac{x! \sum _{i=1}^j (-i+j+1) S_{j+1}^{(-i+j+2)} x^{-i+j+1}}{(x-j)! \left((1-x)_j\right){}^2}$ Defined as: ...
• 145
229 views

How to optimize performance with DeleteDuplicates?

Does anyone know how to improve this for speed performance? The code works fine, but DeleteDuplicates makes it really slow for large lists. ...
• 807
1 vote
435 views

Use of Compile[] to optimize the code to run faster

I am working on a code that takes long time to evaluate, So I come to know that use of Compile[] function can speed up significantly. Here is my original code. ...
• 473
68 views

How to speed up this code? (related to list manipulation)

This code is a program for generating a 2D roughness surface. There is no problem when the image size (m * n) is small (e.g., 50 * 50), but when it gets larger (e.g., 500 * 500), errors occur and the ...
• 157
58 views

Module with two conditions isn't correct

I am trying to divide a country into rectangles in order to integrate over these simpler regions. From a previous post, I am able to use quadtree to divide the country into many small rectangles, over ...
• 225
82 views

Can this loop / code be optimized to find more items in the sequence?

I am looking at the code snippet for OEIS A067075. Do[k = 1; While[Plus @@ IntegerDigits[k^3] != n^3, k++]; Print[k], {n, 1, 6}] It does okay for the first ...
• 3,410
78 views

Efficient construction of Hermitian block matrix

I need to construct large Hermitian matrices $H$, which can be built out of blocks. The matrix $H$ is of total size $Lx\times Ly$, with blocks of size $Ly$. For $Lx=5,\,Ly=3$ and $L=2$ (which is the ...
• 85
33 views

Table with preset variable is slower than table with explicit number

Why it takes ages to evaluate the second table compared to the first one? The tables are same except that first uses explicit constant 667 while the second one uses ...
• 20.3k
305 views

Approximating country by rectangles

Say I have a list of coordinates (these form the border of a country) called testpolycoords that is about 400 points long. I want to use a quadtree to divide the ...
• 225
50 views

Qualitative question: can the code matching the given patterns be made significantly faster if being written in pure C?

I made some code in Mathematica that I compiled in C. It involves operations such as looping inside While, custom random sampling from particular distributions, and ...
• 5,895
30 views

AbsArgPlot for List (Parallel Computation)

Basically, I have a very complicated function that I'd like to draw using AbsArgPlot. I thought it could speed up if I first use ...
109 views

Solving set of Gaussian integrals, integrating over an implicitly defined function that depends on the values of the integrals

I have the following NExpectations and the Implicit Function ...
39 views

Solving a system of NExpectations over an implicit function, repeated evaluations to converge to a fixed point(?)

I have the following NExpectations, ...
1 vote
194 views

Parallelization with compile gives an error

I have this uncompiled code with MMA14, win10,64 ...
• 4,709
1 vote
74 views

Dot product of every pair of rows of a matrix

I have some code to get the cosine of the angle between vectors given by every pair of rows in a large rectangular matrix, ...
• 2,195
1 vote
58 views

Replacement rule runs for a long time [duplicate]

I have a simple expression that reads (some expression in b) q^(8/3): ...
• 543
88 views

How to push the performance of this compiled function

I have the function optvals solving for two variables. For the given example of variables, I need the program to run atmost in a millisecond. The main part of the ...
• 496
1 vote
61 views

How can I efficiently gather similar lists?

I want to gather similar lists by the function sameQ below. Gather works well here, but it's too slow for large data. My real <...
• 807
1 vote
89 views

How to speed up generating and filtering large lists of numbers?

I have the following code where I brute force search for two variables. list gives a list of 3 dimensional vectors, say {x,y,z}. ...
• 496
129 views

Code for sampling and quantizing a signal running too slow

Below is the code for sampling a sine wave and quantizing it with negative feedback. It is running very slowly unless we reduce the sampling size ns. ...
• 941
117 views

Strategy to speed up two polygons (or region) intersection

Basically, I want to compare the overlap between two polygons (or regions). First, I have a reference particle ring that can form a simple polygon, but this type of ring is very thin and long, and its ...
• 71
33 views

Getting better answers by smaller working precision?

I have the following code ...
• 496
1 vote
58 views

Why is SymmetrizedArray taking so much memory?

The context is: I take the tensor product of 2 totally symmetric tensors of rank 8, in 2 dimensions(in this case there are only 9 independent components): ...
• 609
1 vote
115 views

Plotting with piecewise is slow

This drives me crazy. Why producing the first plot is so slow? It is exactly same as the second plot except that the colors are not the same. (The same slow it is with ...
• 20.3k
80 views

Can I reduce execution time of these NDSolve precision runs?

I'm working on an NDSolve project with high precision but the integration takes a lot of time and wondering if there's a quicker way to integrate the DEs ...
• 2,454
79 views

Optimization for NSolve

I am trying to solve the system of n equations numerically. Basically, I am solving saddle point equations for eigenvalues of hermitean matrices and trying to reproduce Wigner's semicircle law: ...
106 views

Fast sampling from Fermi-Dirac distribution under specific conditions

This question is a continuation of the following one. Let us assume a Fermi-Dirac (FD) distribution (times $p^{2}$): ...
• 5,895
96 views

Speeding up the nested NIntegration consisted of Exp' and Bessel' functions

I got stuck with optimizing the nested numerical integration of function with a high number of Bessel functions (first and second kinds) summed and several exponents. I will appreciate any suggestions ...
• 336
1 vote
90 views

Most efficient way of defining the following sets for every step $n$

For each $n\in\mathbb{N}$, how do we compute sets $A_n$ and $B_n$ below: Let $A_1=[0,2/3)$. Let $B_1=(2/3,1]$. If $A_n$ is a union of intervals, then for each interval cut out the middle $1/2^{n+1}$ ...
• 81
80 views

Find disjoint subsets and their union is {1...9}

I have such a list sets = Select[IntegerDigits /@ (Range[Floor@Sqrt@987654321]^2), DuplicateFreeQ@# && FreeQ[#, 0] &] I want to pick all subsets of ...
• 243
1 vote
34 views

Efficient chain rule implementation

(there is a fair amount of context here) I am implementing a generalized chain rule to do some work, say for order 3 in derivatives ($\partial_i = \partial/\partial x_i$): \begin{align} \partial_i \...
• 609
49 views

Memory-Efficient FFT of Sparse Array

I have to take the Fourier transform of quite a large 2D array (2^15 by 2^15, but I'll use 2^10 as an example here). My array is mostly zeros, and since Fourier can ...
• 239
164 views

How could I speed up this tensor product?

I have to take tensor products of lists of tensors and I want to include the possibility of tensors whose components have high working precision. The tensors are all totally symmetric, so the first ...
• 609
109 views

NonlinearModelFit extremely slow performance with a single iteration

I have been experiencing very slow performance of NonlinearModelFit. The code that in my case causes that is below. The first part gets the data, the model and ...
• 4,006
1 vote
39 views

Performing difference in extracting coefficients from a sum

I have an expression ...
• 543
1 vote
103 views

• 283
139 views

How to speed up the following algorithm?

I have some random combinations of numbers pairs (where numbers range from 1 to some ntest) ...
• 5,895
57 views

How to improve Burrows-Wheeler Transform performance?

I have implemented the Burrows-Wheeler Transform as below: ...
• 25.6k