def __init__(self, fspace, partition, tspace, interp='nearest', **kwargs):
        """Initialize a new instance.

        Parameters
        ----------
        fspace : `FunctionSpace`
            The continuous space to be discretized.
        partition : `RectPartition`
            Partition of (a subset of) ``fspace.domain``.
        tspace : `TensorSpace`
            Space of elements used for data storage. It must have the
            same `TensorSpace.field` as ``fspace`` and the same
            `TensorSpace.shape` as ``partition``.
        interp : str or sequence of str, optional
            Interpolation type to be used for discretization.
            A sequence is interpreted as interpolation scheme per axis.
            Possible values:

            - ``'nearest'`` : use nearest-neighbor interpolation.
            - ``'linear'`` : use linear interpolation.

        axis_labels : sequence of str, optional
            Names of the axes to use for plotting etc.
            Default:

            - 1D: ``['$x$']``
            - 2D: ``['$x$', '$y$']``
            - 3D: ``['$x$', '$y$', '$z$']``
            - nD: ``['$x_1$', '$x_2$', ..., '$x_n$']``

            Note: The ``$`` signs ensure rendering as LaTeX.
        """
        if not isinstance(fspace, FunctionSpace):
            raise TypeError('{!r} is not a FunctionSpace instance'
                            ''.format(fspace))
        if not isinstance(fspace.domain, IntervalProd):
            raise TypeError('function space domain {!r} is not an '
                            'IntervalProd instance'.format(fspace.domain))
        if not isinstance(partition, RectPartition):
            raise TypeError('`partition` {!r} is not a RectPartition '
                            'instance'.format(partition))
        if not fspace.domain.contains_set(partition.set):
            raise ValueError('`partition` {} is not a subset of the function '
                             'domain {}'.format(partition, fspace.domain))
        if fspace.scalar_out_dtype != tspace.dtype:
            raise ValueError('`fspace.scalar_out_dtype` does not match '
                             '`tspace.dtype`: {} != {}'
                             ''.format(fspace.scalar_out_dtype, tspace.dtype))

        self.__partition = partition

        # Handle interp
        if is_string(interp):
            interp, interp_in = str(interp).lower(), interp
            if interp not in _SUPPORTED_INTERP:
                raise ValueError('`interp` {!r} not understood'
                                 ''.format(interp_in))
            # Ensure that there is 1 entry for ndim == 0
            self.__interp_byaxis = (interp,) * max(partition.ndim, 1)
        else:
            # Got sequence of strings
            if len(interp) != partition.ndim:
                raise ValueError('expected {} (ndim) entries in `interp`, '
                                 'got {}'.format(partition.ndim, len(interp)))

            self.__interp_byaxis = tuple(str(s).lower() for s in interp)
            if any(s not in _SUPPORTED_INTERP for s in self.interp_byaxis):
                raise ValueError('`interp` sequence {} contains illegal '
                                 'values'.format(interp))

        # Assign sampling and interpolation operators
        sampling = PointCollocation(fspace, self.partition, tspace)
        if all(s == 'nearest' for s in self.interp_byaxis):
            interpol = NearestInterpolation(fspace, self.partition, tspace)
        elif all(s == 'linear' for s in self.interp_byaxis):
            interpol = LinearInterpolation(fspace, self.partition, tspace)
        else:
            interpol = PerAxisInterpolation(
                fspace, self.partition, tspace, self.interp_byaxis)

        super(DiscreteLp, self).__init__(fspace, tspace, sampling, interpol)

        # Set axis labels
        axis_labels = kwargs.pop('axis_labels', None)
        if axis_labels is None:
            if self.ndim <= 3:
                self.__axis_labels = ('$x$', '$y$', '$z$')[:self.ndim]
            else:
                self.__axis_labels = tuple('$x_{}$'.format(axis)
                                           for axis in range(self.ndim))
        else:
            self.__axis_labels = tuple(str(label) for label in axis_labels)

        if kwargs:
            raise ValueError('got unexpected keyword arguments {}'
                             ''.format(kwargs))
