Skip to content

FAQ: How and when to use expand()?

András Retzler edited this page Oct 7, 2022 · 1 revision

What does expand() do accurately?

expand() ‘expands’ the matrix expressions (MX) graph to get the SX graph.

Why does it speed up code?

Evaluating an MX node involves internal for-loops, that adds additional overhead. MX nodes require more memory than the SX nodes, which can affect the efficiency of cache usage.

When do we use it?

As a rule-of-thumb, it is suggested to always try expand() and check if it is faster than using the MX expression. One of the cases, where SX can perform worse than the MX is when there are if-else conditions in the code. For SX expressions, both the branches of the condition are evaluated which can get very expensive when there are many nested if-else conditions.

A slide from Joris' talk

image

Examples of usage

Clone this wiki locally