Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are class methods pure in dask?

Tags:

dask

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)
like image 796
hmaarrfk Avatar asked May 09 '26 20:05

hmaarrfk


1 Answers

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!

like image 185
mdurant Avatar answered May 11 '26 14:05

mdurant