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.

0
votes
0answers
28 views

How can I get an array of very large primes when I don't have a lot of memory?

I would like to perform computations on an array of primes within the range $[2,10^{15}]$. For the moment, I am selecting such an array using the command: ...
2
votes
1answer
75 views

Calculating the trace of the product of several matrices

I want to calculate the trace of something like $\qquad\mathrm{Tr}(\Gamma_RG_d\Gamma_LG_d^\dagger)$ In order to optimise my code, I found something like this Faster trace of product of two matrices, ...
2
votes
0answers
26 views

Profiling - workarounds/fixes for unreliable RuntimeTools`Profile? Update added Clue

[MMA 11.0.1.0 Win 10 64-bit] I have tried using RuntimeTools`Profile manually and the most useful profile[] function provided by @Carl-Woll in this answer. Sadly, neither work reliably and the ...
3
votes
0answers
50 views

Extracting binary digits of machine precision numbers

Currently, I am developing an octree data structure. And I need it to be fast. To this end, I would like to have a fast way to extract the $m$ binary digits "after the dot" of each entry in a matrix ...
1
vote
1answer
34 views

Precalculating ThreeJSymbols to make my program faster

Does anybody have an idea what is the best way to pre-calculate the ThreeJSymbols in order to use them in a loop? (I want to make my program work faster that is why ...
0
votes
2answers
66 views

When computation takes a long time, how to find out if this is normal or if my script contains an error?

I study mechanical engineering and I' working on my first bigger project on Mathematica right now. It's a multibody problem that leads to a system of 4 large equations I'm supposed to solve ...
1
vote
1answer
35 views

Selecting from a matrix according to elements of a column — efficiency and speed?

I need to select all elements from matrix M that have in their 3rd column elements from some given list L (3rd column and L are real numbers). I have written the most obvious (to me) command to select ...
3
votes
1answer
307 views

Parallele Computing - 2 vs. 4 processor speed

I am evaluating a code which ends with Table having ParallelEvaluate of a function XXXX[phi, theta, si]. For a grid of 225 ...
5
votes
2answers
126 views

Plot geologic profile of layers

I am trying to plot a set of layers with different values of densities (density profile). Geometry ({x,z} values) of 15 interfaces of layers look like this: while ...
4
votes
1answer
70 views

Fastest, and numerically stable way to compute $CA^{-1}B$ and $CA^{-1}x$?

I have to compute $CA^{-1}B$ and $CA^{-1}x$, where $A,B,C$ are conformable matrices and $x$ is a vector. I'm not sure if it helps, but $A$ is symmetric and positive definite. The $A$ matrix will be ...
1
vote
0answers
64 views

Speed up Classify using GPU

I am interested in classify binary data using a Random Forest method. My data is numeric tensor and label of each class represented by 1.0 or 0.0. The size of the training data is ~16 million examples,...
0
votes
1answer
59 views

Speed up ParametricNDSolve

I' m trying to solve a second order ode with one parameter.However the solution is taking too much time. I tried using ...
0
votes
0answers
43 views

Rearrange a symbolic function in order that the result contains a minimum number of SQRT() and CBRT() calculations

I use mathematica for analytically calculating a function, which solves two equations: ...
9
votes
2answers
322 views

Picking mesh elements that are not on the border of the mesh

As an example, let's say I use a set of random points to create a Voronoi mesh pts = RandomReal[{-1, 1}, {100, 2}]; VoronoiMesh[pts, {-1, 1}] and get something ...
0
votes
1answer
39 views

Trapezoid rule-esque integration with unevenly spaced n-D grid

I have a function (or rather many functions) defined over an n-dimensional grid. The grid points will often but not always be evenly spaced. I want to compute integrals of these functions numerically. ...
0
votes
0answers
45 views

FindMinimum Speed [closed]

I have a code that uses the FindMinimum function with Method->"PrincipalAxis". The code works fine, but is very slow. However,...
10
votes
6answers
687 views

Fastest way to go from linear index to grid index

I'm sure this has been asked before but I'm interested in going from a position in a vector to the index in the grid version of the vector with given strides, for example, say I have the vector: <...
9
votes
0answers
88 views

Predicting Pick performance

I'm trying to figure out how to use Pick most efficiently. I use it already in a number of places, but only ever in the context of ...
4
votes
3answers
612 views

Mathematica code execution speed testing

I am testing the speed of Mathematica's latest version against a VB macro for simple loops to evaluate Pi. So the VB macro is: ...
4
votes
1answer
50 views

Cleanest way to copy part of one directory to another

I often want to copy a directory and clean it up for deployment purposes. This may involve pruning out large datasets, cleaning up private junk, etc. Doesn't really matter. The issue I often run into ...
3
votes
0answers
78 views

Profiling in Mathematica

This is meant as a broad question, because I couldn't find such a discussion on this topic (the questions I found are very old and basic, e.g. the most popular one only shows where to find Mathematica'...
1
vote
1answer
40 views

Calculation of non-overlapping set (ordering set ) of minimum spanning trees

I am interested in calculating a set of non-overlapping minimum spanning trees of a weighted graph. For example to calculate the set of size 3. I calculate the maximum spanning tree, remove its edges ...
5
votes
1answer
255 views

Huge CSV file with numeric and text data

I try to load a huge CSV file (~ 4 Gbyte), the data is both numeric and textual. So, I can't load the data as a string. ...
4
votes
1answer
111 views

Integers with a given digit sum

My aim is to generate a list of integers less than a given value $r$ with their digit sum equal to $s$. My code given below works fine but it is slow. I would like to see efficient versions. ...
5
votes
2answers
124 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
108 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
99 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
83 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: ...
12
votes
4answers
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
109 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
48 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
165 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
73 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
666 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
174 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
3answers
71 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
74 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
173 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
82 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
27 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
96 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
72 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 ...
9
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
126 views
0
votes
0answers
30 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
91 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
59 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
42 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 ...