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
0 answers
3 views

Find first position satisfying condition, which is true after a certain element

I've made a function called Earliest I believe it is useful and there isn't built-in function like that (at present). The purpose of the post is to try out the code ...
user avatar
  • 2,825
2 votes
0 answers
30 views

Performance regression for big integer computation

Recently I noticed that the big integer calculation of the new version is much slower than the old version, can you reproduce, is there a way to speed up in the new version? ...
user avatar
  • 4,952
1 vote
1 answer
39 views

How do I construct and plot functions properly using NestList?

I am trying to construct a function using NestList and plot the values. Although the individually used and defined functions in my notebook seem to do the right ...
user avatar
5 votes
2 answers
236 views

How to speed up loading 20k lines tsv-file with complex numbers?

I have a long (20k lines) file which looks like this: ...
user avatar
6 votes
1 answer
86 views

Does converting large 3D matrices to VERY large 2D matrices affect speed of operations done on the matix?

Novice question! Does the dimensionality of a matrix affect the speed of operations performed on it (or the speed of retrieval of values from it) IF the total number of elements in the matrices are ...
user avatar
  • 185
8 votes
1 answer
101 views

Very simple, unexpected Low Performance of set(=)

...
user avatar
  • 2,825
1 vote
1 answer
55 views

How to efficiently rearrange elements in big data file? [closed]

I have this data and would like to rearrange the element in a specific way, I used Table but it tasks time 12 sec, is this ...
user avatar
4 votes
1 answer
136 views

Nonnegative Least Squares Algorithm (NNLS) [closed]

Can anyone optimize the code below which is developed in an old version of Mathematica (2003) both in terms of efficiency and adaption to the latest versions of Mathematica? Description of the code: ...
user avatar
1 vote
0 answers
31 views

Using FunctionCompile to emulate DistanceMatrix with my own DistanceFunction

I'd like to create a distance matrix with an expensive distance function. To explore how to do this for a simpler case, consider these three ways of creating a Euclidean distance matrix: Using a ...
user avatar
  • 2,160
5 votes
1 answer
98 views

Optimize cost when ordering wood boards (cutting stock problem)

That is probably a common optimization problem, but I don't know how to solve it efficiently. Say you want to buy the following wood boards: 2 to 1m, 3 of 1.5m, 2 of 2m. The shop has the following ...
user avatar
  • 13.8k
8 votes
2 answers
301 views

Simple, fast re-defining a part of 2D list

A[[{2, 3, 5}]] = {97,98,99} changes 2,3,5-th elements of A to 97,98,99 respectively. Similary A[[{2, 3, 5}]] = 100 changes 2,3,...
user avatar
  • 2,825
2 votes
0 answers
51 views

Speed up numerical evaluation of extremely large expression

I have a large 4x4 symbolic matrix whose components are scalar functions with arguments (t,r,$\theta$, $\phi$) and various parameters. The LeafCount of the purely ...
user avatar
  • 463
5 votes
1 answer
71 views

Speed up dot and cross products for a list of vectors, in a "brick wall" pattern

Yesterday I asked a question on how to speed of computation of dot and cross products for a list of vectors, for which I received a nice answer from Henrik Schumacher. Now I have a follow up question ...
user avatar
8 votes
1 answer
294 views

Speeding up cross and dot products for a list of vectors

I am working on a code where I perform dot and cross product operations on a large list of vectors multiple times. I am using MapThread to achieve this but I feel the speed of operation is not up to ...
user avatar
1 vote
0 answers
50 views

Is there a better way to Distribute after rule substitution?

Here I'm considering a problem related to rule substitution. In the simplest case, it can be shown as follows: ...
user avatar
9 votes
1 answer
108 views

Arithmetic operations on NumericArrays

Currently, NumericArrays are directly supported by the most important array-related functions, what makes them a very attractive data structure for implementing ...
user avatar
1 vote
2 answers
72 views

Timing for generating long matrix

I need a code for thermodynamics research that generates a matrix of 32768 by 32768 elements. The code is the followng: ...
user avatar
19 votes
12 answers
896 views

Partitioning a list based on a criterion for sublists

