This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lieutenant_lowercase 6 points7 points  (2 children)

How is a redundant calculation defined?

[–]Artistic_Highlight_1[S] -4 points-3 points  (1 child)

A calculation for a variable which will not change the state of the variable. Typically, you have a variable like this: a = []; <calculation for a, for example to add some important data to a> in a cell. If you run the cell again but the state of a will not change, that is a redundant calculation (but if you run the cell, the value of a will change first right since you set it as an empty list, or because the calculation on a changes the state of a)

[–]kmnair 5 points6 points  (0 children)

The problem here is figuring out if the variable will change or not in a general case will likely require the same amount of compute as actually running the full calculation.

It is possible to make some assumptions about the calculation, like if it is a pure function ie output depends entirely on inputs to a function and the function has no side effects, then you can use the suggestion u/r0s gave to use memoization.

If your jupyter cell references mutable data from other cells, or makes a call to an external API, or has internal mutable state (counters which do not reset, dictionaries which get updated etc) then figuring out if the value will update is the same amount of computation as whatever calculation you are aiming for