Example #1
0
    def element(self, fcall, vectorized=True):
        """Create a `FunctionSet` element.

        Parameters
        ----------
        fcall : callable
            The actual instruction for out-of-place evaluation.
            It must return a `FunctionSet.range` element or a
            `numpy.ndarray` of such (vectorized call).

        vectorized : bool, optional
            Whether ``fcall`` supports vectorized evaluation.

        Returns
        -------
        element : `FunctionSetElement`
            The new element, always supports vectorization

        See Also
        --------
        odl.discr.grid.RectGrid.meshgrid : efficient grids for function
            evaluation
        """
        if not callable(fcall):
            raise TypeError('`fcall` {!r} is not callable'.format(fcall))
        elif fcall in self:
            return fcall
        else:
            if not vectorized:
                fcall = vectorize(fcall)

            return self.element_type(self, fcall)
Example #2
0
    def element(self, fcall, vectorized=True):
        """Create a `FunctionSet` element.

        Parameters
        ----------
        fcall : callable
            The actual instruction for out-of-place evaluation.
            It must return a `FunctionSet.range` element or a
            `numpy.ndarray` of such (vectorized call).

        vectorized : bool, optional
            Whether ``fcall`` supports vectorized evaluation.

        Returns
        -------
        element : `FunctionSetElement`
            The new element, always supports vectorization

        See Also
        --------
        odl.discr.grid.RectGrid.meshgrid : efficient grids for function
            evaluation
        """
        if not callable(fcall):
            raise TypeError('`fcall` {!r} is not callable'.format(fcall))
        elif fcall in self:
            return fcall
        else:
            if not vectorized:
                fcall = vectorize(fcall)

            return self.element_type(self, fcall)
Example #3
0
    def element(self, fcall=None, vectorized=True):
        """Create a `FunctionSpace` element.

        Parameters
        ----------
        fcall : callable, optional
            The actual instruction for out-of-place evaluation.
            It must return a `FunctionSet.range` element or a
            `numpy.ndarray` of such (vectorized call).

            If fcall is a `FunctionSetElement`, it is wrapped
            as a new `FunctionSpaceElement`.

        vectorized : bool, optional
            Whether ``fcall`` supports vectorized evaluation.

        Returns
        -------
        element : `FunctionSpaceElement`
            The new element, always supports vectorization

        Notes
        -----
        If you specify ``vectorized=False``, the function is decorated
        with a vectorizer, which makes two elements created this way
        from the same function being regarded as *not equal*.
        """
        if fcall is None:
            return self.zero()
        elif fcall in self:
            return fcall
        else:
            if not callable(fcall):
                raise TypeError('`fcall` {!r} is not callable'.format(fcall))
            if not vectorized:
                if self.field == RealNumbers():
                    dtype = 'float64'
                else:
                    dtype = 'complex128'

                fcall = vectorize(otypes=[dtype])(fcall)

            return self.element_type(self, fcall)
Example #4
0
    def element(self, fcall=None, vectorized=True):
        """Create a `FunctionSpace` element.

        Parameters
        ----------
        fcall : callable, optional
            The actual instruction for out-of-place evaluation.
            It must return a `FunctionSet.range` element or a
            `numpy.ndarray` of such (vectorized call).

            If fcall is a `FunctionSetElement`, it is wrapped
            as a new `FunctionSpaceElement`.

        vectorized : bool, optional
            Whether ``fcall`` supports vectorized evaluation.

        Returns
        -------
        element : `FunctionSpaceElement`
            The new element, always supports vectorization

        Notes
        -----
        If you specify ``vectorized=False``, the function is decorated
        with a vectorizer, which makes two elements created this way
        from the same function being regarded as *not equal*.
        """
        if fcall is None:
            return self.zero()
        elif fcall in self:
            return fcall
        else:
            if not callable(fcall):
                raise TypeError('`fcall` {!r} is not callable'.format(fcall))
            if not vectorized:
                if self.field == RealNumbers():
                    dtype = 'float64'
                else:
                    dtype = 'complex128'

                fcall = vectorize(otypes=[dtype])(fcall)

            return self.element_type(self, fcall)