[python-dtcwt] 203/497: re-name backend classes consistently

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 59f7b133f15eb454c30e319dd884ddd3b175aa7b
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Wed Nov 13 14:10:30 2013 +0000

    re-name backend classes consistently
    
    There is no need to call the NumPy flavour of Transform2d
    Transform2dNumPy. The module stops namespace collision.
---
 dtcwt/backend/__init__.py                   | 95 -----------------------------
 dtcwt/backend/backend_numpy/__init__.py     |  7 +++
 dtcwt/backend/backend_numpy/transform2d.py  |  7 +--
 dtcwt/backend/backend_opencl/__init__.py    |  7 +++
 dtcwt/backend/backend_opencl/transform2d.py | 20 +++---
 dtcwt/backend/{__init__.py => base.py}      |  1 +
 dtcwt/transform2d.py                        |  8 +--
 7 files changed, 31 insertions(+), 114 deletions(-)

diff --git a/dtcwt/backend/__init__.py b/dtcwt/backend/__init__.py
index e37883c..e69de29 100644
--- a/dtcwt/backend/__init__.py
+++ b/dtcwt/backend/__init__.py
@@ -1,95 +0,0 @@
-from dtcwt.utils import asfarray
-from dtcwt.defaults import DEFAULT_BIORT, DEFAULT_QSHIFT
-
-class TransformDomainSignal(object):
-    """A representation of a transform domain signal.
-
-    Backends are free to implement any class which respects this interface for
-    storing transform-domain signals. The inverse transform may accept a
-    backend-specific version of this class but should always accept any class
-    which corresponds to this interface.
-
-    .. py:attribute:: lowpass
-        
-        A NumPy-compatible array containing the coarsest scale lowpass signal.
-
-    .. py:attribute:: subbands
-        
-        A tuple where each element is the complex subband coefficients for
-        corresponding scales finest to coarsest.
-
-    .. py:attribute:: scales
-        
-        *(optional)* A tuple where each element is a NumPy-compatible array
-        containing the lowpass signal for corresponding scales finest to
-        coarsest. This is not required for the inverse and may be *None*.
-
-    """
-    def __init__(self, lowpass, subbands, scales=None):
-        self.lowpass = asfarray(lowpass)
-        self.subbands = tuple(asfarray(x) for x in subbands)
-        self.scales = tuple(asfarray(x) for x in scales) if scales is not None else None
-
-class ReconstructedSignal(object):
-    """
-    A representation of the reconstructed signal from the inverse transform. A
-    backend is free to implement their own version of this class providing it
-    corresponds to the interface documented.
-
-    .. py:attribute:: value
-
-        A NumPy-compatible array containing the reconstructed signal.
-
-    """
-    def __init__(self, value):
-        self.value = asfarray(value)
-
-class Transform2d(object):
-    """
-    An implementation of a 2D DT-CWT transformation. Backends must provide a
-    transform class which provides an interface compatible with this base
-    class.
-
-    :param biort: Level 1 wavelets to use. See :py:func:`biort`.
-    :param qshift: Level >= 2 wavelets to use. See :py:func:`qshift`.
-
-    If *biort* or *qshift* are strings, they are used as an argument to the
-    :py:func:`biort` or :py:func:`qshift` functions. Otherwise, they are
-    interpreted as tuples of vectors giving filter coefficients. In the *biort*
-    case, this should be (h0o, g0o, h1o, g1o). In the *qshift* case, this should
-    be (h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b).
-
-    In some cases the tuples may have more elements. This is used to represent
-    the :ref:`rot-symm-wavelets`.
-    
-    """
-    def __init__(self, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT):
-        raise NotImplementedError()
-
-    def forward(self, X, nlevels=3, include_scale=False):
-        """Perform a *n*-level DTCWT-2D decompostion on a 2D matrix *X*.
-
-        :param X: 2D real array
-        :param nlevels: Number of levels of wavelet decomposition
-
-        :returns: A :py:class:`dtcwt.backend.TransformDomainSignal` compatible object representing the transform-domain signal
-
-        """
-        raise NotImplementedError()
-
-    def inverse(self, td_signal, gain_mask=None):
-        """Perform an *n*-level dual-tree complex wavelet (DTCWT) 2D
-        reconstruction.
-
-        :param td_signal: A :py:class:`dtcwt.backend.TransformDomainSignal`-like class holding the transform domain representation to invert.
-        :param gain_mask: Gain to be applied to each subband.
-
-        :returns: A :py:class:`dtcwt.backend.ReconstructedSignal` compatible instance with the reconstruction.
-
-        The (*d*, *l*)-th element of *gain_mask* is gain for subband with direction
-        *d* at level *l*. If gain_mask[d,l] == 0, no computation is performed for
-        band (d,l). Default *gain_mask* is all ones. Note that both *d* and *l* are
-        zero-indexed.
-
-        """
-        raise NotImplementedError()
diff --git a/dtcwt/backend/backend_numpy/__init__.py b/dtcwt/backend/backend_numpy/__init__.py
index 4914aa4..77691d4 100644
--- a/dtcwt/backend/backend_numpy/__init__.py
+++ b/dtcwt/backend/backend_numpy/__init__.py
@@ -3,3 +3,10 @@ A backend which uses NumPy to perform the filtering. This backend should always
 be available.
 
 """
+
+from .transform2d import TransformDomainSignal, Transform2d
+
+__all__ = [
+    'TransformDomainSignal',
+    'Transform2d',
+]
diff --git a/dtcwt/backend/backend_numpy/transform2d.py b/dtcwt/backend/backend_numpy/transform2d.py
index ff99beb..4b821c4 100644
--- a/dtcwt/backend/backend_numpy/transform2d.py
+++ b/dtcwt/backend/backend_numpy/transform2d.py
@@ -3,20 +3,17 @@ import logging
 
 from six.moves import xrange
 
-__all__ = ['Transform2dNumPy',]
-
-from dtcwt.backend import TransformDomainSignal, ReconstructedSignal
+from dtcwt.backend.base import TransformDomainSignal, ReconstructedSignal, Transform2d as Transform2dBase
 from dtcwt.coeffs import biort as _biort, qshift as _qshift
 from dtcwt.defaults import DEFAULT_BIORT, DEFAULT_QSHIFT
 from dtcwt.utils import appropriate_complex_type_for, asfarray
 
-from dtcwt.backend import Transform2d
 from dtcwt.backend.backend_numpy.lowlevel import LowLevelBackendNumPy
 
 # Use the NumPy low-level backend
 _BACKEND = LowLevelBackendNumPy()
 
-class Transform2dNumPy(Transform2d):
+class Transform2d(Transform2dBase):
     """
     An implementation of the 2D DT-CWT via NumPy. *biort* and *qshift* are the
     wavelets which parameterise the transform. Valid values are documented in
