def __init__(self, domain, sampling_points, variant='point_eval'):
        """Initialize a new instance.

        Parameters
        ----------
        domain : `TensorSpace`
            Set of elements on which this operator acts.
        sampling_points : 1D `array-like` or sequence of 1D array-likes
            Indices that determine the sampling points.
            In n dimensions, it should be a sequence of n arrays, where
            each member array is of equal length N. The indexed positions
            are ``(arr1[i], arr2[i], ..., arrn[i])``, in total N
            points.
            If ``domain`` is one-dimensional, a single array-like can be
            used. Likewise, a single point can be given as integer in 1D,
            and as a array-like sequence in nD.
        variant : {'point_eval', 'integrate'}, optional
            For ``'point_eval'`` this operator performs the sampling by
            evaluation the function at the sampling points. The
            ``'integrate'`` variant approximates integration by
            multiplying point evaluation with the cell volume.

        Examples
        --------
        Sampling in 1d can be done with a single index (an int) or a
        sequence of such:

        >>> space = odl.uniform_discr(0, 1, 4)
        >>> op = odl.SamplingOperator(space, sampling_points=1)
        >>> x = space.element([1, 2, 3, 4])
        >>> op(x)
        rn(1).element([ 2.])
        >>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1])
        >>> op(x)
        rn(3).element([ 2.,  3.,  2.])

        There are two variants ``'point_eval'`` (default) and
        ``'integrate'``, where the latter scales values by the cell
        volume to approximate the integral over the cells of the points:

        >>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1],
        ...                           variant='integrate')
        >>> space.cell_volume  # the scaling constant
        0.25
        >>> op(x)
        rn(3).element([ 0.5 ,  0.75,  0.5 ])

        In higher dimensions, a sequence of index array-likes must be
        given, or a single sequence for a single point:

        >>> space = odl.uniform_discr([0, 0], [1, 1], (2, 3))
        >>> # Sample at the index (0, 2)
        >>> op = odl.SamplingOperator(space, sampling_points=[0, 2])
        >>> x = space.element([[1, 2, 3],
        ...                    [4, 5, 6]])
        >>> op(x)
        rn(1).element([ 3.])
        >>> sampling_points = [[0, 1, 1],  # indices (0, 2), (1, 1), (1, 0)
        ...                    [2, 1, 0]]
        >>> op = odl.SamplingOperator(space, sampling_points)
        >>> op(x)
        rn(3).element([ 3.,  5.,  4.])
        """
        if not isinstance(domain, TensorSpace):
            raise TypeError('`domain` must be a `TensorSpace` instance, got '
                            '{!r}'.format(domain))

        self.__sampling_points = _normalize_sampling_points(sampling_points,
                                                            domain.ndim)
        # Flatten indices during init for faster indexing later
        indices_flat = np.ravel_multi_index(self.sampling_points,
                                            dims=domain.shape)
        if np.isscalar(indices_flat):
            self._indices_flat = np.array([indices_flat], dtype=int)
        else:
            self._indices_flat = indices_flat
        self.__variant = str(variant).lower()
        if self.variant not in ('point_eval', 'integrate'):
            raise ValueError('`variant` {!r} not understood'.format(variant))

        ran = tensor_space(self.sampling_points[0].size, dtype=domain.dtype)
        super(SamplingOperator, self).__init__(domain, ran, linear=True)
def __init__ ( self , domain , sampling_points , variant = 'point_eval' ) : if not isinstance ( domain , TensorSpace ) : raise TypeError ( '`domain` must be a `TensorSpace` instance, got ' '{!r}' . format ( domain ) ) self . __sampling_points = _normalize_sampling_points ( sampling_points , domain . ndim ) indices_flat = np . ravel_multi_index ( self . sampling_points , dims = domain . shape ) if np . isscalar ( indices_flat ) : self . _indices_flat = np . array ( [ indices_flat ] , dtype = int ) else : self . _indices_flat = indices_flat self . __variant = str ( variant ) . lower ( ) if self . variant not in ( 'point_eval' , 'integrate' ) : raise ValueError ( '`variant` {!r} not understood' . format ( variant ) ) ran = tensor_space ( self . sampling_points [ 0 ] . size , dtype = domain . dtype ) super ( SamplingOperator , self ) . __init__ ( domain , ran , linear = True )
Initialize a new instance.

        Parameters
        ----------
        domain : `TensorSpace`
            Set of elements on which this operator acts.
        sampling_points : 1D `array-like` or sequence of 1D array-likes
            Indices that determine the sampling points.
            In n dimensions, it should be a sequence of n arrays, where
            each member array is of equal length N. The indexed positions
            are ``(arr1[i], arr2[i], ..., arrn[i])``, in total N
            points.
            If ``domain`` is one-dimensional, a single array-like can be
            used. Likewise, a single point can be given as integer in 1D,
            and as a array-like sequence in nD.
        variant : {'point_eval', 'integrate'}, optional
            For ``'point_eval'`` this operator performs the sampling by
            evaluation the function at the sampling points. The
            ``'integrate'`` variant approximates integration by
            multiplying point evaluation with the cell volume.

        Examples
        --------
        Sampling in 1d can be done with a single index (an int) or a
        sequence of such:

        >>> space = odl.uniform_discr(0, 1, 4)
        >>> op = odl.SamplingOperator(space, sampling_points=1)
        >>> x = space.element([1, 2, 3, 4])
        >>> op(x)
        rn(1).element([ 2.])
        >>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1])
        >>> op(x)
        rn(3).element([ 2.,  3.,  2.])

        There are two variants ``'point_eval'`` (default) and
        ``'integrate'``, where the latter scales values by the cell
        volume to approximate the integral over the cells of the points:

        >>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1],
        ...                           variant='integrate')
        >>> space.cell_volume  # the scaling constant
        0.25
        >>> op(x)
        rn(3).element([ 0.5 ,  0.75,  0.5 ])

        In higher dimensions, a sequence of index array-likes must be
        given, or a single sequence for a single point:

        >>> space = odl.uniform_discr([0, 0], [1, 1], (2, 3))
        >>> # Sample at the index (0, 2)
        >>> op = odl.SamplingOperator(space, sampling_points=[0, 2])
        >>> x = space.element([[1, 2, 3],
        ...                    [4, 5, 6]])
        >>> op(x)
        rn(1).element([ 3.])
        >>> sampling_points = [[0, 1, 1],  # indices (0, 2), (1, 1), (1, 0)
        ...                    [2, 1, 0]]
        >>> op = odl.SamplingOperator(space, sampling_points)
        >>> op(x)
        rn(3).element([ 3.,  5.,  4.])