Is this a valid use of pure in Dask?
Lets assume that bar is never changed during the computation, but it may change while I setup the computation.
from dask import delayed
class a:
def __init__(self):
self.bar = 1
def foo(self, b):
return self.bar + b
def dask_foo(self, b):
return delayed(self.foo, pure=True)(b)
Yes, this is valid use: you are effectively asserting that the bar attribute, which is not an argument to the delayed function, will not change for any subsequent calls. When you say something is "pure", then Dask assumes that calling with argument b=5 will get the same result each time.
Notice that if you call dask_foo with the same value of b multiple times, the key of the resulting delayed object will be the same every time. If you have pure=False, you get a random UUID part to the key each time.
In this case you are obviously able to break your own assertion by changing the value of bar: don't do that!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With