diff --git a/dtcwt/backend/backend_opencl/__init__.py b/dtcwt/backend/backend_opencl/__init__.py
index 7d7ac2d..3622819 100644
--- a/dtcwt/backend/backend_opencl/__init__.py
+++ b/dtcwt/backend/backend_opencl/__init__.py
@@ -3,3 +3,10 @@ Provide low-level OpenCL accelerated operations. This backend requires that
 PyOpenCL be installed.
 
 """
+
+from .transform2d import TransformDomainSignal, Transform2d
+
+__all__ = [
+    'TransformDomainSignal',
+    'Transform2d',
+]
diff --git a/dtcwt/backend/backend_opencl/transform2d.py b/dtcwt/backend/backend_opencl/transform2d.py
index 9be3f9c..ee674d2 100644
--- a/dtcwt/backend/backend_opencl/transform2d.py
+++ b/dtcwt/backend/backend_opencl/transform2d.py
@@ -11,8 +11,8 @@ from dtcwt.backend.backend_opencl.lowlevel import colfilter, coldfilt, colifilt
 from dtcwt.backend.backend_opencl.lowlevel import axis_convolve, axis_convolve_dfilter, q2c
 from dtcwt.backend.backend_opencl.lowlevel import to_device, to_queue, to_array, empty
 
-from dtcwt.backend import TransformDomainSignal, ReconstructedSignal
-from dtcwt.backend.backend_numpy.transform2d import Transform2dNumPy
+from dtcwt.backend.base import TransformDomainSignal, ReconstructedSignal
+from dtcwt.backend.backend_numpy import Transform2d as Transform2dNumPy
 
 try:
     from pyopencl.array import concatenate, Array as CLArray
@@ -21,14 +21,14 @@ except ImportError:
     pass
 
 def dtwavexfm2(X, nlevels=3, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT, include_scale=False, queue=None):
-    t = Transform2dOpenCL(biort=biort, qshift=qshift, queue=queue)
+    t = Transform2d(biort=biort, qshift=qshift, queue=queue)
     r = t.forward(X, nlevels=nlevels, include_scale=include_scale)
     if include_scale:
         return r.lowpass, r.subbands, r.scales
     else:
         return r.lowpass, r.subbands
 
-class TransformDomainSignalOpenCL(object):
+class TransformDomainSignal(object):
     """
     An interface-compatible version of
     :py:class:`dtcwt.backend.TransformDomainSignal` where the initialiser
