Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
2answers
101 views

Fast element-wise division of matrix, generated from vector with `Outer`, and another matrix

m = {a, b, c}; n = {{e, r, t}, {y, u, i}, {g, h, j}}; k = Outer[Divide, m, m]; k/n gives ...
3
votes
3answers
98 views

Fast application of InterpolatingFunction over transformed coordinates

I have an InterpolatingFunction that takes $(x, y)$ coordinates as input and I would like to apply it to a series of data that is rotated by $\frac{\pi}{4}$ into $(\...
3
votes
1answer
93 views

Speedup of DimensionReduce

I am interested in accelerating DimensionReduce using the "TSNE" method. I have a matrix with a size of 30000 * 10, and I want to reduce to 30000 * 8. But the calculation is very slow, any suggestions ...
1
vote
3answers
67 views

Most efficient way to replace/ update the values multiple rows and columns of a Dataset

Suppose we wish to replace the cols "b" and "c" of rows 3 to 5 in the following dataset to b and c respectively: ...
11
votes
3answers
2k views

Can this be solved even faster?

So I would like to solve the following set of equation for $m_i$ given a set of ${M_m,N_m}$. $$ m_1 +m_2 +m_3 +m_4 =M_m \\ |m_1| +|m_2| +|m_3| +|m_4| =N_m $$ All variables are integers. Also $N_m \...
3
votes
3answers
100 views

Efficient function for life duration probability?

Sent to me by a colleague asking me for assistance (the function as is breaks): ...
0
votes
1answer
46 views

Trying to obtain a numeric solution to an inequality. Code might be not working as intended

I need to check whether an inequality can have solutions in the real numbers, given some extra constraints on the variables. I suspect that no solutions exist but I would like some verification of ...
11
votes
1answer
145 views

Profiling a package

I have some code that I want to profile to see how much time each step takes, for instance: ...
0
votes
0answers
40 views

Solution list from “Solve” too large for my RAM space

I was trying to evaluate a sum of the form $$\sum_{\{x_1,x_2,\ldots,x_{n}\}}f(x_1,x_2,\ldots,x_{n}),$$ where $\{x_1,x_2,\ldots,x_{n}\}$ are solutions of a system of linear equations and inequalities ...
4
votes
1answer
69 views

Reading total number of frames in an AVI

I am reading large AVI files and want to know the number of stored frames. To do that in Mathematica 11.3 I use the following: ...
13
votes
2answers
648 views

Delete with multiple indices is extremely slow--workaround?

Delete is unbelievably slow when deleting multiple elements from a non-packed array. Is there a robust workaround that will work on any non-packed array? ...
3
votes
3answers
164 views

Improving performance of algorithm to compute Code puzzles

I hope to explore Mathematica by using it for Advent of Code puzzles this year, so spoiler alert for anyone interested in solving https://adventofcode.com/2018/day/1 for themselves. Part 2 of ...
0
votes
1answer
45 views

Can `PlotRange` of x-axis automattically determine y range?

PlotRange can specify the plotting range in each direction. Let's say you have a large set of data and you may want to plot parts of it by specifying the ...
1
vote
1answer
71 views

Is there any way to save time using of “Cross” or “Table”?

I need to solve a equation by NDSlove, so I write the equation first, but it takes me a lot of time. The follow is my code ...
6
votes
1answer
142 views

Fast export of png images from large avi file with Mathematica 11.3

In version 11.1.1 I used MathMF by Simon Woods to extract png images from large avi files (up to 100GB in size). His package was MUCH faster than using something like that: ...
0
votes
3answers
80 views

Check if number is in list

I have a nested list, but don't know how long the individual lists are. Sometimes they may be 2 numbers long sometimes 1000, so i need to check if theres is a number at position 6 but i doesn't ...
0
votes
1answer
17 views

How can I specify the region for every variable simultaneously in NMinimize?

I want to use NMinimize to find the unknown unitary matrix that solves a (possibly nonlinear) matrix equation. For example, the one that transforms the Pauli matrix ...
4
votes
2answers
85 views

OpenCL compute large matrices

I am trying to compute a big matrix $C$, of size $M \times N$, using the elements of the input matrices $A$ and $B$. The matrix $A$ is of size $M\times4$ and the matrix $B$ is of the size $2\times N$. ...
1
vote
2answers
67 views

Quick cursoring and replacement over a list

I have an initial list which is partitioned as follows. ...
2
votes
0answers
35 views

Fold/ NestList/ etc in MCMC loop for optimisation

I am trying to simplify and optimise an old loop code I wrote. Since Fold and NestWhile use the results of the last iteration in the new iteration, I would like to use them in order to get rid of Do ...
8
votes
3answers
1k views

Speed up code to numerically simulate a game of coin tossing

Description I would like to simulate n games in which two players toss one coin each at the same time: If you toss a tail you will receive two tokens, if you toss ...
2
votes
2answers
119 views
0
votes
0answers
29 views

Recursive function call in Fold: $RecursionLimit issue

I'm trying to generate a list of all local complements of a graph $G$. A local graph complement $G\star v$ for $v\in V$ is defined as taking the neighbourhood of the vertex $v$, and flipping the ...
5
votes
2answers
86 views

Set notebook sections one level up

Suppose I have a notebook filled with many chapters, sections, subsections, subsubsections and so on. Instead of changing the style of each of them manually, is there a clever way to set all or part ...
4
votes
1answer
58 views

Can this multinomial probability query performance be improved?

I'd like to get the probability that some N samples of M equiprobable events does not have any case of the M possible individual outcomes having more than some maximum value. The code I'm using on ...
0
votes
0answers
40 views

Uniform distribution on the manifold: There exist a build-in solution?

In general, the problem is to generate many random points on the (high-dimensional, compact, smooth) manifold ~~ uniform distribution w.r.t. lebesgue measure. So, this is a common in the Monte-Carlo ...
5
votes
0answers
51 views

How to prevent the message: Not enough memory to display a cell

While running a single-cell GUI application that repeatedly changes and refreshes its content I got this message: There was not enough memory to display a cell... I found in this old MathGroup thread ...
0
votes
2answers
113 views

How to efficiently evaluate Exp[I m θ] [closed]

The I is imaginary number. My question is when m becomes large and the number of θ increases, how to evaluate it faster. Here is one way to get the result and store all the value it found. ...
3
votes
2answers
83 views

Improving FindInstance efficiency

I am relatively new to Mathematica and my function has been running for over a month now. I am beginning to think I may never get a solution or that there is a mistake in the code, which means a ...
0
votes
0answers
69 views

Speed up execution of this function

I would like to speed up this following function: ...
2
votes
0answers
47 views

How to construct a time-dependent matrix quickly?

In the process of discretization of a 4D PDE, I need to construct a final sparse matrix $B$, which is very large (I denoted by $\text{size}$ here) and time-dependent, viz, some of its entries change ...
19
votes
4answers
885 views

How to construct a list of lengths efficiently

Say I have a sorted list of integers RandomInteger[{1, 100000}, 10000] // Sort // Short I want to construct another list whose $m$-th element is the number of ...
7
votes
2answers
244 views

Take upper triangular part of matrix

I would like to extract the upper triangular part of a square matrix into a flat list. I am looking for fast ways to do this. I am primarily interested in solutions that are fast for non-packed ...
1
vote
1answer
34 views

Plot number of overexposed pixels per column in grey scale image

I have a grey scale image (1600*480 pixels, 8 bit): https://i.imgur.com/BqgJRv7.png (update) I want to determine the number of overexposed pixels in each column. Then I want to plot the a combined ...
8
votes
1answer
420 views

Is there a faster way to vectorize a matrix than this?

I want to put all the columns stacked up, as a vector. The fastest code I could come up with was Transpose[{Flatten[Transpose[A]]}] Is there a faster way?
2
votes
1answer
33 views

Reformatting the pattern inside a list

So, in principle, I have a simple problem which goes like this: I have vectors that should consist of lists of 2 numbers, see here: ...
0
votes
2answers
39 views

Evaluation control - Hold (?) argument name not argument values

I wanted to produce a list of statistics labelled with the statistic name, for exchange with a database. I defined ...
3
votes
2answers
89 views

Programming with Mathematica Syntax - Dunford decomposition

I am always amazed while I am reading some solutions of problems in mathematical problems of this site with Mathematica. For instance, look at the problem 48. Whereas I am writing 100 lines of code ...
4
votes
2answers
130 views

Performance-tuning a simple 2D Table construct

I've recently been playing with some performance tuning over a seemingly simple construction where I build a 2D array of Sin[x*y] for ...
4
votes
2answers
82 views

speedy update of list of associations

Suppose as is a list of associations that I want to update. For example: ...
7
votes
2answers
423 views

Can we make a faster Boole implementation?

I just learned about Mr. Wizard's very efficient code here. ...
0
votes
0answers
54 views

Solving a real polynomial system takes forever, am I asking the impossible?

I want to find all stationary points of a particular 3 dimensional polynomial function. Sounds easy enough, right? Just get the gradient with Grad[], and solve the ...
8
votes
2answers
450 views

Ways to speed up Pick

I have a few large arrays (100 times larger than in the example) and I need to re-arrange them. Basically using tests on b and c...
8
votes
2answers
108 views

Robust DuplicateFreeQ for numerical data

I am looking for a fast and robust DuplicateFreeQ equivalent for numerical data. Floating point numbers should normally be compared with some tolerance, as ...
1
vote
3answers
95 views

Find k largest edges with unique nodes (kind of maximum weighted matching)

I have a weighted graph, and I am interested to find k largest edges with unique nodes. Currently, I do it in the following manner ...
12
votes
2answers
251 views

Speed up Flatten[] of a large nested list

I have a large jagged list, that is each sub-list has a different length. I would like to Flatten this list for Histogram ...
5
votes
2answers
73 views

Looking up one additional array element increases runtime by three orders of magnitude

The Problem I have a list myList, which is a 487135 x 3 x 2 array of integers between -1000 and 1000. I want to be able to ...
5
votes
4answers
71 views

Non vector graphics display in a notebook

When I generate multiple scatter plots with a large number of points and display them as output, the notebook becomes very sluggish (I assume that this is because each plot has a huge number of points ...
23
votes
1answer
280 views

Which second arguments is VectorQ/MatrixQ/ArrayQ optimized for?

VectorQ and similar functions (MatrixQ, ArrayQ) treat certain second arguments specially. ...