[python-dtcwt] 200/497: move memoize decorator to dtcwt.utils
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.
commit b3a5b494bc8136d0582f2f4c89a3a4bc6a4c9ed2
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Wed Nov 13 11:34:39 2013 +0000
move memoize decorator to dtcwt.utils
The decorator is about to be used elsewhere. It's worth moving to a
standard place.
---
dtcwt/backend/backend_opencl/lowlevel.py | 15 +--------------
dtcwt/utils.py | 13 +++++++++++++
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/dtcwt/backend/backend_opencl/lowlevel.py b/dtcwt/backend/backend_opencl/lowlevel.py
index 4004474..ec111b9 100644
--- a/dtcwt/backend/backend_opencl/lowlevel.py
+++ b/dtcwt/backend/backend_opencl/lowlevel.py
@@ -15,21 +15,8 @@ class NoCLPresentError(RuntimeError):
import numpy as np
from six.moves import xrange
import struct
-import functools
-from dtcwt.utils import asfarray, as_column_vector
-
-# note that this decorator ignores **kwargs
-# From https://wiki.python.org/moin/PythonDecoratorLibrary#Alternate_memoize_as_nested_functions
-def memoize(obj):
- cache = obj.cache = {}
-
- @functools.wraps(obj)
- def memoizer(*args, **kwargs):
- if args not in cache:
- cache[args] = obj(*args, **kwargs)
- return cache[args]
- return memoizer
+from dtcwt.utils import asfarray, as_column_vector, memoize
def empty(shape, dtype, queue=None):
return cl_array.empty(to_queue(queue), shape, dtype)
diff --git a/dtcwt/utils.py b/dtcwt/utils.py
index 137993d..dcfcd78 100644
--- a/dtcwt/utils.py
+++ b/dtcwt/utils.py
@@ -1,5 +1,6 @@
""" Useful utilities for testing the 2-D DTCWT with synthetic images"""
+import functools
import numpy as np
def drawedge(theta,r,w,N):
@@ -122,3 +123,15 @@ def reflect(x, minx, maxx):
y[t] = (2*maxx - y[t]).astype(y.dtype)
return y
+
+# note that this decorator ignores **kwargs
+# From https://wiki.python.org/moin/PythonDecoratorLibrary#Alternate_memoize_as_nested_functions
+def memoize(obj):
+ cache = obj.cache = {}
+
+ @functools.wraps(obj)
+ def memoizer(*args, **kwargs):
+ if args not in cache:
+ cache[args] = obj(*args, **kwargs)
+ return cache[args]
+ return memoizer
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git
More information about the debian-science-commits
mailing list