Implementing a system where, when it comes to the heavy mathematical lifting, I want to do as little as possible.
I'm aware that there are issues with memoisation with numpy objects, and as such implemented a lazy-key cache to avoid the whole "Premature optimisation" argument.
def magic(numpyarg,intarg):
key = str(numpyarg)+str(intarg)
try:
ret = self._cache[key]
return ret
except:
pass
... here be dragons ...
self._cache[key]=value
return value
but since string conversion takes quite a while...
t=timeit.Timer("str(a)","import numpy;a=numpy.random.rand(10,10)")
t.timeit(number=100000)/100000 = 0.00132s/call
What do people suggest as being 'the better way' to do it?