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
9
votes
2answers
165 views

Looking for a Compilable Form of DeleteDuplicates

Union is Compilable but DeleteDuplicates Isn't?! First, DeleteDuplicates is not compilable ...
0
votes
0answers
65 views

Plot is fast, solve is slow - what optimizations can be made?

I'm trying to solve a 3D geometric problem in terms of 3 variables (rotational angles), and I think the end is finally in sight - quite literally, I can see on a 3D plot where my solution exists. ...
1
vote
1answer
64 views

Speed up FindRoot

I need to calculate Sv[zm,zs,zh] for a given range of zm and zs with fixed ...
4
votes
1answer
168 views

Why is a function of two functions that use memoization still slow?

I have two functions that I both use memoization for. My goal is to plot the ratio of these two functions. Since I already plot the functions by themselves, and I use memoization, it would seem to me ...
6
votes
3answers
798 views

Multiplication with zero

So I have a function $f(x) = g(x) h(x)$ that I want to evaluate on a large discrete set $\Lambda$ expressed as a list. I have that $g$ is complicated and takes time to evaluate at each point in the ...
1
vote
1answer
46 views

Is there an efficent way to rearange lists of lists where transposing the whole list is no option?

I have a list of lists of lists, listing pairs of pairings. {{{a,b},{c,d}},{{a,e},{f,g}},....} I want to apply a function to this list that gives me a 4 level list where each first level element ...
0
votes
0answers
43 views

What is the limit involving `Sum`, `Subsets`, and `RankedMax` as `t` approaches infinity? [migrated]

This question is different from the last one as I changed $d$ since different $F_t$ in my previous question gives the same $d$. Suppose we have a countably infinite $A$ and $F_1,F_2,\cdot\cdot\cdot$ ...
7
votes
4answers
346 views

AnyTrue is too good (compared to MemberQ)

Let L be a list of integers, and ⓝ denote an explicit integer. I've thought the most natural way to tell whether ⓝ belongs to L is In[1] MemberQ[L, ⓝ] But there ...
3
votes
0answers
234 views

Is there a way we can compute my sum involving `subsets` more efficiently? [migrated]

Suppose we have a countably infinite $A$ and $F_1,F_2,\cdot\cdot\cdot$ are an infinite sequence of finite sets (denoted $\left\{F_n\right\}_{n=1}^{\infty}$) such that $\bigcup\limits_{n=1}^{\infty}F_n=...
2
votes
1answer
92 views

Faster way to generate a sequence of numbers

There is a sequence of Numbers that satisfies (1) $a_1+p\geq 0, a_2+p=0, p\in R$ (2) $a_{4n}>a_{4 n-1}, (n=1,2,...)$ (3) $a_{m+n}\in\{a_m+a_n+p, a_m+a_n+p+1\}, (m,n=1,2...)$ I tried to list the ...
3
votes
1answer
289 views

Why ParallelTable is even slower than Table for large tensor construction?

I would like to create a large rank-4 tensor by using both Table and ParallelTable. What is actually constructed is given below: ...
4
votes
0answers
62 views

How to efficiently build a large sparse matrix and overloading a compiled function?

I would like to construct a large sparse matrix folding from rank-4 tensor given by the following: $\mathcal{L}_{1L}^{00}(i,j)=\mathcal{L}_{1L}^{00}(m_1,m_2;M_1,M_2)$ The indices of matrix $(i,j)$ are ...
1
vote
0answers
37 views

Faster computation process time of cashier working at different speeds

Consider the following simple problem: there is a warehouse that needs to process orders in a given order. The processing is done by the workers ('cashiers') of the warehouse, who work in shifts of ...
0
votes
0answers
112 views

Plotting a curve defined implicitly

I have defined the function functiontoplot using the following piece of code: ...
4
votes
1answer
100 views

How can I reduce the memory cost of this parallel table?

The main question I was trying to obtain the piecewise cubic-spline interpolating polynomials of a series of very long lists of (x, f(x)) pairs (O(100) of them with length ~350,000), i.e. to get ...
0
votes
0answers
35 views

Compiling using Which function is slower than without it! [duplicate]

I have a list of functions that I'd like to compile to speed up the evaluation. I'll use the list length to be n=5, but in general I'm interested in longer lists. ...
2
votes
1answer
68 views

Considerations for Compiling and Parallelizing Code Outside or Inside Map[]

Assume f as well as Map[f,list] are parallelizable and compilable, such that parallelization and compilation give significant ...
0
votes
1answer
39 views

What is the fastest way to read a constant, read-only dataset from compiled function?

I need a compiled function $f(\theta,\mathcal D)$ that uses some variables $\theta$ and some data $\mathcal D$. I will be calling the function multiple times with different values of the variables, ...
3
votes
2answers
302 views

Polygon Diameter

I want to calculate the diameter of a convex polygon. That is, the largest distance between any pair of vertices. Here's my approach ...
4
votes
2answers
72 views

Speeding up repeated calls to `ParametricNDSolve`

I am running a Markov-chain Monte Carlo sampling code. Evaluating the objective function for this case requires solving a system of ODEs for a large number (≈500) of different values of a parameter ...
3
votes
1answer
154 views

Increase computation and Plot speed

I have the following functions ...
1
vote
1answer
124 views

How to speed up a complex function involving integration and matrix inversion?

