[python-dtcwt] 191/497: fix some imports in the NumPy backend
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:03 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 01f2e6c30ceb0a947e54c2c665478fb9a831d724
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Mon Nov 11 17:31:35 2013 +0000
fix some imports in the NumPy backend
Make sure that the NumPy backend uses its own colfilter, etc low-level
API instead of trying to use the indirect main API.
---
docs/reference.rst | 6 ++++
dtcwt/backend/__init__.py | 6 ++--
dtcwt/backend/backend_numpy/__init__.py | 5 +++
dtcwt/backend/backend_numpy/transform2d.py | 56 ++++++++++++++++--------------
dtcwt/backend/backend_opencl/__init__.py | 6 ++--
5 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/docs/reference.rst b/docs/reference.rst
index a962fce..2e9d30d 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -45,3 +45,9 @@ NumPy
.. automodule:: dtcwt.backend.backend_numpy
:members:
+
+OpenCL
+''''''
+
+.. automodule:: dtcwt.backend.backend_opencl
+ :members:
diff --git a/dtcwt/backend/__init__.py b/dtcwt/backend/__init__.py
index 34d08bf..b0f91e7 100644
--- a/dtcwt/backend/__init__.py
+++ b/dtcwt/backend/__init__.py
@@ -72,7 +72,7 @@ class Transform2d(object):
:param X: 2D real array
:param nlevels: Number of levels of wavelet decomposition
- :returns td: A :pyclass:`dtcwt.backend.TransformDomainSignal` compatible object representing the transform-domain signal
+ :returns td: A :py:class:`dtcwt.backend.TransformDomainSignal` compatible object representing the transform-domain signal
"""
raise NotImplementedError()
@@ -81,10 +81,10 @@ class Transform2d(object):
"""Perform an *n*-level dual-tree complex wavelet (DTCWT) 2D
reconstruction.
- :param td_signal: A :pyclass:`dtcwt.backend.TransformDomainSignal`-like class holding the transform domain representation to invert.
+ :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 Z: A :pyclass:`dtcwt.backend.ReconstructedSignal` compatible instance with the reconstruction.
+ :returns Z: 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
diff --git a/dtcwt/backend/backend_numpy/__init__.py b/dtcwt/backend/backend_numpy/__init__.py
index e69de29..4914aa4 100644
--- a/dtcwt/backend/backend_numpy/__init__.py
+++ b/dtcwt/backend/backend_numpy/__init__.py
@@ -0,0 +1,5 @@
+"""
+A backend which uses NumPy to perform the filtering. This backend should always
+be available.
+
+"""
diff --git a/dtcwt/backend/backend_numpy/transform2d.py b/dtcwt/backend/backend_numpy/transform2d.py
index ff1b8f6..7497a0a 100644
--- a/dtcwt/backend/backend_numpy/transform2d.py
+++ b/dtcwt/backend/backend_numpy/transform2d.py
@@ -6,9 +6,13 @@ from six.moves import xrange
from dtcwt.backend import TransformDomainSignal, ReconstructedSignal
from dtcwt.coeffs import biort as _biort, qshift as _qshift
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.backend_numpy.lowlevel import LowLevelBackendNumPy
+
+# Use the NumPy low-level backend
+_BACKEND = LowLevelBackendNumPy()
+
class Transform2dNumPy(object):
def __init__(self, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT):
# Load bi-orthogonal wavelets
@@ -90,20 +94,20 @@ class Transform2dNumPy(object):
if nlevels >= 1:
# Do odd top-level filters on cols.
- Lo = colfilter(X,h0o).T
- Hi = colfilter(X,h1o).T
+ Lo = _BACKEND.colfilter(X,h0o).T
+ Hi = _BACKEND.colfilter(X,h1o).T
if len(self.biort) >= 6:
- Ba = colfilter(X,h2o).T
+ Ba = _BACKEND.colfilter(X,h2o).T
# Do odd top-level filters on rows.
- LoLo = colfilter(Lo,h0o).T
+ LoLo = _BACKEND.colfilter(Lo,h0o).T
Yh[0] = np.zeros((LoLo.shape[0] >> 1, LoLo.shape[1] >> 1, 6), dtype=complex_dtype)
- Yh[0][:,:,0:6:5] = q2c(colfilter(Hi,h0o).T) # Horizontal pair
- Yh[0][:,:,2:4:1] = q2c(colfilter(Lo,h1o).T) # Vertical pair
+ Yh[0][:,:,0:6:5] = q2c(_BACKEND.colfilter(Hi,h0o).T) # Horizontal pair
+ Yh[0][:,:,2:4:1] = q2c(_BACKEND.colfilter(Lo,h1o).T) # Vertical pair
if len(self.biort) >= 6:
- Yh[0][:,:,1:5:3] = q2c(colfilter(Ba,h2o).T) # Diagonal pair
+ Yh[0][:,:,1:5:3] = q2c(_BACKEND.colfilter(Ba,h2o).T) # Diagonal pair
else:
- Yh[0][:,:,1:5:3] = q2c(colfilter(Hi,h1o).T) # Diagonal pair
+ Yh[0][:,:,1:5:3] = q2c(_BACKEND.colfilter(Hi,h1o).T) # Diagonal pair
if include_scale:
Yscale[0] = LoLo
@@ -119,21 +123,21 @@ class Transform2dNumPy(object):
LoLo = np.hstack((LoLo[:,:1], LoLo, LoLo[:,-1:]))
# Do even Qshift filters on rows.
- Lo = coldfilt(LoLo,h0b,h0a).T
- Hi = coldfilt(LoLo,h1b,h1a).T
+ Lo = _BACKEND.coldfilt(LoLo,h0b,h0a).T
+ Hi = _BACKEND.coldfilt(LoLo,h1b,h1a).T
if len(self.qshift) >= 10:
- Ba = coldfilt(LoLo,h2b,h2a).T
+ Ba = _BACKEND.coldfilt(LoLo,h2b,h2a).T
# Do even Qshift filters on columns.
- LoLo = coldfilt(Lo,h0b,h0a).T
+ LoLo = _BACKEND.coldfilt(Lo,h0b,h0a).T
Yh[level] = np.zeros((LoLo.shape[0]>>1, LoLo.shape[1]>>1, 6), dtype=complex_dtype)
- Yh[level][:,:,0:6:5] = q2c(coldfilt(Hi,h0b,h0a).T) # Horizontal
- Yh[level][:,:,2:4:1] = q2c(coldfilt(Lo,h1b,h1a).T) # Vertical
+ Yh[level][:,:,0:6:5] = q2c(_BACKEND.coldfilt(Hi,h0b,h0a).T) # Horizontal
+ Yh[level][:,:,2:4:1] = q2c(_BACKEND.coldfilt(Lo,h1b,h1a).T) # Vertical
if len(self.qshift) >= 10:
- Yh[level][:,:,1:5:3] = q2c(coldfilt(Ba,h2b,h2a).T) # Diagonal
+ Yh[level][:,:,1:5:3] = q2c(_BACKEND.coldfilt(Ba,h2b,h2a).T) # Diagonal
else:
- Yh[level][:,:,1:5:3] = q2c(coldfilt(Hi,h1b,h1a).T) # Diagonal
+ Yh[level][:,:,1:5:3] = q2c(_BACKEND.coldfilt(Hi,h1b,h1a).T) # Diagonal
if include_scale:
Yscale[level] = LoLo
@@ -214,11 +218,11 @@ class Transform2dNumPy(object):
hh = c2q(Yh[current_level-1][:,:,[1, 4]], gain_mask[[1, 4], current_level-1])
# Do even Qshift filters on columns.
- y1 = colifilt(Z,g0b,g0a) + colifilt(lh,g1b,g1a)
- y2 = colifilt(hl,g0b,g0a) + colifilt(hh,g1b,g1a)
+ y1 = _BACKEND.colifilt(Z,g0b,g0a) + _BACKEND.colifilt(lh,g1b,g1a)
+ y2 = _BACKEND.colifilt(hl,g0b,g0a) + _BACKEND.colifilt(hh,g1b,g1a)
# Do even Qshift filters on rows.
- Z = (colifilt(y1.T,g0b,g0a) + colifilt(y2.T,g1b,g1a)).T
+ Z = (_BACKEND.colifilt(y1.T,g0b,g0a) + _BACKEND.colifilt(y2.T,g1b,g1a)).T
# Check size of Z and crop as required
[row_size, col_size] = Z.shape
@@ -239,19 +243,19 @@ class Transform2dNumPy(object):
hh = c2q(Yh[current_level-1][:,:,[1, 4]],gain_mask[[1, 4],current_level-1])
# Do odd top-level filters on columns.
- y1 = colfilter(Z,g0o) + colfilter(lh,g1o)
+ y1 = _BACKEND.colfilter(Z,g0o) + _BACKEND.colfilter(lh,g1o)
if len(self.qshift) >= 10:
- y2 = colfilter(hl,g0o)
- y2bp = colfilter(hh,g2o)
+ y2 = _BACKEND.colfilter(hl,g0o)
+ y2bp = _BACKEND.colfilter(hh,g2o)
# Do odd top-level filters on rows.
- Z = (colfilter(y1.T,g0o) + colfilter(y2.T,g1o) + colfilter(y2bp.T, g2o)).T
+ Z = (_BACKEND.colfilter(y1.T,g0o) + _BACKEND.colfilter(y2.T,g1o) + _BACKEND.colfilter(y2bp.T, g2o)).T
else:
- y2 = colfilter(hl,g0o) + colfilter(hh,g1o)
+ y2 = _BACKEND.colfilter(hl,g0o) + _BACKEND.colfilter(hh,g1o)
# Do odd top-level filters on rows.
- Z = (colfilter(y1.T,g0o) + colfilter(y2.T,g1o)).T
+ Z = (_BACKEND.colfilter(y1.T,g0o) + _BACKEND.colfilter(y2.T,g1o)).T
return ReconstructedSignal(Z)
diff --git a/dtcwt/backend/backend_opencl/__init__.py b/dtcwt/backend/backend_opencl/__init__.py
index cdc697f..7d7ac2d 100644
--- a/dtcwt/backend/backend_opencl/__init__.py
+++ b/dtcwt/backend/backend_opencl/__init__.py
@@ -1,5 +1,5 @@
"""
-Provide low-level OpenCL accelerated operations.
-"""
+Provide low-level OpenCL accelerated operations. This backend requires that
+PyOpenCL be installed.
-from .lowlevel import colfilter
+"""
--
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