pylops.utils.decorators.reshapedยถ

pylops.utils.decorators.reshaped(func=None, forward=None, swapaxis=False, axis=-1)[source]ยถ

Decorator for the common reshape/flatten pattern used in many operators.

Parameters:
funccallable, optional

Function to be decorated when no arguments are provided

forwardbool, optional

Reshape to dims if True, otherwise to dimsd. If not provided, the decorated functionโ€™s name will be inspected to infer the mode. Any operator having a name with โ€˜rmatโ€™ as substring or whose name is โ€˜divโ€™ or โ€˜__truediv__โ€™ will reshape to dimsd.

swapaxisbool, optional

If True, swaps the axis of the input array of the decorated function with self.axis. Only use if the decorated LinearOperator has axis attribute.

axisint, optional

Axis to be swapped when swapaxis is True.

Notes

A _matvec (forward) function can be simplified from

def _matvec(self, x):
    x = x.reshape(self.dims)
    x = x.swapaxes(self.axis, -1)
    y = do_things_to_reshaped_swapped(y)
    y = y.swapaxes(self.axis, -1)
    y = y.ravel()
    return y

to

@reshaped(swapaxis=True, axis=-1)
def _matvec(self, x):
    y = do_things_to_reshaped_swapped(y)
    return y

When the decorator has no arguments, it can be called without parenthesis, e.g.:

@reshaped
def _matvec(self, x):
    y = do_things_to_reshaped(y)
    return y

Examples using pylops.utils.decorators.reshapedยถ

Normal Moveout (NMO) Correction

Normal Moveout (NMO) Correction