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
15 views

Optimizing and Parallel Computing for Large Dyadic Intervals

I need help with the efficiency of my code i.e. less time so I can compute for large range of values. My function n[x] takes in a number x and outputs the ...
0
votes
0answers
26 views

Optimization of Do loop with multiple variables

I am pretty new to Mathematica and I would like to optimize a Do loop with multiple variables that I have. I have three lists of three elements each, with the condition that the first element must ...
2
votes
0answers
81 views

How to speed up the integral in NDSolve?

On the MMA.SE, there have been several question on how to solve equations including integral using NDSolve, see example 1, example 2, and example 3. Many people, ...
3
votes
1answer
58 views

Signed cell adjacency matrices (boundary operators)

In How to obtain the cell-adjacency graph of a mesh? there are some great answers that show how to obtain the cell adjacency matrix of a mesh. How would one generalize these to incorporate the ...
5
votes
2answers
641 views

How can I shorten the calculation time effectively?

I try to do a big simulation like below. (However, I do not change the sizes I want to 10 ^ 5, 10 ^ 7, 10 ^ 9.) ...
2
votes
1answer
88 views

Slow execution in Fourier analysis [on hold]

The following example executes and plots a Fourier transform of a integrable function. Can anyone suggests why the execution is so slow (about 1 min on a laptop Intel(R) Core(TM) i7-4600U CPU @ 2....
0
votes
1answer
67 views

Mathematica quits its calculations automatically

I am trying to plot the ListPlot3D but mathematica quits calculations without any warning or error. ...
8
votes
4answers
323 views

Optimising Table wrapping over a Select

Suppose we have the following lists: ...
5
votes
2answers
126 views

Adjacent faces in a discrete mesh

I have a MeshRegion R and I want to extract all pairs of adjacent faces efficiently. The way that I've been computing this is demonstrated below: ...
4
votes
3answers
443 views

Generating random numbers that keep a minimum distance

I want to create a list of n random integers from 1 to m, where all integers have to be at least a certain distance min apart (i.e. 3 integers out of Range[10], keeping a minimum distance of 2) ...
3
votes
4answers
374 views

Performance tuning : alternative to the Do loop

I wonder if anyone could help me to improve the following code. I used the Do loop, which is not recommended by MMA. What I need is the final value of 'fB' after looping over ...
17
votes
1answer
361 views

Efficiently defining a SparseArray function

I've got a fairly large SparseMatrix (~60,000 entries in a ~10,000-by-10,000 matrix) that depends on two parameters (im1 and <...
2
votes
3answers
115 views

Speeding up an intrinsically sequential operation

I am new to Mathematica and I am trying to measure its performance on a fundamentally sequential procedure. It involves a function STEP that operates on a List and returns an updated List. Therefore ...
6
votes
1answer
123 views

Speeding up tensor contractions and multiplication

Consider a tensor $T\in\mathbb{R}^{N\times N\times N\times M}$ and two vectors $x,y\in\mathbb{R}^N$. I want to compute the $N\times M$ vector defined by $X_{ij}=\operatorname{tr}(x^\top T_{:,:,i,j}y)=\...
4
votes
0answers
118 views

Speed improvements and confusion for MapThread and Dot

I have a question / confusion over improving the speed of MapThread[Dot,...] for lists of tensors. My problem involves taking two lists of tensors and then ...
3
votes
1answer
77 views

how to make my polytopes generator code more efficient?

The main purpose of my code is to generate polytopes by starting with a point. With this point, I then apply 3 actions which generates at most 3 others points: ...
0
votes
0answers
32 views

How to reduce large matrix to a multidimensional matrix?

I have a large matrix $h$ with dimension $N_x N_y\times N_x N_y $. it is related to matrix $a$ by this formula,where $i,i_1=1..N_x$ and $j,j_1=1..N_y$. ...
7
votes
1answer
72 views

SparseArray: how to efficiently extract/delete many entries?

This is a follow-up of this question. We have a large $m\!\times\!n$ matrix stored as a SparseArray a and a list of positions pos...
5
votes
1answer
275 views

Buliding a larger matrix from a smaller one

I have my matrix $h$ of size $2N\times 2N$ in this form $$h=\begin{pmatrix} a & b \\ c & d \end{pmatrix} $$ where $a,b,c,d$ are smaller matrices which i don't know. Is there any simple way to ...
4
votes
2answers
122 views

How do we optimise double Tables?

I have made the following code which I shall explain it in two parts: First Part: ...
0
votes
0answers
73 views

How to tell Mathematica to do all calculations in a notebook numerically?

I would like to tell mathematica to do all calculations numerically. I have already replaced my input by adding a dot in the end, for example : nAvg=10. But the ...
2
votes
1answer
34 views

Creating pairs of non-intersecting set from a given set

Let's say I have a set {a,b,c,d} and I want to create a list of pairs {{a,b,c,d},{}},{{a,b,c},{d}},{{a,b,c},{}},... such that there is no intersection between each pair, and they do not need to use ...
4
votes
1answer
101 views

Non-flat partitions of a set

A non-flat partition of a set is one where, when the elements of the set are on a grid, the partition does not contain subsets with elements from the same row. When the set is more irregular the same ...
18
votes
3answers
346 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(...
2
votes
2answers
42 views

Efficient ListConvolve over 3d matrix

I'm trying to find an efficient way of applying list convolve to a 3d matrix of 0 and 1, where about 5% of the matrix are 1, but the 1s may either be randomly placed, or grouped in one large ...
4
votes
2answers
213 views

Improving do loop speed with IntegerQ conditions

The following program runs rather slow when the upper bound for n gets large (~6 secs for 10^5). ...
2
votes
2answers
70 views

Vortex motion equation for flux-flow instability

I am solving the motion equation of an isolated vortex oscillation in a superconductor. I am assuming that the driving force is generated by an RF current oscillating at 1.3 GHz. The main point of ...
10
votes
3answers
524 views

Optimising subdiagonal shift matrix generation time

I want a square matrix $A$ such that $$A_{i,i-1} = 1 \ \forall i\\ A_{i,j} = 0 \text{ for } \ j \ne i-1$$ I have tried ...
1
vote
0answers
32 views

Performance issues with Packages within Packages

I am currently working on parallelizing a piece of code, as indicated in here, which explains the following, rather convoluted, way of evaluating a function; so please bare with me. But irrespective ...
9
votes
0answers
110 views

CUDADot[] takes ~3x time compared to Dot[]

It all started when specifying TargetDevice -> "GPU" in Classify[] yielded no speedup nor any activity in the GPU. Then I tried something simpler like ...
0
votes
1answer
39 views

Symbolic Resultant Too Slow/Keeps Running

Evalutation of the following cell, which includes the symbolic resultant, of two univariate polynomials in $x$, with parameters $a,b,c$ for the first polynomial (of degree 4) and parameters $d,e,f,g$ ...
4
votes
2answers
188 views

Classifier training on a large data set

I am interested in binary classification and I have a huge set of training examples (around 4 millions). Each example is a $10 \times 2$ matrix. When I run the classification after two hour run the ...
3
votes
1answer
117 views

Possible speed improvement for numerical linear algebra?

I have a question about further optimising a numerical linear algebra calculation. I've trawled through many useful posts on this site and have ended up with something quite efficient - I was ...
0
votes
0answers
63 views

How to make the following integral evaluating faster?

Consider an integral: ...
1
vote
1answer
73 views

How to compile properly for performance tuning

I have a question about how to compile functions properly for performance tuning. Currently, I am trying to solve an eigenvalue problem of a large matrix. Initially I just used the conventional ...
1
vote
1answer
73 views

How to speed up the calculation of a multi-dimension matrix involving symbolic integral?

The following program succeeds in getting matrix CC, but it takes time badly, especially in the case varNumber becomes larger just as the following ...
5
votes
1answer
570 views

How to plot the eigenvalues of a parametric matrix efficiently?

I was wondering how can I set the variable type of matrix elements to be real. The problem is, I creat a variable-dependent matrix as follows and I get the eigenvalues now I want to plot the ...
5
votes
1answer
1k views

Computing elements of a 1000 x 60 matrix exhausts RAM

I am trying to compute a 1000 x 60 matrix or list of lists (and ideally this should go up to 1000 x 500 or 1000 x 1000). Each element is the result of a FindRoot ...
8
votes
2answers
1k views

Why does a table with a defined constant in its index compute 10X slower?

I need to do some iterative summations. Here is a minimum working example: ...
1
vote
1answer
98 views

How to make these operations occur faster?

How can I get this section of the code to solve this integration faster. I have rather large values but I don't need it to be too specific. However if I lower the precision it says the integration is ...
0
votes
0answers
18 views

Any way to accelerate `SessionSubmit`?

I want to write my program in continuation-passing style, but it is too slow compared to the normal code pattern. The following expression took around 1 second to finish in 11.3. ...
2
votes
2answers
82 views

Finding extremes in discrete data by the fastest code

everybody! I'm new and that's my first post. I have such a problem: need to extract from a matrix (with dimensions n x 2) such points which have second coordinate smaller than -500 or higher than 500....
5
votes
1answer
133 views

Speed up selecting positive eigenvalues repeatedly

I have a smallish (e.g. 2x2 or 4x4, but ideally up to 10x10) non-symmetric square matrix $\mathbf{A}(x)$. I need to define a function $f(x)$ which is the sum of the eigenvalues with positive real part ...
8
votes
1answer
161 views

Most efficient method for export/import of non-traditional tensor-style dimensions of matrices/tables/lists-of-lists-of-lists(-of lists)?

Hello World! (I did it for my first answer, so it only feels proper...I'm not nostalgic, you are!) OKAY, here we go! Let's start off with the good-stuff, here's my code, made relatively arbitrary, ...
0
votes
0answers
28 views

What is the fastest way to get all the titles of emails in a folder?

I am using the function MailSearch[] to get the titles of all the relevant emails in one of my folders in Gmail. What I am currently doing works, but it takes a few ...
11
votes
1answer
675 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 ...
1
vote
1answer
49 views

How to disable symbolic preprocessing in NMinimize without performance loss?

I want to find a global minimum of a function which is defined only numerically and cannot be evaluated with symbolic arguments. For example, this could be a minimum of a compiled function. ...
8
votes
1answer
659 views

Replacement of Do loops

Here is an example code (to calculate the so called structure factor, please see the comment below the question) for a small data set of 2d coordinates. In reality I have a factor of up to 100 times ...
3
votes
3answers
90 views

Efficient manipulation of Associations passed to functions, how-to? [duplicate]

I have some data wrapped into a MyData[data_Association] "structure". My Association contains some big arrays and I do not want ...