code: def astra_algorithm(direction, ndim, vol_id, sino_id, proj_id, impl):
      
      if direction not in ('forward', 'backward'):
          raise ValueError("`direction` '{}' not understood".format(direction))
      if ndim not in (2, 3):
          raise ValueError('{}-dimensional projectors not supported'
                           ''.format(ndim))
      if impl not in ('cpu', 'cuda'):
          raise ValueError("`impl` type '{}' not understood"
                           ''.format(impl))
      if ndim == 3 and impl == 'cpu':
          raise NotImplementedError(
              '3d algorithms for CPU not supported by ASTRA')
      if proj_id is None and impl == 'cpu':
          raise ValueError("'cpu' implementation requires projector ID")
  
      algo_map = {'forward': {2: {'cpu': 'FP', 'cuda': 'FP_CUDA'},
                              3: {'cpu': None, 'cuda': 'FP3D_CUDA'}},
                  'backward': {2: {'cpu': 'BP', 'cuda': 'BP_CUDA'},
                               3: {'cpu': None, 'cuda': 'BP3D_CUDA'}}}
  
      algo_cfg = {'type': algo_map[direction][ndim][impl],
                  'ProjectorId': proj_id,
                  'ProjectionDataId': sino_id}
      if direction is 'forward':
          algo_cfg['VolumeDataId'] = vol_id
      else:
          algo_cfg['ReconstructionDataId'] = vol_id
  
      # Create ASTRA algorithm object
      return astra.algorithm.create(algo_cfg)
docs: Create an ASTRA algorithm object to run the projector.
  
      Parameters
      ----------
      direction : {'forward', 'backward'}
          For ``'forward'``, apply the forward projection, for ``'backward'``
          the backprojection.
      ndim : {2, 3}
          Number of dimensions of the projector.
      vol_id : int
          Handle for the ASTRA volume data object.
      sino_id : int
          Handle for the ASTRA projection data object.
      proj_id : int
          Handle for the ASTRA projector object.
      impl : {'cpu', 'cuda'}
          Implementation of the projector.
  
      Returns
      -------
      id : int
          Handle for the created ASTRA internal algorithm object.