Skip to content

Commit 34f8be0

Browse files
committed
Fix doctests in discr_ops.py
1 parent 382d72f commit 34f8be0

File tree

1 file changed

+38
-44
lines changed

1 file changed

+38
-44
lines changed

odl/discr/discr_ops.py

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
from odl.operator import Operator
2020
from odl.space import tensor_space
2121
from odl.util import (
22-
normalized_scalar_param_list, resize_array, safe_int_conv, writable_array)
22+
normalized_scalar_param_list, resize_array, safe_int_conv)
2323
from odl.util.numerics import _SUPPORTED_RESIZE_PAD_MODES
24-
from odl.util.utility import none_context
2524

2625
__all__ = ('Resampling', 'ResizingOperator')
2726

@@ -64,14 +63,14 @@ def __init__(self, domain, range, interp):
6463
6564
Apply the corresponding resampling operator to an element:
6665
67-
>>> print(resampling([0, 1, 0]))
68-
[ 0., 0., 1., 1., 0., 0.]
66+
>>> resampling([0, 1, 0])
67+
array([ 0., 0., 1., 1., 0., 0.])
6968
7069
With linear interpolation:
7170
7271
>>> resampling = odl.Resampling(coarse_discr, fine_discr, 'linear')
73-
>>> print(resampling([0, 1, 0]))
74-
[ 0. , 0.25, 0.75, 0.75, 0.25, 0. ]
72+
>>> resampling([0, 1, 0])
73+
array([ 0. , 0.25, 0.75, 0.75, 0.25, 0. ])
7574
"""
7675
if domain.domain != range.domain:
7776
raise ValueError(
@@ -107,11 +106,9 @@ def _call(self, x, out=None):
107106
x, self.domain.grid.coord_vectors, self.interp
108107
)
109108

110-
context = none_context if out is None else writable_array
111-
with context(out) as out_arr:
112-
return point_collocation(
113-
interpolator, self.range.meshgrid, out=out_arr
114-
)
109+
return point_collocation(
110+
interpolator, self.range.meshgrid, out=out
111+
)
115112

116113
@property
117114
def inverse(self):
@@ -151,14 +148,14 @@ def adjoint(self):
151148
coarser to a finer sampling:
152149
153150
>>> x = [0, 1, 0]
154-
>>> print(resampling_inv(resampling(x)))
155-
[ 0., 1., 0.]
151+
>>> resampling_inv(resampling(x))
152+
array([ 0., 1., 0.])
156153
157154
However, it can fail in the other direction:
158155
159156
>>> y = [0, 0, 0, 1, 0, 0]
160-
>>> print(resampling(resampling_inv(y)))
161-
[ 0., 0., 0., 0., 0., 0.]
157+
>>> resampling(resampling_inv(y))
158+
array([ 0., 0., 0., 0., 0., 0.])
162159
"""
163160
return self.inverse
164161

@@ -251,29 +248,29 @@ def __init__(self, domain, range=None, ran_shp=None, **kwargs):
251248
>>> x = [[1, 2, 3, 4],
252249
... [5, 6, 7, 8]]
253250
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4))
254-
>>> print(resize_op(x))
255-
[[ 0., 0., 0., 0.],
256-
[ 1., 2., 3., 4.],
257-
[ 5., 6., 7., 8.],
258-
[ 0., 0., 0., 0.]]
251+
>>> resize_op(x)
252+
array([[ 0., 0., 0., 0.],
253+
[ 1., 2., 3., 4.],
254+
[ 5., 6., 7., 8.],
255+
[ 0., 0., 0., 0.]])
259256
>>>
260257
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
261258
... offset=(0, 0),
262259
... pad_mode='periodic')
263-
>>> print(resize_op(x))
264-
[[ 1., 2., 3., 4.],
265-
[ 5., 6., 7., 8.],
266-
[ 1., 2., 3., 4.],
267-
[ 5., 6., 7., 8.]]
260+
>>> resize_op(x)
261+
array([[ 1., 2., 3., 4.],
262+
[ 5., 6., 7., 8.],
263+
[ 1., 2., 3., 4.],
264+
[ 5., 6., 7., 8.]])
268265
>>>
269266
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
270267
... offset=(0, 0),
271268
... pad_mode='order0')
272-
>>> print(resize_op(x))
273-
[[ 1., 2., 3., 4.],
274-
[ 5., 6., 7., 8.],
275-
[ 5., 6., 7., 8.],
276-
[ 5., 6., 7., 8.]]
269+
>>> resize_op(x)
270+
array([[ 1., 2., 3., 4.],
271+
[ 5., 6., 7., 8.],
272+
[ 5., 6., 7., 8.],
273+
[ 5., 6., 7., 8.]])
277274
278275
Alternatively, the range of the operator can be provided directly.
279276
This requires that the partitions match, i.e. that the cell sizes
@@ -283,11 +280,11 @@ def __init__(self, domain, range=None, ran_shp=None, **kwargs):
283280
>>> large_spc = odl.uniform_discr([-0.5, 0], [1.5, 1], (4, 4))
284281
>>> resize_op = odl.ResizingOperator(space, large_spc,
285282
... pad_mode='periodic')
286-
>>> print(resize_op(x))
287-
[[ 5., 6., 7., 8.],
288-
[ 1., 2., 3., 4.],
289-
[ 5., 6., 7., 8.],
290-
[ 1., 2., 3., 4.]]
283+
>>> resize_op(x)
284+
array([[ 5., 6., 7., 8.],
285+
[ 1., 2., 3., 4.],
286+
[ 5., 6., 7., 8.],
287+
[ 1., 2., 3., 4.]])
291288
"""
292289
# Swap names to be able to use the range iterator without worries
293290
import builtins
@@ -371,10 +368,9 @@ def axes(self):
371368

372369
def _call(self, x, out):
373370
"""Implement ``self(x, out)``."""
374-
with writable_array(out) as out_arr:
375-
resize_array(x.asarray(), self.range.shape, offset=self.offset,
376-
pad_mode=self.pad_mode, pad_const=self.pad_const,
377-
direction='forward', out=out_arr)
371+
resize_array(x, self.range.shape, offset=self.offset,
372+
pad_mode=self.pad_mode, pad_const=self.pad_const,
373+
direction='forward', out=out)
378374

379375
def derivative(self, point):
380376
"""Derivative of this operator at ``point``.
@@ -411,11 +407,9 @@ class ResizingOperatorAdjoint(Operator):
411407

412408
def _call(self, x, out):
413409
"""Implement ``self(x, out)``."""
414-
with writable_array(out) as out_arr:
415-
resize_array(x.asarray(), op.domain.shape,
416-
offset=op.offset, pad_mode=op.pad_mode,
417-
pad_const=0, direction='adjoint',
418-
out=out_arr)
410+
resize_array(x, op.domain.shape,
411+
offset=op.offset, pad_mode=op.pad_mode,
412+
pad_const=0, direction='adjoint', out=out)
419413

420414
@property
421415
def adjoint(self):

0 commit comments

Comments
 (0)