SeedRandom[1]; alist = RandomInteger[{1, 10}, 20] {2, 5, 1, 8, 1, 1, 9, 7, 1, 5, 2, 9, 6, 2, 2, 2, 4, 3, 2, 7} I would like to divide this list into sublists (...
user avatar
  • 16.2k
28 votes
6 answers
1k views

What secrets are hidden away in your init.m and where do you place it? Please help me build the ideal init.m

My init.m Feels Like it's Missing Something Although I am familiar with about a dozen or so programming languages I am only sort of, kind of, halfway competent in about three. MMA with it's boxes, ...
11 votes
1 answer
248 views

Association vs Pair - Creation performance, Selection performance

Suppose that we ...
user avatar
  • 2,825
3 votes
1 answer
157 views

How to speed up the calculation of recurrence formula?

I have a recurrence formula. How to quickly solve P[1] to p[49]? ...
user avatar
  • 301
2 votes
0 answers
74 views

sometimes Select / sometimes Position is faster

As you see, For list L, L1(Select method) is slower than L2(Position method). But for list <...
user avatar
  • 2,825
14 votes
4 answers
608 views

Monitoring Apply / @@@ over large lists

How to monitor and/or print partial progress of Apply, e.g. f @@@ list? I have found answers using Map (e.g. this nice trick using Echo, or this general trick), but ...
user avatar
  • 243
5 votes
1 answer
378 views

Fast double sum involving Kronecker symbol

I have three lists $$A=\{\alpha_1...\alpha_N\}$$ $$B=\{\beta_1...\beta_N\}$$ $$M=\{M_1....M_N\}$$ In practice $\alpha_i$ and $\beta_i$ are complex numbers with modulus smaller than 1. The $M_i$s are ...
user avatar
  • 912
8 votes
1 answer
267 views

Working around Memory Leak from HermiteDecomposition

I am running into an issue where HermiteDecomposition seems to leak memory, but only from certain matrices ...
user avatar
0 votes
1 answer
70 views

get positions satisfying multiple criteria

Given a list L. It is mathematically proven that there is no element in L matching 2 or more patterns in ...
user avatar
  • 2,825
5 votes
4 answers
212 views

Solving equation over TruncatedDistribution (FindRoot)

I'm trying to solve the following equation : ...
user avatar
0 votes
1 answer
74 views

Parallelize for loop in mathematica

I have the following code which essentially consists of a first for loop that iterates through a very large number of rows and a small for loop that iterates through a small number of columns. The ...
user avatar
  • 111
2 votes
1 answer
119 views

Speed Up the Gelman-Rubin-History function

A bit of background information I have created a function to calculate the convergence of the Gelman Rubin diagnostic (useful in Bayesian analysis). The function seems to work as I want, however I ...
user avatar
2 votes
0 answers
97 views

Nested numerical integration strategies

I have the following space time integral ...
user avatar
  • 320
5 votes
1 answer
97 views

K-Mean Clustering Algorithm

I have implemented the k-Means Clustering Algorithm using the Wolfram Language. However, I think it can be more efficient. Do you have any idea how to make it more efficient (e.g., by removing the ...
user avatar
4 votes
3 answers
195 views

Implementing fast linear search for perfect vertical image alignment

After experimenting with image alignment aprroaches presented here and here and some other approaches involving ImageDistance and ...
user avatar
1 vote
1 answer
71 views

Selecting edges for a random geometric graph in an arbitrarily shaped domain

I have some code to generate a random geometric graph in a domain of specificed shape (here an H-shape). Edges cannot exist when they intersect the domain boundary (so we need line of sight for edges ...
user avatar
  • 1,589
1 vote
1 answer
49 views

Performance tuning joinAcross (my version)

I have written what I think is a more or less complete version of JoinAcross with code below. I've done this to try to avoid the misbehavior I've observed in the ...
user avatar
  • 572
2 votes
2 answers
99 views

Efficient alternatives to a Table based iteration

I have performed some operations using the Table iterator but I am looking for efficient alternatives to my approach. First, some preliminary code: ...
user avatar
  • 187
4 votes
2 answers
186 views

Speeding up the Kuramoto model on a random graph

I am solving the Kuramoto model on a random graph $G(n,p)$, plotting the synchrony against the coupling parameter, as follows, ...
user avatar
  • 1,589
3 votes
0 answers
57 views

Parallel Evaluation Stops Evaluating Without Warning Message

This is my full code ...
user avatar
1 vote
0 answers
65 views

Find Max Instance Over Permutations

I would like to find the maximum of some objective function over all possible permutations ...
user avatar
9 votes
2 answers
369 views

Why AppendTo is much faster than Table for tracking object movement

I need to track some objects, the simplified version something like this ...
user avatar
  • 6,530
7 votes
1 answer
420 views

Tuples optimization challenge

Consider a function that for a given integer $0\le n <256$ computes the number of leading zeros in its binary representation. ...
user avatar
  • 16k
3 votes
1 answer
127 views

How to optimize ContourPlot3D evaluation?

I tried to plot a certain 3D sine function: ContourPlot3D[(Sin[x^2] + 2) * (Sin[y^2] + 2) * (Sin[z^2] + 2) , {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] but ran into an ...
user avatar
  • 333
0 votes
0 answers
76 views

Is any attempt to implement by hand built-in functions reasonable?

There are a lot of functions that are related to numerical computation of integrals, numerical solutions of algebraic/differential equations, etc. In such functions there a lot of different methods (...
user avatar
0 votes
1 answer
94 views

Help with optimization of Reduce/Solve function

I have a set of vectors in $3$D as shown below, ...
user avatar
  • 268
6 votes
1 answer
141 views

Fast integration of ElementMeshInterpolation[]-functions

In this simplified example I consider a small FEM-mesh ...
user avatar
2 votes
0 answers
47 views

Free up used Memory

When using FunctionCompile[] to generate a large matrix of ranges there seems to be no way of recovering memory even though the variables are either out of scope or overwritten. I am aware that there ...
user avatar
  • 101
1 vote
1 answer
102 views

Recursive relationship too slow

Writing: ...
user avatar
  • 4,281
2 votes
0 answers
30 views

How To Speed Up Looping TimeSeriesModelFit?

I need to apply 'TimeSeriesModelFit' to successive subsets of a long list. A small scale example of this is given here. ...
user avatar
6 votes
6 answers
325 views

Grouping consecutive elements at specified positions

Let L1={1,2,4,6,8,9,10,14,15,17,21,22,72,76,80,96,106,116,117} Question1) Group from 10-th to 14-th elements in L1. So that the ...
user avatar
  • 2,825
1 vote
1 answer
168 views

Need to find a unique mathematical expression (not in documentation) that is as short as possible but takes a good amount of time to evaluate

I am writing a public ResourceFunction and I need a good clever use case that should not appear to emulate any examples in the official documentation but will ...
user avatar
  • 1,829
0 votes
0 answers
103 views

Why is this 3D sine plot taking so much RAM?

I'm using the online version in the Wolfram Cloud. Whenever I attempt the following computation: ...
user avatar
  • 333

1
2 3 4 5
54