python - Checking input values to methods to reduce the number of computations -
I have several ways that are independent of each other but collectively necessary to calculate an output. Thus, when any method changes in one variable is said in the calculation of all the methods which is slow and expensive here is a quick passcode-code which I have:
# o one The original variable represents the value A # represents A variable which can convert def (O, Value A): # Return return result A def b (O, valueB): # Return return result A def c (o , ValueC1, valueC2): # Return return result A def compute (A, B, C1, C2): A = self.a (O, A) two = self. For example, when the value of C1 changes, when
all the methods ofcompute
calls,a
& amp; ; Due to no change in the value ofA, B, C1, C2
, each call of value change betweencompute
There is no way to check that has been given.I have considered defining a list of values, then on next call it is being compiled by comparing new values to
compute
for example, call 1:List = [1,2,3,4]
2 call onlist [[1,3,4,5]
henceb
& Amp ; Calculation ofc
is required buta
is similar, however, what is the uncertainty about how to compare to compare to calling?The background of my special application in case of use of my use. I have a wxPython window with sliders, which define values for image processing, and a picture is drawn on each change in these slides.
What is the best way to compare each call with
calculation
and remove these waste repeated computation?
If I have to solve this, then I will use a dictionary, where the value is valueX (or If a list is more than one, then in your example C) and the price function should be the result.
Therefore, you should have something like this:
{valueA: resultA, valueB: resultB, [valueC1, valueC2]: resultC}
To do this, you have to add it:
DIF A (O, AA): [CALS] DIC [value A] = Result returns result A [...] Diff C (O, von C1, WellC2) [CALS] DIC [[Value C1, Value C2]] = Result C returns result C
And, which calculations In that function, you can try to get the value for the values and if If the value is not received, then calculate it
DIF calculation (A, B, C1, C2): A = DIC.Ast (A) if DIC.AST (A) and SFA (O, A) two = DIC. Aetate (B) DIC Gate (B)) Other self.b (A, B) Three = DIC .get ([C1, C2]) DIC This is a "crude" implementation of the memo functions ([C1, C1]) and other Lf.c (two, C1, C2) IMG
PD: Holden Vib told in his comment.
Comments
Post a Comment