Stack Exchange Network

Stack Exchange network consists of 175 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
36 views

FindMinimum is running too slow

For defined a function h[x_?NumericQ], I can get a plot of the function from Plot function in about seven seconds. But when I ...
8
votes
2answers
382 views

How do I remove artifacts from my ContourPlot3D Valentine?

My version (below) of the "Valentine Formula" that appeared in today's New York Times, has some ugly artifacts that don't appear in the NYT (Java) version: How do I remove these artifacts? ...
1
vote
0answers
30 views

Generic symbols vs Generic functions arguments [closed]

I've got a lot recursion relation that takes multiple hours at a time to run. I'm looking for some subtle reasons why it takes so long, and hoping to be able to reduce the time it takes for the more ...
1
vote
1answer
29 views

Improving efficency in generating Tables with large numbers of values

I'm simulating some transient data for fast Fourier transform -- on the order of 20 million points. Understandably MM takes a while to do this. Are the any techniques in table generation optimisation ...
-2
votes
0answers
55 views

speed up the code

greetings I have the problem with this lines of code: it takes more than 4 hours to compute...Since i am new with mathematica anyone more expert is able to improve the coding and speed it up? ...
2
votes
1answer
31 views

A fast way to create a list with $A_i\cdot B_i^{-1}\cdot C_i$ in each component

Let us suppose I have to do the following computation $A_i\cdot B_i^{-1}\cdot C_i$, where $A_i,B_i,C_i$ are conformable matrices(dim=$50\times 50$). For that, I have 3 lists, each of size 1 by 10,000 ...
8
votes
0answers
48 views

Performance warning using TakeList and All on big lists

According to Mathematica's own documentation, TakeList can operate with lists containing All. For example: ...
3
votes
0answers
67 views

Hopcroft's Algorithm for Minimization of Deterministic Finite State Automaton

Background Given a deterministic finite state automaton, Hopcroft's algorithm is a $O(n \log(n))$ algorithm for finding an automaton that generates the same language with a minimal number of vertices....
2
votes
1answer
48 views

Fast and Listable Piecewise function

I am writing a simulation where I have an array with ten columns and on the order of millions of rows, for which I need to iterate on the order of ten thousand times, making computation time a major ...
5
votes
0answers
69 views

Efficient Image Export [closed]

I am trying to export around 10000 plots from Mathematica in order to compile them into an animation with another program. Using the following, where "frames" is the list of plots ...
1
vote
0answers
43 views

The hyper-parameters tuning

I am looking for an automatic tool to hyperparameter tuning. Something similar to Random Search Cross Validation in Scikit-Learn. Note: I used ValidationSet options,...
2
votes
1answer
30 views

Performance Tuning: Construction of Matrix with Summations

I am trying to solve an eigenvalue problem of a large matrix. The issue is that it takes too much time to construct this large matrix. This is the code that I built: ...
0
votes
1answer
57 views

I have a working code, but work very slowly. want to improve the code

I have working code which gives the result as expected by me. But the problem is it is taking too much of time to give me those results. I have a determinant function which depends on z1,z2,z3, kt,m, ...
0
votes
0answers
46 views

How do I make this summation work faster?

Is there any way to make this summation be faster? I previously had spherical harmonics integration which was taking forever to run How can I do a faster integration? Using math, I tried to use ...
0
votes
0answers
23 views

Relative Chop for Fractions with Trigonometric Terms

I have a fraction, which contains long sums of various terms that might include trigonometric functions in both the numerator and denominator. I want to get rid of the negligible terms. This is my ...
1
vote
0answers
27 views

Does NonlinearModelFit result stores FitResiduals? [closed]

I fits a long data series with a complex model by NonlinearModelFit: fitnlm = NonlinearModelFit[...] Then I can use ...
2
votes
0answers
52 views

Another for loop question: efficiency versus readability

I have some sorted data: data = Sort[RandomInteger[{0, 15}, 10]] and I want to generate a duplicate array where a counter is ...
0
votes
0answers
37 views

Optimising the NSolve

Suppose I have the following list of rational functions, ...
7
votes
1answer
624 views

Can we turn this for loop into a more elegant Mathematica code?

I am coding stuff manipulating indirection arrays and I have some code like: ...
3
votes
0answers
92 views

How can I do a faster integration?

I have this part of my code, which takes forever to run. Does anybody know how to make it faster? Using NIntegrate I face error: "NIntegrate::eincr: The global error of the strategy GlobalAdaptive ...
6
votes
1answer
58 views

How to prevent or clear the cache used by ComponentMeasurements

Let's restart the kernel and take the first example from ref/ComponentMeasurements: Timings indicate some kind of caching mechanism. It seems useful in many cases. ...
6
votes
2answers
731 views

How to optimize Mathematica code that depends on eigenvalues of big matrices and big sums?

I've been using Mathematica recently to generate some plots of a few functions. I've been able to get it right after a few questions here. The resulting code, which works, is this: ...
2
votes
0answers
57 views

Memory leak in SmithDecomposition?

While trying to compute a large number of Smith decompositions in Mathematica 11.0 under Windows 10, my computer keeps running out of memory for no apparent reason. Here is a self-contained example ...
3
votes
1answer
48 views

Is it possible to make double tables more efficiently coded? [closed]

I am wondering about the following situation, suppose I have Table[Table[x^Length[l[[j]][[i]]], {i, Length[l[[1]]]}] // Total, {j, Length[l]}]; where ...
0
votes
0answers
33 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
81 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
32 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 ...
5
votes
1answer
83 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
39 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
86 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
36 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
332 views

Parallele Computing - 2 vs. 4 processor speed [closed]

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
135 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
74 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
68 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
75 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
47 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
332 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
42 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. ...
11
votes
6answers
705 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
621 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
51 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
88 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
42 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
264 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
112 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
127 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
109 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
104 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 ...