예제 #1
0
파일: ray_trafo.py 프로젝트: rajmund/odl
    def _call(self, x, out=None):
        """Apply the operator to ``x`` and store the result in ``out``.

        Parameters
        ----------
        x : `DiscreteLpVector`
           Element in the domain of the operator to be forward projected
        out : `DiscreteLpVector`, optional
            Vector in the projection space to which the result is written.
            If `None` creates an element in the range of the operator.

        Returns
        -------
        out : `DiscreteLpVector`
            Returns an element in the projection space
        """
        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_forward_projector(x, self.geometry,
                                                   self.range, out)
            elif data_impl == 'cuda':
                return astra_cuda_forward_projector(x, self.geometry,
                                                    self.range, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_forward(x, self.geometry, self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
예제 #2
0
    def _call_real(self, x_real, out_real):
        """Real-space forward projection for the current set-up.

        This method also sets ``self._astra_projector`` for
        ``impl='astra_cuda'`` and enabled cache.
        """
        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')

            if data_impl == 'cpu':
                return astra_cpu_forward_projector(x_real, self.geometry,
                                                   self.range.real_space,
                                                   out_real)

            elif data_impl == 'cuda':
                if self._astra_wrapper is None:
                    astra_wrapper = AstraCudaProjectorImpl(
                        self.geometry, self.domain.real_space,
                        self.range.real_space)
                    if self.use_cache:
                        self._astra_wrapper = astra_wrapper
                else:
                    astra_wrapper = self._astra_wrapper

                return astra_wrapper.call_forward(x_real, out_real)
            else:
                # Should never happen
                raise RuntimeError('bad `impl` {!r}'.format(self.impl))
        elif self.impl == 'skimage':
            return skimage_radon_forward(x_real, self.geometry,
                                         self.range.real_space, out_real)
        else:
            # Should never happen
            raise RuntimeError('bad `impl` {!r}'.format(self.impl))
예제 #3
0
파일: ray_trafo.py 프로젝트: odlgroup/odl
 def _call(self, x, out=None):
     """Forward project ``x`` and store the result in ``out`` if given."""
     if self.impl.startswith('astra'):
         backend, data_impl = self.impl.split('_')
         if data_impl == 'cpu':
             return astra_cpu_forward_projector(x, self.geometry,
                                                self.range, out)
         elif data_impl == 'cuda':
             return astra_cuda_forward_projector(x, self.geometry,
                                                 self.range, out)
         else:
             # Should never happen
             raise RuntimeError('implementation info is inconsistent')
     elif self.impl == 'scikit':
         return scikit_radon_forward(x, self.geometry, self.range, out)
     else:  # Should never happen
         raise RuntimeError('implementation info is inconsistent')
예제 #4
0
    def _call(self, x, out=None):
        """Forward project ``x`` and store the result in ``out`` if given."""
        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_forward_projector(x, self.geometry,
                                                   self.range, out)
            elif data_impl == 'cuda':
                proj = getattr(self, 'astra_projector', None)
                if proj is None:
                    self.astra_projector = AstraCudaProjectorImpl(
                        self.geometry, self.domain, self.range,
                        use_cache=self.use_cache)

                return self.astra_projector.call_forward(x, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_forward(x, self.geometry, self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
예제 #5
0
    def _call(self, x, out=None):
        """Forward project ``x`` and store the result in ``out`` if given."""
        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')
            if data_impl == 'cpu':
                return astra_cpu_forward_projector(x, self.geometry,
                                                   self.range, out)
            elif data_impl == 'cuda':
                proj = getattr(self, 'astra_projector', None)
                if proj is None:
                    self.astra_projector = AstraCudaProjectorImpl(
                        self.geometry,
                        self.domain,
                        self.range,
                        use_cache=self.use_cache)

                return self.astra_projector.call_forward(x, out)
            else:
                # Should never happen
                raise RuntimeError('implementation info is inconsistent')
        elif self.impl == 'scikit':
            return scikit_radon_forward(x, self.geometry, self.range, out)
        else:  # Should never happen
            raise RuntimeError('implementation info is inconsistent')
    def _call_real(self, x_real, angle_array, out_real):
        """Real-space forward projection for the current set-up."""
        geometry = self.spacegeometry(angle_array)
        partialrange = self.range(geometry)
        partialdomain = self.domain(geometry)

        if self.impl.startswith('astra'):
            backend, data_impl = self.impl.split('_')

            if data_impl == 'cpu':
                return astra_cpu_forward_projector(x_real, geometry,
                                                   partialrange.real_space,
                                                   out_real)

            elif data_impl == 'cuda':
                # if self._astra_wrapper is None:
                #     astra_wrapper = AstraCudaProjectorImpl(
                #         geometry, partialdomain.real_space,
                #         partialrange.real_space)
                #     if self.use_cache:
                #         self._astra_wrapper = astra_wrapper
                # else:
                #     print("ever here?")
                #     astra_wrapper = self._astra_wrapper
                astra_wrapper = AstraCudaProjectorImpl(
                    geometry, partialdomain.real_space,
                    partialrange.real_space)

                return astra_wrapper.call_forward(x_real, out_real)
            else:
                # Should never happen
                raise RuntimeError('bad `impl` {!r}'.format(self.impl))

        else:
            # Should never happen
            raise RuntimeError('bad `impl` {!r}'.format(self.impl))