def __init__(self, domain, axis, range=None, method='forward',
                 pad_mode='constant', pad_const=0):
        """Initialize a new instance.

        Parameters
        ----------
        domain : `DiscreteLp`
            Space of elements on which the operator can act.
        axis : int
            Axis along which the partial derivative is evaluated.
        range : `DiscreteLp`, optional
            Space of elements to which the operator maps, must have the
            same shape as ``domain``.
            For the default ``None``, the range is the same as ``domain``.
        method : {'forward', 'backward', 'central'}, optional
            Finite difference method which is used in the interior of the
            domain of ``f``.
        pad_mode : string, optional
            The padding mode to use outside the domain.

            ``'constant'``: Fill with ``pad_const``.

            ``'symmetric'``: Reflect at the boundaries, not doubling the
            outmost values.

            ``'periodic'``: Fill in values from the other side, keeping
            the order.

            ``'order0'``: Extend constantly with the outmost values
            (ensures continuity).

            ``'order1'``: Extend with constant slope (ensures continuity of
            the first derivative). This requires at least 2 values along
            each axis where padding is applied.

            ``'order2'``: Extend with second order accuracy (ensures continuity
            of the second derivative). This requires at least 3 values along
            the ``axis`` where padding is applied.

        pad_const : float, optional
            For ``pad_mode == 'constant'``, ``f`` assumes
            ``pad_const`` for indices outside the domain of ``f``

        Examples
        --------
        >>> f = np.array([[ 0.,  1.,  2.,  3.,  4.],
        ...               [ 0.,  2.,  4.,  6.,  8.]])
        >>> discr = odl.uniform_discr([0, 0], [2, 1], f.shape)
        >>> par_deriv = PartialDerivative(discr, axis=0, pad_mode='order1')
        >>> par_deriv(f)
        uniform_discr([ 0.,  0.], [ 2.,  1.], (2, 5)).element(
            [[ 0.,  1.,  2.,  3.,  4.],
             [ 0.,  1.,  2.,  3.,  4.]]
        )
        """
        if not isinstance(domain, DiscreteLp):
            raise TypeError('`domain` {!r} is not a DiscreteLp instance'
                            ''.format(domain))

        if range is None:
            range = domain

        # Method is affine if nonzero padding is given.
        linear = not (pad_mode == 'constant' and pad_const != 0)
        super(PartialDerivative, self).__init__(
            domain, range, base_space=domain, linear=linear)
        self.axis = int(axis)
        self.dx = self.domain.cell_sides[axis]

        self.method, method_in = str(method).lower(), method
        if method not in _SUPPORTED_DIFF_METHODS:
            raise ValueError('`method` {} not understood'
                             ''.format(method_in))

        self.pad_mode, pad_mode_in = str(pad_mode).lower(), pad_mode
        if pad_mode not in _SUPPORTED_PAD_MODES:
            raise ValueError('`pad_mode` {} not understood'
                             ''.format(pad_mode_in))

        self.pad_const = self.domain.field.element(pad_const)
def __init__ ( self , domain , axis , range = None , method = 'forward' , pad_mode = 'constant' , pad_const = 0 ) : if not isinstance ( domain , DiscreteLp ) : raise TypeError ( '`domain` {!r} is not a DiscreteLp instance' '' . format ( domain ) ) if range is None : range = domain linear = not ( pad_mode == 'constant' and pad_const != 0 ) super ( PartialDerivative , self ) . __init__ ( domain , range , base_space = domain , linear = linear ) self . axis = int ( axis ) self . dx = self . domain . cell_sides [ axis ] self . method , method_in = str ( method ) . lower ( ) , method if method not in _SUPPORTED_DIFF_METHODS : raise ValueError ( '`method` {} not understood' '' . format ( method_in ) ) self . pad_mode , pad_mode_in = str ( pad_mode ) . lower ( ) , pad_mode if pad_mode not in _SUPPORTED_PAD_MODES : raise ValueError ( '`pad_mode` {} not understood' '' . format ( pad_mode_in ) ) self . pad_const = self . domain . field . element ( pad_const )
Initialize a new instance.

        Parameters
        ----------
        domain : `DiscreteLp`
            Space of elements on which the operator can act.
        axis : int
            Axis along which the partial derivative is evaluated.
        range : `DiscreteLp`, optional
            Space of elements to which the operator maps, must have the
            same shape as ``domain``.
            For the default ``None``, the range is the same as ``domain``.
        method : {'forward', 'backward', 'central'}, optional
            Finite difference method which is used in the interior of the
            domain of ``f``.
        pad_mode : string, optional
            The padding mode to use outside the domain.

            ``'constant'``: Fill with ``pad_const``.

            ``'symmetric'``: Reflect at the boundaries, not doubling the
            outmost values.

            ``'periodic'``: Fill in values from the other side, keeping
            the order.

            ``'order0'``: Extend constantly with the outmost values
            (ensures continuity).

            ``'order1'``: Extend with constant slope (ensures continuity of
            the first derivative). This requires at least 2 values along
            each axis where padding is applied.

            ``'order2'``: Extend with second order accuracy (ensures continuity
            of the second derivative). This requires at least 3 values along
            the ``axis`` where padding is applied.

        pad_const : float, optional
            For ``pad_mode == 'constant'``, ``f`` assumes
            ``pad_const`` for indices outside the domain of ``f``

        Examples
        --------
        >>> f = np.array([[ 0.,  1.,  2.,  3.,  4.],
        ...               [ 0.,  2.,  4.,  6.,  8.]])
        >>> discr = odl.uniform_discr([0, 0], [2, 1], f.shape)
        >>> par_deriv = PartialDerivative(discr, axis=0, pad_mode='order1')
        >>> par_deriv(f)
        uniform_discr([ 0.,  0.], [ 2.,  1.], (2, 5)).element(
            [[ 0.,  1.,  2.,  3.,  4.],
             [ 0.,  1.,  2.,  3.,  4.]]
        )