def __init__ ( self , fspace , partition , tspace , interp = 'nearest' , ** kwargs ) : if not isinstance ( fspace , FunctionSpace ) : raise TypeError ( '{!r} is not a FunctionSpace instance' '' . format ( fspace ) ) if not isinstance ( fspace . domain , IntervalProd ) : raise TypeError ( 'function space domain {!r} is not an ' 'IntervalProd instance' . format ( fspace . domain ) ) if not isinstance ( partition , RectPartition ) : raise TypeError ( '`partition` {!r} is not a RectPartition ' 'instance' . format ( partition ) ) if not fspace . domain . contains_set ( partition . set ) : raise ValueError ( '`partition` {} is not a subset of the function ' 'domain {}' . format ( partition , fspace . domain ) ) if fspace . scalar_out_dtype != tspace . dtype : raise ValueError ( '`fspace.scalar_out_dtype` does not match ' '`tspace.dtype`: {} != {}' '' . format ( fspace . scalar_out_dtype , tspace . dtype ) ) self . __partition = partition if is_string ( interp ) : interp , interp_in = str ( interp ) . lower ( ) , interp if interp not in _SUPPORTED_INTERP : raise ValueError ( '`interp` {!r} not understood' '' . format ( interp_in ) ) self . __interp_byaxis = ( interp , ) * max ( partition . ndim , 1 ) else : if len ( interp ) != partition . ndim : raise ValueError ( 'expected {} (ndim) entries in `interp`, ' 'got {}' . format ( partition . ndim , len ( interp ) ) ) self . __interp_byaxis = tuple ( str ( s ) . lower ( ) for s in interp ) if any ( s not in _SUPPORTED_INTERP for s in self . interp_byaxis ) : raise ValueError ( '`interp` sequence {} contains illegal ' 'values' . format ( interp ) ) sampling = PointCollocation ( fspace , self . partition , tspace ) if all ( s == 'nearest' for s in self . interp_byaxis ) : interpol = NearestInterpolation ( fspace , self . partition , tspace ) elif all ( s == 'linear' for s in self . interp_byaxis ) : interpol = LinearInterpolation ( fspace , self . partition , tspace ) else : interpol = PerAxisInterpolation ( fspace , self . partition , tspace , self . interp_byaxis ) super ( DiscreteLp , self ) . __init__ ( fspace , tspace , sampling , interpol ) axis_labels = kwargs . pop ( 'axis_labels' , None ) if axis_labels is None : if self . ndim <= 3 : self . __axis_labels = ( '$x$' , '$y$' , '$z$' ) [ : self . ndim ] else : self . __axis_labels = tuple ( '$x_{}$' . format ( axis ) for axis in range ( self . ndim ) ) else : self . __axis_labels = tuple ( str ( label ) for label in axis_labels ) if kwargs : raise ValueError ( 'got unexpected keyword arguments {}' '' . format ( kwargs ) )
Initialize a new instance.

        Parameters
        ----------
        fspace : `FunctionSpace`
            The continuous space to be discretized.
        partition : `RectPartition`
            Partition of (a subset of) ``fspace.domain``.
        tspace : `TensorSpace`
            Space of elements used for data storage. It must have the
            same `TensorSpace.field` as ``fspace`` and the same
            `TensorSpace.shape` as ``partition``.
        interp : str or sequence of str, optional
            Interpolation type to be used for discretization.
            A sequence is interpreted as interpolation scheme per axis.
            Possible values:

            - ``'nearest'`` : use nearest-neighbor interpolation.
            - ``'linear'`` : use linear interpolation.

        axis_labels : sequence of str, optional
            Names of the axes to use for plotting etc.
            Default:

            - 1D: ``['$x$']``
            - 2D: ``['$x$', '$y$']``
            - 3D: ``['$x$', '$y$', '$z$']``
            - nD: ``['$x_1$', '$x_2$', ..., '$x_n$']``

            Note: The ``$`` signs ensure rendering as LaTeX.