Here I have a function $I(V)$ (current with respect to voltage $V$) involving numerical integration of dummy variable $E$ for a given $V$. The whole expression of current is given by the following: $I(...
3
votes
1answer
100 views

Exporting Animation Video Using Only a Bounded Amount of Memory

The prevailing solutions seem to be: Use Export with ListAnimate (and similar solutions) which requires unrealistic amounts of ...
2
votes
1answer
120 views

Yet another slow plot involving numerical integration

Well, after reading a lot about how plotting expressions involving NIntegrate can take a lot of time, and how to overcome this issue with ...
1
vote
1answer
46 views

Problems manipulating 3d Show[] output with multiple 3d objects

My situation is as follows. I have two 3d objects, one created inside Mathematica and the second an imported STL file, that I want to superimpose and view together inside Mathematica. I want to be ...
0
votes
0answers
42 views

A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those ...
3
votes
2answers
83 views

Passing Arguments or Passing a List and Referring to its Parts – Which Gives Better Performance?

Which is better for optimizing speed, memory, and coding "safety" – passing arguments to a function or passing a list to the function and call the list's parts? That is, which of the ...
0
votes
1answer
82 views

Highly oscillatory Integral over Airy function

I have to (numerically) integrate this function over all p from to get a function g(x): ...
2
votes
1answer
52 views

Efficient way to partition a list into equivalence classes given an equivalence class function (not an equivalence relation)?

Suppose I have a list of elements and a function f which maps each element of list to an ...
0
votes
2answers
98 views

Is there any way to speed up this Mathematica evaluation?

I am interested in evaluation of the following integral ...
2
votes
1answer
87 views

Parallelization of two procedures inside Module

I am new in parallel programming and I am trying to speed up an old code using parallelization when possible. So I am (re)writing a function that computes two lists with the same dimensions (called <...
1
vote
0answers
48 views

Reduce the time-complexity of an algorithm using BellY

The code below is critical for my computation. I have to evaluate it for n around 100 and 200...
2
votes
1answer
107 views

Slow Sum with Subscripts

Edit: My original question implicated D in the problem, but it seems unrelated, so I've removed that part of the question. I am writing a function that uses ...
0
votes
0answers
59 views

Calculating my code for higher values of `k`?

How do I calculate the mean of A for higher values of k ...
4
votes
1answer
151 views

How can I speed up this Monte Carlo integration for the Stieltjes constant $\gamma_n$?

Pre-requisite Definition Stieltjes constants ($\gamma_n$) are the constants that occur in the Laurent series expansion of the Riemann zeta function. $${\displaystyle \zeta (s)={\frac {1}{s-1}}+\sum _{...
7
votes
3answers
363 views

Speed up minimization of a high-degree polynomial

For fixed $s$ and $n$, I need to find $\alpha$ which minimizes the following expression $$h (I-2\alpha H + 2\alpha^2 H + \alpha^2 \mathcal{H})^s x0$$ where $$ \begin{array}{lll} h&=&(1,\frac{1}...
3
votes
1answer
125 views

Quickly compute inverse summation

I'd like to look at behavior of $f(n)$ for the following $f$ $$\begin{array}{lll} g(s,n)&=&\frac{1}{n}\sum_i^n \left(1-\frac{1}{i}\right)^s\\ f(n)&=&\text{smallest } s \text{ such that ...
2
votes
1answer
70 views

Why does the integration of this symbolic matrix slow down after compilation?

There's a symbolic matrix as the following. Why does the integration of the symbolic matrix slow down after compilation? How to eliminate the error information in red? Thanks. Note: The sample matrix ...
4
votes
0answers
61 views

Should I worry about concurrent access to LibraryLinked code?

According to these answers, when several heterogeneous results (say {MTensor, mint, double}) are needed to be returned from a LibraryLink ...
0
votes
0answers
66 views

Simplify a heavy calculation

I'm aware that this may be regarded as too non-specific and with too little information, but I hope that someone will be able to help me nonetheless or to request information which would be imperative ...
4
votes
1answer
138 views

How to speed up the calculation process of a symbolic matrix?

There are a symbolic matrix and a real number list. I'm going to replace the symbols of the matrix with all the elements of the list, and then to get the Eigenvalues...
20
votes
2answers
929 views

How to make Mathematica read in CSV as fast as Python's Pandas

I have many big CSV files for processing in Mathematica. And each time loading them into Mathematica takes a long time. Meanwhile, it takes much less time using Pandas under Python. For example, ...
0
votes
0answers
43 views

Two-dimensional numerical integration with multi-valued function

How can I compute two dimensional integral for the function f[x,y], which is multi-valued? This function appears as follows: For a given pair ...
4
votes
1answer
128 views

Determining Mean Path Length

I'm interested in working out the average path length in a square. Assume at a single point within the square, photons are released in every direction. I'm interested in determining the average path ...
1
vote
3answers
117 views

How can I more quickly get the interchangeable variables in a function?

Let's say I have an expression like a b + c d e. This is equal to: a b + c d e, a b + c e d, ...
0
votes
1answer
59 views
0
votes
1answer
60 views

Efficient way of iterating over satisfiability instances

I am working on a problem that involves searching through solutions to a boolean equation, to see if any have a specific property. As the computations are not particularly fast, I would like to ...
3
votes
2answers
263 views

Optimize molecule distance analyzing code

I have a very large dataset (31552000 lines) of xyz coordinates in the following format 1 2 3 4 5 6 7 8 9 . . . I have to take a distance using the special ...
2
votes
1answer
198 views

How to increase the speed of Collocation method to solve System of differential equations

all. Kindly suggest me a ways to improve the speed of computations. I recently came to know about collocation methods and their application to find solution for system of differential equations. Here ...
4
votes
1answer
45 views

Why is extracting values from an Association with 1 level slower than extracting values from a list of depth 1?

I am not looking for a solution or work-around, but an explanation. Here are six examples of doing a trivial operation on an association and a list. Initially, I was curious about the cost of calling ...

1
2 3 4 5
51