@@ -81,7 +81,7 @@ class TransformDomainSignalOpenCL(object):
     def scales(self):
         return tuple(to_array(x) for x in self.cl_scales) if self.cl_scales is not None else None
 
-class Transform2dOpenCL(Transform2dNumPy):
+class Transform2d(Transform2dNumPy):
     """
     An implementation of the 2D DT-CWT via OpenCL. *biort* and *qshift* are the
     wavelets which parameterise the transform. Valid values are documented in
@@ -99,7 +99,7 @@ class Transform2dOpenCL(Transform2dNumPy):
 
     """
     def __init__(self, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT, queue=None):
-        super(Transform2dOpenCL, self).__init__(biort=biort, qshift=qshift)
+        super(Transform2d, self).__init__(biort=biort, qshift=qshift)
         self.queue = to_queue(queue)
 
     def forward(self, X, nlevels=3, include_scale=False):
@@ -179,9 +179,9 @@ class Transform2dOpenCL(Transform2dNumPy):
 
         if nlevels == 0:
             if include_scale:
-                return TransformDomainSignalOpenCL(X, (), ())
+                return TransformDomainSignal(X, (), ())
             else:
-                return TransformDomainSignalOpenCL(X, ())
+                return TransformDomainSignal(X, ())
 
         # initialise
         Yh = [None,] * nlevels
@@ -275,6 +275,6 @@ class Transform2dOpenCL(Transform2dNumPy):
                 'The rightmost column has been duplicated, prior to decomposition.')
 
         if include_scale:
-            return TransformDomainSignalOpenCL(Yl, tuple(Yh), tuple(Yscale))
+            return TransformDomainSignal(Yl, tuple(Yh), tuple(Yscale))
         else:
-            return TransformDomainSignalOpenCL(Yl, tuple(Yh))
+            return TransformDomainSignal(Yl, tuple(Yh))
diff --git a/dtcwt/backend/__init__.py b/dtcwt/backend/base.py
similarity index 99%
copy from dtcwt/backend/__init__.py
copy to dtcwt/backend/base.py
index e37883c..5ec05fa 100644
--- a/dtcwt/backend/__init__.py
+++ b/dtcwt/backend/base.py
@@ -93,3 +93,4 @@ class Transform2d(object):
 
         """
         raise NotImplementedError()
+
diff --git a/dtcwt/transform2d.py b/dtcwt/transform2d.py
index 936cf70..2361619 100644
--- a/dtcwt/transform2d.py
+++ b/dtcwt/transform2d.py
@@ -8,8 +8,8 @@ from dtcwt.defaults import DEFAULT_BIORT, DEFAULT_QSHIFT
 from dtcwt.lowlevel import colfilter, coldfilt, colifilt
 from dtcwt.utils import appropriate_complex_type_for, asfarray
 
-from dtcwt.backend import TransformDomainSignal
-from dtcwt.backend.backend_numpy.transform2d import Transform2dNumPy
+from dtcwt.backend.base import TransformDomainSignal
+from dtcwt.backend.backend_numpy import Transform2d
 
 def dtwavexfm2(X, nlevels=3, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT, include_scale=False):
     """Perform a *n*-level DTCWT-2D decompostion on a 2D matrix *X*.
@@ -41,7 +41,7 @@ def dtwavexfm2(X, nlevels=3, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT, include
 
     """
 
-    trans = Transform2dNumPy(biort, qshift)
+    trans = Transform2d(biort, qshift)
     res = trans.forward(X, nlevels, include_scale)
 
     if include_scale:
@@ -83,7 +83,7 @@ def dtwaveifm2(Yl,Yh,biort=DEFAULT_BIORT,qshift=DEFAULT_QSHIFT,gain_mask=None):
     .. codeauthor:: Cian Shaffrey, Cambridge University, May 2002
 
     """
-    trans = Transform2dNumPy(biort, qshift)
+    trans = Transform2d(biort, qshift)
     res = trans.inverse(TransformDomainSignal(Yl, Yh), gain_mask=gain_mask)
     return res.value
 

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