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 (4)

12
votes
2answers
147 views

How to count the number of the tube

There is a picture Get the binary image binimg = ColorSeparate[img][[2]] // Binarize[#, 0.25] & // Thinning Visulize the result of regconization ...
0
votes
0answers
82 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. ...
7
votes
1answer
292 views

A more perfect Union[]

I was doing a Project Euler problem with my class, and found the following weird fact: Union[] of a list of some 50 million numbers (of which only around 15000 were ...
4
votes
1answer
75 views

Is it possible to recover the efficiency of ListConvolve when generalizing the convolution?

I've noticed that, while ListConvolve is very fast, it becomes much slower when you use anything but the standard Times,Plus as ...
4
votes
1answer
132 views

How to efficiently find all combinations of the letters in an alphabet given a condition

Problem: I want to find all unique expressions with n number of terms that contain all the digits (or characters) in alphabet. ...
1
vote
1answer
84 views

How to improve speed of the following code

The following code do what I needed, but it takes too long ...
0
votes
0answers
55 views

Is this problem parametrically solvable or it can just be solved for specific $\sigma$ and $\theta$?

In order to solve This problem: What is the maximum value of coefficient fv with the constraint that the matrix is positive semi-definite?, I have used the following code (Determinant is computed by ...
0
votes
0answers
79 views
3
votes
1answer
116 views

Efficiently generating tuples with Outer

I'm trying to efficiently generate tuples of lists of objects that satisfy a given criterion. The similar questions that I have found on this website end up finding a specific workaround for the given ...
18
votes
5answers
446 views

Partitioning a list when the cumulative sum exceeds 1

I have a long list of say 1 million Uniform(0,1) random numbers, such as: dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65} I want to ...
7
votes
1answer
143 views

Why is Random faster than RandomReal?

As of version 6, Random[] was superseded by RandomReal[ ] etc, but both still work perfectly well. Playing with some timing ...
36
votes
9answers
2k views

What would you ask Mathematica to do on a big system?

Our hardware supplier has given us the opportunity to test Mathematica on a big Windows system. The specs will be 1 to 4 TB of working memory and 12 sockets with 18 cores each. I got 1 full week of ...
1
vote
1answer
140 views

Only perform a symbolic differentiation once

I want to define a function that involves a differentiation step that Mathematica can do easily, which might be of the form ...
6
votes
0answers
89 views

What are the time and space complexities of Classify/Predict?

Does anyone have knowledge of the O(n) time & space complexities for various model types supported by Classify[] and ...
-2
votes
1answer
62 views

Manipulate aborts the computation of NDSolve with the Piecewise function after curtain time [closed]

I'm facing the problem with performance: Manipulate is working fine till end time =60 sec, after that it aborts. There is NDSolve inside Manipulate with Piecewise function, and the plot of the ...
14
votes
3answers
427 views

Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
3
votes
0answers
52 views

NelderMeadMinimize for 2D Gaussian fitting

I would like to fit a large number (10^5-10^6) of small images to 2D gaussians by taking advantage of the NelderMeadMinimize package from Oleksandr: Shaving the last 50 ms off NMinimize. The ...
0
votes
1answer
42 views

Slow sum computation

I'm doing a simple OLS regression and I strikes my attention that this very simple computation takes several seconds to perform in Mathematica ...
3
votes
1answer
62 views
4
votes
2answers
86 views
0
votes
1answer
72 views

Computing the coefficients for Gaussian integral

I wrote a small script to find the Gaussian integral points and weights: ...
9
votes
3answers
384 views

Generalization to AllTrue, AnyTrue and NoneTrue

I am wondering if there is a natural Mathematica way to generalize those functions. To be specific, All three functions AllTrue, ...
3
votes
2answers
110 views

Implementation of a matrix formula

For the Bezier surface, which owns the following matrix definition: where, $B_{n,i}$ denotes Bernstein-basis. ...
1
vote
0answers
51 views

Solving a polynomial equation with an approximate constraint is slower than the symbolic solution

Why do these two operations have such different timing, when the only difference is specifying r as approximate $0.1$ vs arbitrary-precision $1/10$? Here are the ...
0
votes
0answers
55 views

Solving a transcendental equation wth a power series term [closed]

I have the following code for a transcendental equation that i am trying to solve for E2 using the Erzek Root Finder. However, there is a slight complication owning to the presence of an infinite ...
3
votes
1answer
43 views

Replacing elements of a matrix

I'm trying to write a program that takes a given matrix $A$ of 1's and 0's and flips a designated amount of 1's to -1's. ...
5
votes
1answer
145 views

Fast loading of png files

I need to process through 600 images that are stored as png-files. Each file has 8.3-ish Mb and 2400x2400 pixel (Real32). For a single processor it takes 0.93sec per image to be loaded with Import ...
6
votes
1answer
117 views

Finding mean brightness, standard deviation, count of pixels in gray scale images

I have many sequential gray scale images (2048*2048 pixels, 8bit). To determine the brightness, standard deviation, and count of pixels with in two bins, zero and non-zero brightness, I use the code ...
15
votes
5answers
614 views

Easiest/most efficient way to delete duplicates from one list at the positions of another?

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the ...
3
votes
0answers
38 views
15
votes
3answers
403 views

Highlighting pattern strings in a large text

I would like to apply Style to strings that are matched, for example, with one or more specified patterns or regular expressions, a string or a list of both, ...
3
votes
3answers
287 views

Mandelbrot set—efficiently iterate over a list of initial points

OP edit: This is a Mathematica-specific question about an approach it attempted for a fractal visualization problem described HERE. I'm using the Mandelbrot set there and here as an example, but the ...
0
votes
1answer
107 views

Histograms of gray scale images

I have a large set of subsequent 8bit gray scale png images (50 Hz). They show the noise of a CMOS camera, with the lens covered. A subset of 50 images is available here: https://goo.gl/Sa3P9P I ...
1
vote
1answer
89 views

Manipulating Some Lists in Compile

Consider a list of lists, such as: Z={{1,4,3},{2,1,3},{3,1,4}} Z is an $n \times n$ matrix (here $3 \times 3$) which ...
1
vote
1answer
89 views

How to do this Function with compile

There is 4 lists, 3 of them are at same length (l0, l1 and l3). ...
3
votes
1answer
138 views

How to speed up filling a matrix as much as possible in a loop?

In order to find the solution of an $n\times n$ system of nonlinear equations by the method $x_{k+1}=x_k-D_k^{-1}f(x_k)$ where $D_k$ is an approximation of the Jacobian and defined by ...
11
votes
1answer
243 views

Why does Outer sometimes return a packed array, and sometimes not?

For example In[342]:= test3 = Flatten[Outer[Plus, Range[1000], Range[1000]], 1]; // AbsoluteTiming Out[342]= {0.0198735, Null} returns PackedArray ...
2
votes
1answer
85 views

Product of $N\ 2 \times 2$ matrices and subsequently solving an equation dependent on the product

I have $N\ 2 \times 2$ matrices, each one containing one variable energy which may be complex. I want to muliply them all together to a single matrix ...
32
votes
3answers
813 views

Parallelize evaluation of function with memoization

I have a complicated function that I need multiple times, so I want to memoize it and have the first evaluation done in parallel. Unlike in my example below it's not a continuous function, so ...
14
votes
1answer
248 views

Why is SatisfiabilityCount faster than SatisfiableQ?

Consider the following (large) Boolean expression, which arose in a SAT problem. (The expression is not satisfiable.) ...
1
vote
1answer
23 views

Coefficient of function with general argument

I would like to obtain the coefficients of a general function f in a list. For example, the coefficient list of ...
6
votes
3answers
240 views

How to get “Signature” of each element of “Permutation” output

I need to sum over all possible permutations, multiplied by the Signature of each permutation of a given list of symbols. But, I don't know how to determine the ...
10
votes
2answers
278 views

How to “inform” successive ContourPlot calculations?

I need to draw some contour plots of very non-linear functions. As a simple example, take a Mandelbrot Set divergence contour near $z\approx i$. (Just to be clear, I'm not trying to write a ...
2
votes
0answers
89 views

Fast construction and reshaping of large tensors

I'm trying to construct a large matrix which is derived from some higher rank tensor (the rank of interest to me changes case by case, so it needs to be a general method). Currently, the process of ...
0
votes
1answer
53 views

Timing and memory use is critical:fast partitioning of binary sparse array

I do experiments were I measure a signal, and I need to know at what time points it is above a threshold. If at a given time point, the signal is above the threshold, then a '1' gets put into the ...
5
votes
5answers
120 views

How to find the derivative value at $(\pi,0)$ for this implcit function $n$ times?

I am trying to take the implicit derivative at $\sin(x+y)+\sin(x)=y$ and substitute $x=\pi$ and $y=0$ at least 6-7 times since I need to find the Taylor series for this function. Since I barely ...