def transfer_many(objects, shape, pixel_size, energy, exponent=False, offset=None, queue=None, out=None, t=None, check=True, block=False): """Compute transmission from more *objects*. If *exponent* is True, compute only the exponent, if it is False, evaluate the exponent. Use *shape* (y, x), *pixel_size*, *energy*, *offset* as (y, x), OpenCL command *queue*, *out* array, time *t*, check the sampling if *check* is True and wait for OpenCL kernels if *block* is True. Returned *out* array is different from the input one because of the pyopencl.clmath behavior. """ if queue is None: queue = cfg.OPENCL.queue if out is None: out = cl_array.zeros(queue, shape, cfg.PRECISION.np_cplx) u_sample = cl_array.Array(queue, shape, cfg.PRECISION.np_cplx) lam = energy_to_wavelength(energy) for i, sample in enumerate(objects): try: out += sample.transfer(shape, pixel_size, energy, exponent=True, offset=offset, t=t, queue=queue, out=u_sample, check=False, block=block) except NotImplementedError: LOG.debug('%s does not support real space transfer', sample) if check and not is_wavefield_sampling_ok(out, queue=queue): LOG.error('Insufficient transmission function sampling') # Apply the exponent if not exponent: out = clmath.exp(out, queue=queue) return out
def transfer(thickness, refractive_index, wavelength, exponent=False, queue=None, out=None, check=True, block=False): """Transfer *thickness* (can be either a numpy or pyopencl array) with *refractive_index* and given *wavelength*. If *exponent* is True, compute the exponent of the function without applying the wavenumber. Use command *queue* for computation and *out* pyopencl array. If *block* is True, wait for the kernel to finish. If *check* is True, the function is checked for aliasing artefacts. Returned *out* array is different from the input one because of the pyopencl.clmath behavior. """ if queue is None: queue = cfg.OPENCL.queue if isinstance(thickness, cl_array.Array): thickness_mem = thickness else: prep = thickness.simplified.magnitude.astype(cfg.PRECISION.np_float) thickness_mem = cl_array.to_device(queue, prep) if out is None: out = cl_array.Array(queue, thickness_mem.shape, cfg.PRECISION.np_cplx) if exponent or check: wavenumber = cfg.PRECISION.np_float(2 * np.pi / wavelength.simplified.magnitude) ev = cfg.OPENCL.programs['physics'].transmission_add(queue, thickness_mem.shape[::-1], None, out.data, thickness_mem.data, cfg.PRECISION.np_cplx( refractive_index), wavenumber, np.int32(1)) if check and not is_wavefield_sampling_ok(out, queue=queue): LOG.error('Insufficient transmission function sampling') if not exponent: # Apply the exponent out = clmath.exp(out, queue=queue) else: ev = cfg.OPENCL.programs['physics'].transfer(queue, thickness_mem.shape[::-1], None, out.data, thickness_mem.data, cfg.PRECISION.np_cplx(refractive_index), cfg.PRECISION.np_float( wavelength.simplified.magnitude)) if block: ev.wait() return out
def exp(a, out=None): #TODO: work with out res = clmath.exp(a, queue=queue) #np.exp(*args, **kwargs) res.__class__ = myclArray res.reinit() return res
def exp(self): outimgcl = self.clone_empty() outimgcl.clarray = clmath.exp(self.clarray) return outimgcl