def impl_test_std(self, dtype): x = np.random.normal(scale=5.0, size=(3, 5)) x = x.astype(dtype=dtype, order='C') x_gpu = gpuarray.to_gpu(x) assert np.allclose(misc.std(x_gpu).get(), x.std()) assert np.allclose(misc.std(x_gpu, axis=0).get(), x.std(axis=0)) assert np.allclose(misc.std(x_gpu, axis=1).get(), x.std(axis=1))
def _impl_test_std(self, dtype): x = np.random.normal(scale=5.0, size=(3, 5)) x = x.astype(dtype=dtype, order='C') x_gpu = gpuarray.to_gpu(x) assert_allclose(misc.std(x_gpu).get(), x.std(), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype]) assert_allclose(misc.std(x_gpu, axis=0).get(), x.std(axis=0), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype]) assert_allclose(misc.std(x_gpu, axis=1).get(), x.std(axis=1), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype]) assert_allclose(misc.std(x_gpu, ddof=1).get(), x.std(ddof=1), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype]) assert_allclose(misc.std(x_gpu, ddof=1, axis=0).get(), x.std(ddof=1, axis=0), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype]) assert_allclose(misc.std(x_gpu, ddof=1, axis=1).get(), x.std(ddof=1, axis=1), rtol=dtype_to_rtol[dtype], atol=dtype_to_atol[dtype])
from pycuda import cumath # I. subjects to monkey patching: from ..particles import particles as def_particles from ..particles import slicing as def_slicing from ..trackers import simple_long_tracking as def_simple_long_tracking from ..trackers import wrapper as def_wrapper # II. actual monkey patching # a) Particles rebindings for GPU from .particles import ParticlesGPU def_particles.Particles = ParticlesGPU def_particles.mean = lambda *args, **kwargs: mean(*args, **kwargs).get() def_particles.std = lambda *args, **kwargs: std(*args, **kwargs).get() # b) Slicing rebindings for GPU # def_slicing.min_ = lambda *args, **kwargs: gpuarray.min(*args, **kwargs).get() # def_slicing.max_ = lambda *args, **kwargs: gpuarray.max(*args, **kwargs).get() # def_slicing.diff = diff from .slicing import SlicerGPU # # to be replaced: find a better solution than monkey patching base classes! # # (to solve the corresponding need to replace all inheriting classes' parent!) # def_slicing.Slicer = SlicerGPU # def_slicing.UniformBinSlicer.__bases__ = (SlicerGPU,) # c) Longitudinal tracker rebindings for GPU def_simple_long_tracking.sin = cumath.sin