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.

learn more… | top users | synonyms (2)

2
votes
0answers
41 views

Optimization of custom probability distibutions?

Consider the two tests: Timing[Do[RandomVariate[NormalDistribution[0.5, 0.3]], {200}]] {0.001188, Null} ...
0
votes
0answers
22 views

How can I find all stationary points? i.e Something like MinDetect but for saddle points (that applies to data arrays of arbitrary rank)

I would like to find all stationary points of a data set of arbitrary rank. MinDetect and MaxDetect are great for finding minima and maxima but I can't find a good way of finding the saddle points. ...
2
votes
1answer
61 views

Faster variant of Reduce for finding zeros of holomorphic functions in a region

I'm currently using Reduce to find zeros of a function in a region on a complex plane: ...
8
votes
4answers
123 views

ImageApply Performance Difference

How come the timing difference between these calls is so big? (0.2 and 39 seconds on my computer) ImageApply[q3, img] ImageApply[q3[#] &, img] Where ...
1
vote
1answer
73 views

Improving Performance - Finding Polynomial Roots [duplicate]

I'm fairly new to Mathematica. In the past, my usage has mostly been limited to solving the occasional equation, making some plots, and working with small scaled statistics. None of these have been ...
10
votes
1answer
139 views

Faster trimming of leading/trailing zeroes in rectangular array

Given a (large) rectangular array, e.g. (small for example case): ...
7
votes
2answers
139 views

why MeanFilter is nearly 100 times slower than MovingAverage for 1D array?

I used to average over my data with MeanFilter before I learn about MovingAverage and thought that these two functions are similar except that MeanFilter is more powerful for its ability to deal with ...
0
votes
0answers
96 views

How can I speed up this NM optimization? Most delay seems to be due to long analytic expression

I am struggling with computational speed of a NelderMead optimization. Nevertheless my impression is that I lose lots of speed not only due to the NM optimization itself but rather to for instance ...
7
votes
3answers
200 views

How to speed up auxilary DoolittleDecomposite function?

The Doolittle Decomposition algorithm as below: $$A=LU$$ where $A= \begin{bmatrix} a_{11} & a_{12} & \cdots a_{1n}\\ a_{21} & a_{22} & \cdots a_{2n}\\ \vdots & \vdots & \vdots ...
2
votes
1answer
81 views

speeding up creation of SparseArray

I have to create the following sparse arrays, which are reshaped in a two dimensional matrix, so that i can use the build in Dot[] function to do a kind of ...
6
votes
1answer
60 views

DatePlus and DayPlus perform much worse than my user-defined-function

I was debugging a function speed, and discovered that the time bottleneck was in DatePlus. I tried to change to DayPlus and get ...
13
votes
1answer
155 views

Unexpected slowness checking for empty list?

I thought I had a firm understanding of the differences between Equal and SameQ, but this has me puzzled: ...
3
votes
1answer
128 views

How to accelerate my code?

Given a 2D $M \times N$ matrix with non-negative values, I would like to find a path going from top to bottom such that the sum of the path is minimum. My function is defined as follow: ...
3
votes
1answer
166 views

Very slow mathematica finite differences

I have a simple code which solves an equation by an explicit method (FTCS). It takes mathematica several minutes (mathematica 10.0.2) to finish the calculation while the same code in Fortran runs less ...
1
vote
1answer
81 views

NIntegrate over a list of functions

This question is the result of these other two questions. Question 1 and 2. I thought it would be better to ask a new question rather than deleting previous one. I think When ...
23
votes
7answers
660 views

Faster position list construction from a “take instructions” list

Take some list, e.g., {1,2,3,4,5}, and a "take instructions" list, say {1,1,2,1,1}. The latter is read as "take the first ...
5
votes
1answer
148 views

Slow exponential evaluation over lists

This question,which is still unanswered, might be relevant because it involves NIntegrate over lists and it also has Exp. In ...
4
votes
1answer
52 views

How to get probabilities for multinomial & hypergeometric distribution ranges more quickly?

I often need to calculate the probability of a result from a multinomial distribution falling within some range, e.g., the maximum of the categories having an upper bound, or a lower bound for the ...
1
vote
1answer
140 views

Slow evaluation of NIntegrate when used as a pure function

I asked a perhaps related question here. Here is my code in below. The goal is that to define a function which must be integrated numerically. The function itself first is calculated over different ...
0
votes
1answer
77 views

Animating a Large Graphic Aborts, but Dynamic Works Fine

I'm trying to animate a large Graphics output, and it is returning $Aborted. I'm confused because when I use Dynamic and Slider, the graphics output is exactly what I want, i.e., I can 'animate' the ...
13
votes
1answer
173 views

Major slowdown when using a ColorFunction with more than one named scheme

Earlier Kuba noted a major slowdown with code Simon Woods posted. Here is a simplified example. First a color function using two different named gradient schemes: ...
0
votes
0answers
58 views

Improve performance of processing transactions in a large file

I want to work with a table which has 296,705 transactionslines and 172,147 transactions. ...
2
votes
3answers
105 views

Finding minimum of a list of pairs

Sometimes I need to find the Min of a list, whose elements are lists (say of two elements, a pair). Given that Min does not have the option to indicate a sorting function like Sort, I elaborated the ...
1
vote
1answer
66 views

Performance problem with summation in Mathematica

I was trying to find out why the following function is rather slow. ...
0
votes
0answers
110 views

Run out of memory. How to optimize this code?

I have two sets of data: short with 22 entries, long with 46 entries. I want to take 20 entries from ...
1
vote
1answer
48 views

Let's do this list-rearrangement prettier [duplicate]

Suppose that i have a list in this format= $list=\{ \{a,obj1 \} ,\{c,obj2 \}, \{a,obj3 \}, \{b,obj4 \} \dots\}$ I want to construct a new list in this way: $ newlist= \{ \{ \{a,obj1\} , \{a,obj3\} ...
0
votes
0answers
100 views

Is there a way to give Mathematica extra memory?

I am running Mathematica 10 (Student Edition) on Mac OS X 10.7.5 on an old Mac Pro. I have lots of extra RAM that the system isn't touching, and I would like to give some of it to Mathematica in the ...
3
votes
2answers
65 views

Slow application of `Outer` on a matrix

I have some performance issue with the calculation of a gaussian kernel applied to a not-that-large dataset. I'm not very good with performance tuning in Mma and I have the feeling this one could be ...
6
votes
0answers
98 views

Efficient image stacking

I have a list of lists of images that I would like to stack and create mean images for each list of images. Images are .jpg files 2592x1944 pixels large. Each list ...
13
votes
3answers
1k views

Can Mathematica's random number generation be improved?

Performance on Random Number generation is intolerable. Whenever you need many deviates from the same distribution but with different parameters it takes forever. Here is a thread on Poisson ...
6
votes
2answers
980 views

Dramatic speed difference of code on Matlab and Mathematica

Background: I was trying to convert a Matlab code (fluid simulation, SPH method) into a Mathematica one, but the speed difference is huge. Matlab code: ...
1
vote
1answer
55 views

Performance boost for definite integration with symbolic limits

In Mathematica, the symbolic definite integration ...
1
vote
2answers
75 views

Performance in calculating maximum-likelihood- based estimates

My probability density function is a complicated one for which numerical estimation is necessary. Here my pdf: ...
2
votes
1answer
80 views

Simple-looking Minimize takes for ever

Consider the following: Minimize[{(ξ - x)^2 + (η - y)^2, a ξ + b η == c}, {ξ, η}, Reals] After asking Mathematica to do this yesterday afternoon and forgetting ...
2
votes
2answers
61 views

What is the fastest way to get notebook CellGroups / Cells structure?

So the question is how to get this kind of information: from This is one of my ideas: ...
6
votes
2answers
167 views

Efficient Lloyd Sampling of Images

I want to sample a grayscale image so that every voronoi cell contains approximately the same total intensity using lloyd sampling. My current code is kind of slow and I was hoping for some advice to ...
5
votes
1answer
256 views

Function takes hugely different times to evaluate on sets of virtually (but also literally) identical data

I'm experiencing something which I believe to be weird with a function that I wrote. Briefly: what happens is that I generate random data to feed my function in two different but equivalent ways ...
11
votes
1answer
281 views

Does NRoots own an abstract counterpart? If not, can we write one?

We know when solving linear algebra equations, despite its abstract syntax, LinearSolve is much faster compared to Solve: ...
3
votes
3answers
257 views

fastest way to perform the following summation

I have a vector $A$ with components $A_{i}$, and two matrices $X$ and $Y$ with components $X_{ij}$, and $Y_{ij}$ respectively. What is the fastest way of performing the following summation ...
3
votes
1answer
38 views

Is it possible to generate a message when precision upgrade occur?

I use Mathematica mostly for numerical simulation, so most of the time double precision (or machine precision) is enough for me. Mathematica has this nice feature of automatically upgrade to arbitrary ...
1
vote
0answers
47 views

Complex input for Compile makes it slow

I asked a question here and then tried to use Compile for the solution to gain even more speed. Inside Compile there is a loop ...
3
votes
1answer
102 views

Making table of matrix product and efficiency

I want to make a table in which each element is a matrix product: ...
4
votes
2answers
186 views

Generate lists that satisfy a condition in an efficient way

The following code produces lists of sublists with maximum length 5 that shuffle zeros around an ordered list (here {1,2}). It produces all permutations while ...
15
votes
2answers
399 views

Why is my data 10 times slower than random data when doing matrix multiplication

I have some data generated from some program, and it appears that matrix multiplication on these data are about 10 times slower than on some random data: ...
11
votes
2answers
251 views

Choose between `Apply` and `Map`

Even though this might be too general question(or not answerable), I want to get some advice here. I apologize in advance if it is not a relevant question. I frequently have to process large list of ...
1
vote
1answer
236 views

Lookup construction using data matrix and Reap/Sow versus AppendTo`s

I am a user of MMA9 and made my own kind of Lookup, which is now a standard command in Version 10. In my program there is a section in which by means of a StringReplace[ ]-command containing a lot of ...
4
votes
1answer
94 views

Number of divisors visualized with the QPochhammer function, how improve performance of code?

I have this code that originally is Jeffrey Stopple's code for the Riemann zeta function in the complex plane. Because I discovered yesterday that the number of divisors can be generated with the ...
1
vote
0answers
72 views

Speed up replacement using Rule Dispatch Associtation

I knew that this has asked many times, but I hope there is something more could be done to speed this up. The expression kappa is here. ...
4
votes
1answer
183 views

Fast matrix multiplication in MMA and GPU

Matlab multiplies two 3000by3000 matrix around 0.18s faster than MMA. While for just a few matrix multiplications the speed difference is not important, it becomes crucial when I want to do those ...
10
votes
1answer
211 views

Max element of a list with a custom ordering function

I need a function to find max element of a list according to some custom ordering function, assuming that the function implements a total order (elements being compared might not even be numbers). ...