Skip to content

Commit 409ae01

Browse files
committed
Fix doctests in discr_ops.py
1 parent 382d72f commit 409ae01

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

odl/discr/discr_ops.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def __init__(self, domain, range, interp):
6464
6565
Apply the corresponding resampling operator to an element:
6666
67-
>>> print(resampling([0, 1, 0]))
68-
[ 0., 0., 1., 1., 0., 0.]
67+
>>> resampling([0, 1, 0])
68+
array([ 0., 0., 1., 1., 0., 0.])
6969
7070
With linear interpolation:
7171
7272
>>> 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. ]
73+
>>> resampling([0, 1, 0])
74+
array([ 0. , 0.25, 0.75, 0.75, 0.25, 0. ])
7575
"""
7676
if domain.domain != range.domain:
7777
raise ValueError(
@@ -107,11 +107,9 @@ def _call(self, x, out=None):
107107
x, self.domain.grid.coord_vectors, self.interp
108108
)
109109

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-
)
110+
return point_collocation(
111+
interpolator, self.range.meshgrid, out=out
112+
)
115113

116114
@property
117115
def inverse(self):
@@ -151,14 +149,14 @@ def adjoint(self):
151149
coarser to a finer sampling:
152150
153151
>>> x = [0, 1, 0]
154-
>>> print(resampling_inv(resampling(x)))
155-
[ 0., 1., 0.]
152+
>>> resampling_inv(resampling(x))
153+
array([ 0., 1., 0.])
156154
157155
However, it can fail in the other direction:
158156
159157
>>> y = [0, 0, 0, 1, 0, 0]
160-
>>> print(resampling(resampling_inv(y)))
161-
[ 0., 0., 0., 0., 0., 0.]
158+
>>> resampling(resampling_inv(y))
159+
array([ 0., 0., 0., 0., 0., 0.])
162160
"""
163161
return self.inverse
164162

@@ -251,29 +249,29 @@ def __init__(self, domain, range=None, ran_shp=None, **kwargs):
251249
>>> x = [[1, 2, 3, 4],
252250
... [5, 6, 7, 8]]
253251
>>> 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.]]
252+
>>> resize_op(x)
253+
array([[ 0., 0., 0., 0.],
254+
[ 1., 2., 3., 4.],
255+
[ 5., 6., 7., 8.],
256+
[ 0., 0., 0., 0.]])
259257
>>>
260258
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
261259
... offset=(0, 0),
262260
... 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.]]
261+
>>> resize_op(x)
262+
array([[ 1., 2., 3., 4.],
263+
[ 5., 6., 7., 8.],
264+
[ 1., 2., 3., 4.],
265+
[ 5., 6., 7., 8.]])
268266
>>>
269267
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
270268
... offset=(0, 0),
271269
... 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.]]
270+
>>> resize_op(x)
271+
array([[ 1., 2., 3., 4.],
272+
[ 5., 6., 7., 8.],
273+
[ 5., 6., 7., 8.],
274+
[ 5., 6., 7., 8.]])
277275
278276
Alternatively, the range of the operator can be provided directly.
279277
This requires that the partitions match, i.e. that the cell sizes
@@ -283,11 +281,11 @@ def __init__(self, domain, range=None, ran_shp=None, **kwargs):
283281
>>> large_spc = odl.uniform_discr([-0.5, 0], [1.5, 1], (4, 4))
284282
>>> resize_op = odl.ResizingOperator(space, large_spc,
285283
... 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.]]
284+
>>> resize_op(x)
285+
array([[ 5., 6., 7., 8.],
286+
[ 1., 2., 3., 4.],
287+
[ 5., 6., 7., 8.],
288+
[ 1., 2., 3., 4.]])
291289
"""
292290
# Swap names to be able to use the range iterator without worries
293291
import builtins
@@ -371,10 +369,9 @@ def axes(self):
371369

372370
def _call(self, x, out):
373371
"""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)
372+
resize_array(x, self.range.shape, offset=self.offset,
373+
pad_mode=self.pad_mode, pad_const=self.pad_const,
374+
direction='forward', out=out)
378375

379376
def derivative(self, point):
380377
"""Derivative of this operator at ``point``.
@@ -411,11 +408,9 @@ class ResizingOperatorAdjoint(Operator):
411408

412409
def _call(self, x, out):
413410
"""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)
411+
resize_array(x, op.domain.shape,
412+
offset=op.offset, pad_mode=op.pad_mode,
413+
pad_const=0, direction='adjoint', out=out)
419414

420415
@property
421416
def adjoint(self):

0 commit comments

Comments
 (0)