[python-dtcwt] 148/497: remove dependency on memoized

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:05:59 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 a1aa7c1a433a61609502defed7ed1142bfd2f670
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Thu Nov 7 15:07:01 2013 +0000

    remove dependency on memoized
    
    memoized uses cPickle internally which is a Python 2-only package. Since
    memoization is a fairly simple thing to implement directly, do so.
---
 dtcwt/opencl/lowlevel.py | 20 ++++++++++++++++----
 setup.py                 |  2 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/dtcwt/opencl/lowlevel.py b/dtcwt/opencl/lowlevel.py
index 0ed155e..8b74b71 100644
--- a/dtcwt/opencl/lowlevel.py
+++ b/dtcwt/opencl/lowlevel.py
@@ -1,12 +1,24 @@
 import pyopencl as cl
 import pyopencl.array as cl_array
 import numpy as np
-from memoized import memoized
 from six.moves import xrange
 import struct
+import functools
 
 from dtcwt.lowlevel import asfarray, as_column_vector, reflect, _column_convolve
 
+# 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
+
 def colfilter(X, h):
     """Filter the columns of image *X* using filter vector *h*, without decimation.
     If len(h) is odd, each output sample is aligned with each input sample
@@ -190,7 +202,7 @@ def colifilt(X, ha, hb):
 
     return Y
 
- at memoized
+ at memoize
 def get_default_queue():
     """Return the default queue used for computation if one is not specified.
 
@@ -305,7 +317,7 @@ def axis_convolve_dfilter(X, h, axis=0, queue=None, output=None):
 
     return _apply_kernel(X, h, kern, output, axis=axis, elementstep=2, extra_kernel_args=[np.int32(flip_output),])
 
- at memoized
+ at memoize
 def _convolve_kernel_for_queue(context):
     """Return a kernel for convolution suitable for use with *context*. The
     return values are memoized.
@@ -315,7 +327,7 @@ def _convolve_kernel_for_queue(context):
     kern_prog.build()
     return kern_prog.convolve_kernel
 
- at memoized
+ at memoize
 def _dfilter_kernel_for_queue(context):
     """Return a kernel for convolution suitable for use with *context*. The
     return values are memoized.
diff --git a/setup.py b/setup.py
index ab65375..ea0809b 100644
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,7 @@ setup(
 
     setup_requires=[ 'nose>=1.0', ],
 
-    install_requires=[ 'numpy', 'six', 'memoized', ],
+    install_requires=[ 'numpy', 'six', ],
 
     extras_require={
         'docs': [ 'sphinx', 'docutils', ],

-- 
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