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.
2,966
questions
5
votes
5
answers
476
views
Can I generate a "piecewise" list from a list in a fast and elegant way?
Suppose we have a number list a:
n = 1000000;
a = RandomReal[{0, 1}, {n}];
We want to generate a list ...
3
votes
0
answers
208
views
Expanding a Function in Series works, SeriesCoefficient Doesn't Work
Take the following definitions:
...
5
votes
2
answers
273
views
How to improve efficiency when classifying lists according to certain laws
I have a function that generates lists:
f[n_] := Join @@ Permutations /@ PadLeft@IntegerPartitions[n];
For example
f[3]
<...
3
votes
1
answer
2k
views
Simulated Annealing InitialPoints option
I have a cost function that depends on 4 parameters: CostFunction[{tx,ty,tz,ox}].
I used NMinimize[] function with ...
13
votes
2
answers
2k
views
Efficiently searching a list for the position of the closest number to a specified number
Searching by closest and position I wasn't able to find an answer—but found Nearest by guessing. Nearest, however, returns ...
7
votes
1
answer
524
views
MapThread Alternatives
I want to add two matrices, the first one containing a 2D vector at each position the other one a list of 2D vectors. The 2D vector from the first matrix should be added to each of the 2D vectors at ...
5
votes
1
answer
307
views
MapThread and Compile
After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of ...
11
votes
1
answer
2k
views
Imposing a Periodic Boundary Condition in Nearest Neighbour Search
I am trying to find first nearest neighbour distributions of randomly dispersed point-like objects in an infinite system. To do this I make a finite sized box unit cell with a chosen concentration of ...
5
votes
0
answers
93
views
Is there something like MaxProcessorUsed?
For standard procedures it is easy to test if the implementation is better or worse than other by using Timing etc.
It does not help us with creating ...
3
votes
0
answers
701
views
Taking real and imaginary parts of indexed functions and speeding up ComplexExpand
I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts.
I am ...
6
votes
1
answer
185
views
11
votes
2
answers
2k
views
Why is ParallelMap way slower than Map
I recently tried to use ParallelMap instead of Map and to my surprise encountered that ...
0
votes
1
answer
379
views
Better way to evaluate integral containing Boolean function
I am trying to compute the integral
...
0
votes
1
answer
244
views
How to combine two usages of # into one and speed up the code?
I have a function num with two variables, matf and matg. How can I combine the last two lines of code below into one? The code is aimed to find out the maxiaml count bel when we give each $i3 = 1,\...
4
votes
3
answers
592
views
Improve the performance of solutions to Project Euler (#14)
Problem
I have following code, when n<=10^5 it's not slow, but n>2*10^5 it's became very slow.
I think maybe some temp value greater than 2^31-1, so make compile invalid.
Could you give any idea ...
4
votes
2
answers
195
views
How to optimize computing a product?
Problem description
Write a function to caculate the formula
My solutions
Solution 1:
...
6
votes
1
answer
3k
views
Fastest way to do vector / matrix multiplication with constant matrix
Suppose we have a fixed n x n matrix, call it $B$. What is fastest way to evaluate $v^t B\;v$ over many different vectors $v$?
Since $B$ is a constant matrix, does this allow the number of operations ...
0
votes
1
answer
556
views
Efficiency problem with least square algorithm (Error in both variables)
I was informing myself about the least square algorithms with errors in x and y. I found this post and the top answer wasn't ...
5
votes
1
answer
580
views
How to speed up multi-curve plotting?
The following example is a very simplified version of the problem I'm working with, though I hope it still captures the essentials. First, the definitions:
...
3
votes
1
answer
256
views
Any way to speed up evaluation in an Animate?
I have a self-defined function which is fairly complicated and gives the analytical form. The result contains two independent variables. I use Animate to plot the ...
28
votes
5
answers
1k
views
Compiling ColorFunction for faster complex phase-amplitude plots
I have gotten into the habit of plotting complex-valued functions on a plane using a color-function along the lines of
Function[{z}, Hue[Arg[z]/(2 π), 1, Abs[z]]].
...
8
votes
1
answer
129
views
Why does Rescale performance vary significantly based on the real number values in a list?
I have a list of the form:
testList = Table[{Flatten[RandomReal[{-200, 200}, {1, 2}], 1], RandomReal[{-200, 200}, {69, 2}]}, {i, 1, 100}];
And I would like to ...
3
votes
2
answers
534
views
johansen test error in code
Cross-posted at the Wolfram community forum
I have found this code on a forum, apparently it worked in a previous version of mathematica. Now when I run it, it keeps running for ages. I am not able to ...
1
vote
1
answer
131
views
Insert glyphs into a string using functional code
I asked this question few days ago:
Replace For-loop with functional code
Suppose I use strings instead of lists; for example
a = ToString /@ {123123, 112233};`
...
6
votes
2
answers
261
views
Parallelizing or optimizing a script for calculating the size of all pairwise intersections between collections of sets
I need to speed up or parallelize an operation that looks essentially like this:
...
5
votes
2
answers
1k
views
Quickly reducing the number of decimal digits for a set of real numbers
How can I quickly convert a number with $n$ decimal points to a number of with $m$ decimal points? Round works, however, it is slower than I would like. This ...
3
votes
2
answers
451
views
Reducing quality of Graphics3D scene to improve performance?
ProteinData["SERPINA1", "MoleculePlot"] gives the detailed Graphics3D plot below. I'd like to make many small copies of this ...
6
votes
1
answer
248
views
Why LinearModelFit is slower than NonlinearModelFit?
Why LinearModelFit is slower than NonlinearModelFit?
...
9
votes
2
answers
1k
views
How to reduce the number of operations needed to evaluate an expression? [duplicate]
For some numerical calculations in C++ I have, for example, this complicated expression to evaluate. Given as Mathematica input, in its original form it is
...
5
votes
3
answers
1k
views
SparseArray row operations
Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude (...
3
votes
1
answer
856
views
Manipulate executes expressions multiple times
I am using Manipulate for a rather intricate front end for data visualization. I was getting very sluggish performance and was able to boil the problem down to a ...
8
votes
2
answers
1k
views
Faster Eigenvalues with lower precision goal
I compute all eigenvalues of a large matrix, and I decide that the speed is more important than the precision. Then the question is, can I speed up Eigenvalues[] by ...
7
votes
1
answer
2k
views
How to speed up calculations with large number of replacement rules?
In my program I have an expression which looks like:
...
6
votes
1
answer
615
views
How to avoid unpacking from Language`ExtendedFullDefinition
Consider this code:
LaunchKernels[];
On["Packing"]
a = RandomReal[{0., 1.}, {64, 30000}];
ParallelMap[Fourier, a]; // AbsoluteTiming
Developer...
11
votes
1
answer
515
views
Why I only get 2X speedup when parallelized with 16 kernels
I'm trying to parallelize a function by ParallelTable, and it seems the speedup is not very good.
I have 16 parallel kernels on my computer node:
...
21
votes
14
answers
4k
views
Pick elements of largest absolute value
For example, given
list = {{1, -3, -5}, {2, 1, 6}, {0, 2, 4}, {-9, 2, 6}}
should return:
{-5, 6, 4, -9}
Updated
I found ...
10
votes
3
answers
1k
views
How can I speed up my compiled RBF interpolating function?
Overview
I have a function that acts like the Interpolation on sparse $n$-dimensional data using a simple implementation of RBF interpolation method. I want my ...
3
votes
1
answer
381
views
Optimization of power tower fractal generator [closed]
I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list.
Here is my code :
...
21
votes
3
answers
5k
views
How can I efficiently "remap" an image?
Many image processing libraries like OpenCV, Intel Performance Primitives or Octave have a useful function called "remap", that takes an image, an array with X coordinates and an array with Y ...
8
votes
1
answer
1k
views
Why is building a table of function values so much slower than just plotting the function?
Here is a function that take some time to evaluate:
n = 1000;
coeffs = RandomVariate[NormalDistribution[], n];
f[x_] := Sum[coeffs[[k]] Sin[k x]/k, {k, 1, n}];
...
11
votes
0
answers
348
views
Improving the performance of a package for working with rational functions
As Mathematica gets slow for large symbolic calculations, the cost of putting terms over a common denominator (Together), in particular, gets too high. It occurred ...
1
vote
0
answers
895
views
Is there a way to speed up Simplify and/or PolynomialReduce Modulus-> 2?
I'm trying to simplify a series of equations with at most 64 input terms. As the number of terms involved in the equations increase, the runtime seems to grow exponentially.
Does anyone know of ways ...
4
votes
5
answers
411
views
How to generalize and speed up this program?
There is a vector whose length is $n*m$, we can part it into $n$ sections in order. I want to define a function to compare the $i$-th and $i+1$-th section and find the minimum. The program for $n=m=3$ ...
3
votes
2
answers
1k
views
How can I track the execution time of an evaluating Manipulate cell?
In Wolfram's tutorial on Advanced Manipulate Functionality, a nice example of a continually evaluating Manipulate cell is presented:
...
6
votes
2
answers
923
views
Consecutive Print to target same output Cell
Is it possible to conveniently direct the output of consecutive Print statements to the same output without actually accumulating the output in a temporary string/variable?
This would be useful in ...
3
votes
1
answer
482
views
Writing CSV or alternative
I've tried to export a list to a CSV file. I shut it down after about 20 minutes of processing. The list has 261,000 rows and 30 columns. I finally exported it to a TXT file and its size was 111 MB....
7
votes
0
answers
118
views
Does one need to be careful about loading multiple (many) contexts or packages in the same session?
I have a number of large pieces of precomputed data which I am considering putting into individual packages in order to load them (via DeclarePackage) and unload ...
16
votes
4
answers
7k
views
Simulate MATLAB's meshgrid function
Here is MATLAB's meshgrid. I came up with these implementations in Mathematica:
...
2
votes
2
answers
238
views
Time differences between code using user-defined probability distribution and code using built-in distribution
Why is the reponse time of of kernel significantly different when I use the first code rather than the second? Shouldn it not be the same? Is there any way that the response time can be made smaller ...
9
votes
1
answer
129
views
IntegerDigits has Listable attributes, but not fast
See this example, a function has Listable attributes often more efficient than Map,but why is this one is an exception?
...