DiscretizedSpaceElement.writable_array

DiscretizedSpaceElement.writable_array(must_be_contiguous: bool = False)[source]

Context manager that casts self to a backend-specific array and saves changes made to that array back in self.

Parameters

must_be_contiguousbool

Whether the writable array should guarantee standard C order. See documentation to asarray for the semantics.

Examples

>>> space = odl.uniform_discr(0, 1, 3)
>>> x = space.element([1, 2, 3])
>>> with x.writable_array() as arr:
...     arr += [1, 1, 1]
>>> x
uniform_discr(0.0, 1.0, 3).element([ 2.,  3.,  4.])

Note that the changes are in general only saved upon exiting the context manager. Before, the input object may remain unchanged.