FAQ: How and when to use expand()?
András Retzler edited this page Oct 7, 2022
·
1 revision
expand()
‘expands’ the matrix expressions (MX) graph to get the SX graph.
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.
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.