@@ -64,14 +64,14 @@ def __init__(self, domain, range, interp):
64
64
65
65
Apply the corresponding resampling operator to an element:
66
66
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.])
69
69
70
70
With linear interpolation:
71
71
72
72
>>> 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. ])
75
75
"""
76
76
if domain .domain != range .domain :
77
77
raise ValueError (
@@ -107,11 +107,9 @@ def _call(self, x, out=None):
107
107
x , self .domain .grid .coord_vectors , self .interp
108
108
)
109
109
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
+ )
115
113
116
114
@property
117
115
def inverse (self ):
@@ -151,14 +149,14 @@ def adjoint(self):
151
149
coarser to a finer sampling:
152
150
153
151
>>> x = [0, 1, 0]
154
- >>> print( resampling_inv(resampling(x) ))
155
- [ 0., 1., 0.]
152
+ >>> resampling_inv(resampling(x))
153
+ array( [ 0., 1., 0.])
156
154
157
155
However, it can fail in the other direction:
158
156
159
157
>>> 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.])
162
160
"""
163
161
return self .inverse
164
162
@@ -251,29 +249,29 @@ def __init__(self, domain, range=None, ran_shp=None, **kwargs):
251
249
>>> x = [[1, 2, 3, 4],
252
250
... [5, 6, 7, 8]]
253
251
>>> 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.]])
259
257
>>>
260
258
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
261
259
... offset=(0, 0),
262
260
... 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.]])
268
266
>>>
269
267
>>> resize_op = odl.ResizingOperator(space, ran_shp=(4, 4),
270
268
... offset=(0, 0),
271
269
... 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.]])
277
275
278
276
Alternatively, the range of the operator can be provided directly.
279
277
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):
283
281
>>> large_spc = odl.uniform_discr([-0.5, 0], [1.5, 1], (4, 4))
284
282
>>> resize_op = odl.ResizingOperator(space, large_spc,
285
283
... 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.]])
291
289
"""
292
290
# Swap names to be able to use the range iterator without worries
293
291
import builtins
@@ -371,10 +369,9 @@ def axes(self):
371
369
372
370
def _call (self , x , out ):
373
371
"""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 )
378
375
379
376
def derivative (self , point ):
380
377
"""Derivative of this operator at ``point``.
@@ -411,11 +408,9 @@ class ResizingOperatorAdjoint(Operator):
411
408
412
409
def _call (self , x , out ):
413
410
"""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 )
419
414
420
415
@property
421
416
def adjoint (self ):
0 commit comments