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
3
votes
1answer
120 views

Find all non-isomorphic trees with $n$ nodes

I would like to compute all non-isomorphic trees with n nodes efficiently. I use the following approach: I create all possible trees ( Visualizing Cayley's Formula in Mathematica) and filter the ...
3
votes
1answer
63 views

Copy DateListPlot ticks in ListLinePlot (for large data)

It is not very surprising that plotting a PackedArray is faster to plot than a list of pairs (date, value), nonetheless the plotting time may be prohibitive with <...
1
vote
1answer
27 views

Is there a better way : solutions to integer equation

I have the following code which solves for Integers the equation $$a_1+a_2+a_3+a_4+b_1+b_2+b_3+b_4+c_1+c_2+c_3+c_4=tot$$ with $$ -4<a_i\in \mathbb{Z}<4$$ $$ -7<b_i\in \mathbb{Z}<7$$ $$ -4&...
1
vote
0answers
38 views

Problem with the return type of Compile [closed]

Can I return anything other than a real number with a compiled function ? In the example below, I use Compile on a toy function to illustrate my problem, the real ...
2
votes
1answer
71 views

Minimize Number of Boolean Formulas that Evaluate to True

I'm interested in a MinSat variant: given a list of boolean formulas like ...
3
votes
2answers
276 views

Using compile to speed up evaluation of a While loop

I want to calculate a loop. For speed, I compiled my code. Even after the compilation, it is still very slow in getting the results. Are there any further improvements that can be made to my code? <...
7
votes
1answer
150 views

Performance of select from a 3d list - Mathematica slower than Python

I am creating a random 3d data set in Matematica 12.1. Then I am selecting all points that are in a certain range of one axis. The same I am doing in Python (same computer, Python 3.8.5, numpy 1.19.2) ...
2
votes
0answers
101 views

Repeated calling of a ParametricNDSolve result in a faster way?

I recently learned of ParametricNDSolve and found that I need to compute it once and then call its result sol at different ...
2
votes
1answer
87 views

Multiply lists: element-wise but matrix-like in the last 2 levels

How can I do the following computation more efficiently? We have nested lists and want to multiply element-wise, where the 'element' is the deepest 2 levels treated like normal matrix multiplication. ...
1
vote
1answer
90 views

Fastest way to compute the solution of this equation

I am looking for the solutions to the equation : $$a_1+...+a_n =x$$ with $$ -3 \leq a_i\in \mathbb {Z} \leq 3 \ \ \ \ \ \forall i$$ $$x \in \mathbb Z$$ Mathematica will get you the solutions ...
6
votes
1answer
110 views

GroebnerBasis internals and runtime dependence on variable list ordering

I have a problem I have reduced to asking for a Gröbner basis. For some reason, Mathematica is able to solve this in minutes, while other programs more dedicated to these types of calculations run for ...
1
vote
1answer
51 views

understanding this timing result

I got two timings which I do not understand. ...
5
votes
2answers
141 views

Unexpected timing result of Total and Part performance of packed array

Define a = RandomReal[1., {2, 100, 100, 100}]; then Total[a, Infinity]; // RepeatedTiming {0.00183727, Null} and ...
1
vote
1answer
169 views

How to speed up by Compile?

I need to NDSolve a system many times by scanning some of its parameters and do some matrix calculation with the (discretized) solutions. The example is the ...
10
votes
2answers
699 views

Why is mathematica so slow when tables reach a certain length

So Here is an example: I have a table full of numbers: foo = Table[Table[RandomComplex[], {i, 1000}], {j, 8192}]; No I want to do things with some elements of this ...
3
votes
1answer
96 views

Memoization of functions with optional arguments

Consider the following function that generates a sparse diagonal matrix: ...
1
vote
1answer
53 views

Speeding Up ImageApply / Binarize?

I have a 5Kx4K image. I'm wanting to binarize it. At the moment, I have a simple binarization function, but it's taking 6 seconds or 8 seconds to binarize. ...
2
votes
4answers
153 views

How to use function `GeneratingFunction ` to solve this combinatorial problem efficiently?

Divide the 14 elements {A, B, C, C, C, C, D, D, D, D, E, E, E, E} into 7 groups (one group all have two elements), and I want to find out how many kinds of methods ...
1
vote
1answer
200 views

Program for efficient computation of given functional:

I need to plot the following functional with accuracy: $$ I(x,s) =\int_0^\infty\mathrm dy \frac{F(x + \mathrm iy,s) − F(x −\mathrm iy,s)}{\mathrm e^{2πy}-1}, $$ Where $ F(z,s) = \dfrac{1}{z^s\Gamma(\...
2
votes
2answers
110 views

Most efficient strategy for integrating over removable poles?

I am finding many situations where I have to numerically integrate some function $f(x)$ of the form: $$f(x)=f_{s}(x)-ax^{-n},$$ where $f_s$ is a special function with a finite-order pole that is ...
5
votes
1answer
77 views

Improving performace of `GeoDistance` and `NearestNeighborGraph`

I am trying to construct a NearestNeighborGraph of the 3143 US counties, using their latitude and longitude positions. ...
5
votes
4answers
421 views

How to reduce the time to solve this system of equations?

I am trying to solve the system of equations. My code ...
3
votes
2answers
124 views

Best way to write a system of conditions

Quite simply, I am wondering if there is a cleaner (and more easily altered) way to write a system of conditions for an evaluation. For instance, suppose I have something like (I don't think a real ...
0
votes
0answers
44 views

Setting up constraints in NMaximize

I have an optimization problem for which I'm using NMaximize. For the constraints I need the variables to belong to a particular set. ...
5
votes
1answer
168 views

Finding invariant matrix given group elements

I have a question about speeding up / optimising the following calculation. I have a feeling there is a way to rewrite it but I can't quite see what to do. In $d=3$ dimensions, given a set of ...
4
votes
1answer
131 views

why does wolframscript start an instance of Mathematica frontend?

The following wls file surprisingly creates an instance of Mathematica (v12.1) on OS X 10.15.7: ...
4
votes
3answers
180 views

generating lists of integers with constraint

Suppose you have the list $a=(k_1,k_2,k_3, \dots, k_N)$ such that $k_{i}\; (i=1,\ldots, N)$ are non negative integers. How can you get all the lists that satisfy the constraint $\sum_{i=1}^{N} k_{i}=M$...
1
vote
0answers
78 views

Fast definition of sparse tensor

I'm defining a sparse array through ...
2
votes
0answers
117 views

Replacing an part in a dataset

I have a nested dataset, which has been created to be the correct size from using Table, and I wish to replace parts of the dataset with the data. My dataset would look like (with placeholder values ...
0
votes
1answer
95 views

Improve running speed of FullSimplify function

How can I make this code faster? The checking with FullSimplify takes a lot of time. ...
3
votes
2answers
333 views

Speedup calculation of the largest eigenvalue and eigenvector of a 400×400 matrix? [duplicate]

Actually, the matrix is an adjacency matrix of a network. The code is: ...
4
votes
2answers
80 views

Matrix which gives the existence in a graph of a path of length $k$

In a graph $G$, for some $k$, I am looking to get a 0-1 matrix whose $ij^{\text{th}}$ entry is 1 whenever vertex $i$ has a path of length $k$ to vertex $j$ in $G$, and is otherwise zero. I have been ...
2
votes
1answer
113 views

Speeding up code doing random sampling

I have a particular probability distribution (that is a function of a parameter $\phi$), that I would like to sample from and then do a listplot for that function. Here is the code that I came up with:...
0
votes
0answers
54 views

Slow evaluation of derivative of Solution of NDSolve

I need to perform a Fourier Transform on the results of a ParametricNDSolve function as well as on the derivative of one of the coefficients. Now I do this by ...
0
votes
1answer
93 views

speed up symbolic summation

I have the following summation L=24; sind=Range[-Pi,Pi,2*Pi/L]; Sum[f, {x, sind}, {y, sind}, {x1, sind}, {y1, sind}, {x2, sind}, {y2, sind}] where ...
17
votes
3answers
585 views

Faster "Closest Pair of Points Problem" implementation?

The closest pair of points problem is a common computational geometry problem: given n points, find a pair of points with the smallest distance between them. A naive algorithm of finding distances ...
3
votes
1answer
172 views

(Non)LinearModelFit hangs on "trivial" linear fit (Fit succeeds)

A simplified version of my function and a simplified subset of my data (real data also has weights, if that matters, but I tested both with and without those): ...
8
votes
3answers
491 views

Improve running speed for DeleteDuplicates

How to make this faster? I want to remove elements that satisfy the condition below but it's way too slow. ...
0
votes
0answers
50 views

Finding if a number is perfect square [duplicate]

I used the following code to found if a specific number is a perfect square: ...
6
votes
1answer
152 views

Reducing execution time without compromising on accuracy and precision

I have the following NDSolve code, and it is extremely time consuming for me to run it, even when I set both AccuracyGoal and <...
7
votes
2answers
123 views

Can I improve performance of compiled deleteDuplicates?

I'm working on a project to compute pairs of complex numbers and need to delete the duplicates (within some tolerance, 10^-5 below). I was wondering if the performance of my compiled version can be ...
1
vote
0answers
32 views

Easiest Way To Parallelize Derivatives

What I would like to do I have a Lagrangian (a scalar). Of this function I take the derivative w.r.t. to metric-components. Of the result, I take again a derivative. The formula looks like $\partial_a\...
5
votes
1answer
169 views

Why does the Frontend slow down in long sessions?

I'm running Mathematica 12.1.1 on my Windows 10 laptop (Dell Latitude E5550 with Intel iCore 5, 8 GB RAM). My MMA sessions tend to be very long, sometimes extending on over days and weeks, interrupted ...
4
votes
2answers
389 views

Ways to speed up numerical integration

This first code block is just to create the functions I'm considering. Actual problem follows. ...
1
vote
1answer
50 views

loop execution time difference after Map operation

I am box filtering data from a DNS simulation. When filtering the original data read from a file, this is fast. When filtering a function of these data after applying Map, it is 10 times slower. If I ...
0
votes
0answers
56 views

Making animation more efficient

I created some code to create a nice animation. However, it takes a considerable amount of time to run it. I would like to make it run in the least amount of time possible. First, I load two packages ...
8
votes
2answers
268 views

Generate random lines that don't be too crowded between the intersections

It's easy to generate random lines, such as this ...
0
votes
0answers
63 views

How to evaluate the following integral faster?

I have a problem with the time required for evaluating the multi-dimensional integral and would be grateful for any help in reducing this time. First of all, there are some pre-definitions used in the ...
1
vote
0answers
38 views

Solving Kronecker-structured linear equations

I need to approximately solve the following underdetermined system of $n$ linear equations $$y_i=a_i^T X b_i$$ Where $X$ is $d\times d$ unknown matrix, $a_i$ and $b_i$ are given vectors and $n=d$. Is ...
31
votes
11answers
3k views

Plotting the Star of Bethlehem

Christmas is around the corner! In preparation, consider the polynomial f[x_,y_]:= 1/10 (4 - x^2 - 2 y^2)^2 + 1/2 (x^2 + y^2) and define $r=(f_x,f_y)$ using the ...

1
3 4
5
6 7
52