Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 7a35250

Browse files
committed
Merge pull request #99 from rjw57/fix-switch-backend
ensure preserve_backend_stack() preserves backend name
2 parents 1957eb1 + 8ee7ae0 commit 7a35250

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Changes
7373

7474
* Add queue parameter to low-level OpenCL ``colifilt`` and ``coldfilt`` functions.
7575
* Significantly increase speed of ``dtcwt.registration.estimatereg`` function.
76+
* Fix bug whereby ``dtcwt.backend_name`` was not restored when using
77+
``preserve_backend_stack``.
7678

7779
0.9.1
7880
'''''

dtcwt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ def _update_from_current_backend():
4848

4949
class _BackendGuard(object):
5050
def __init__(self, stack):
51+
# Explicitly copy the stack
5152
self._stack = list(stack)
5253

5354
def __enter__(self):
5455
return _BACKEND_STACK
5556

5657
def __exit__(self, exc_type, exc_value, exc_tb):
5758
dtcwt._BACKEND_STACK = self._stack
59+
_update_from_current_backend()
5860
# only re-raise if it's *not* the exception that was
5961
# passed to throw(), because __exit__() must not raise
6062
# an exception unless __exit__() itself failed. But

tests/testswitchbackends.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@ def test_backend_with_guard_and_exception():
8080
correctly propagated.
8181
8282
"""
83-
assert len(dtcwt._BACKEND_STACK) == 1
83+
dtcwt.push_backend('numpy')
84+
assert len(dtcwt._BACKEND_STACK) == 2
85+
assert dtcwt.backend_name == 'numpy'
8486
def tst():
8587
with dtcwt.preserve_backend_stack():
86-
dtcwt.push_backend('numpy')
87-
assert len(dtcwt._BACKEND_STACK) == 2
88+
dtcwt.push_backend('opencl')
89+
assert dtcwt.backend_name == 'opencl'
90+
assert len(dtcwt._BACKEND_STACK) == 3
8891
raise RuntimeError('test error')
8992
assert_raises(RuntimeError, tst)
90-
assert len(dtcwt._BACKEND_STACK) == 1
93+
assert dtcwt.backend_name == 'numpy'
94+
assert len(dtcwt._BACKEND_STACK) == 2

0 commit comments

Comments
 (0)