def diff_is_negligible(m, m_ref, atol=None, rtol=None): if m.dtype.names is not None: return all(diff_is_negligible(m[name], m_ref[name]) for name in m.dtype.names) assert m.dtype == m_ref.dtype if dtypes.is_integer(m.dtype): close = (m == m_ref) else: if atol is None: atol = DOUBLE_ATOL if dtypes.is_double(m.dtype) else SINGLE_ATOL if rtol is None: rtol = DOUBLE_RTOL if dtypes.is_double(m.dtype) else SINGLE_RTOL close = numpy.isclose(m, m_ref, atol=atol, rtol=rtol) if close.all(): return True far_idxs = numpy.vstack(numpy.where(close == False)).T print( ("diff_is_negligible() with atol={atol} and rtol={rtol} " + "found {diffs} differences, first ones are:").format( atol=atol, rtol=rtol, diffs=str(far_idxs.shape[0]))) for idx, _ in zip(far_idxs, range(10)): idx = tuple(idx) print("idx: {idx}, test: {test}, ref: {ref}".format( idx=idx, test=m[idx], ref=m_ref[idx])) return False
def diff_is_negligible(m, m_ref, atol=None, rtol=None, verbose=True): if m.dtype.names is not None: return all( diff_is_negligible(m[name], m_ref[name]) for name in m.dtype.names) assert m.dtype == m_ref.dtype if dtypes.is_integer(m.dtype): close = (m == m_ref) else: if atol is None: atol = DOUBLE_ATOL if dtypes.is_double(m.dtype) else SINGLE_ATOL if rtol is None: rtol = DOUBLE_RTOL if dtypes.is_double(m.dtype) else SINGLE_RTOL close = numpy.isclose(m, m_ref, atol=atol, rtol=rtol) if close.all(): return True if verbose: far_idxs = numpy.vstack(numpy.where(close == False)).T print(("diff_is_negligible() with atol={atol} and rtol={rtol} " + "found {diffs} differences, first ones are:").format( atol=atol, rtol=rtol, diffs=str(far_idxs.shape[0]))) for idx, _ in zip(far_idxs, range(10)): idx = tuple(idx) print("idx: {idx}, test: {test}, ref: {ref}".format( idx=idx, test=m[idx], ref=m_ref[idx])) return False
def uniform_float(bijection, dtype, low=0, high=1): """ Generates uniformly distributed floating-points numbers in the interval ``[low, high)``. Supported dtypes: ``float(32/64)``. A fixed number of counters is used in each thread. Returns a :py:class:`~reikna.cbrng.samplers.Sampler` object. """ assert low < high ctype = dtypes.ctype(dtype) bitness = 64 if dtypes.is_double(dtype) else 32 raw_func = 'get_raw_uint' + str(bitness) raw_max = dtypes.c_constant(2 ** bitness, dtype) size = dtypes.c_constant(high - low, dtype) low = dtypes.c_constant(low, dtype) module = Module( TEMPLATE.get_def("uniform_float"), render_kwds=dict( bijection=bijection, ctype=ctype, raw_func=raw_func, raw_max=raw_max, size=size, low=low)) return Sampler(bijection, module, dtype, deterministic=True)
def uniform_float(bijection, dtype, low=0, high=1): """ Generates uniformly distributed floating-points numbers in the interval ``[low, high)``. Supported dtypes: ``float(32/64)``. A fixed number of counters is used in each thread. Returns a :py:class:`~reikna.cbrng.samplers.Sampler` object. """ assert low < high ctype = dtypes.ctype(dtype) bitness = 64 if dtypes.is_double(dtype) else 32 raw_func = 'get_raw_uint' + str(bitness) raw_max = dtypes.c_constant(2**bitness, dtype) size = dtypes.c_constant(high - low, dtype) low = dtypes.c_constant(low, dtype) module = Module(TEMPLATE.get_def("uniform_float"), render_kwds=dict(bijection=bijection, ctype=ctype, raw_func=raw_func, raw_max=raw_max, size=size, low=low)) return Sampler(bijection, module, dtype, deterministic=True)
def diff_is_negligible(m, m_ref): if m.dtype.names is not None: return all(diff_is_negligible(m[name], m_ref[name]) for name in m.dtype.names) assert m.dtype == m_ref.dtype if dtypes.is_integer(m.dtype): return ((m - m_ref) == 0).all() diff = float_diff(m, m_ref) if dtypes.is_double(m.dtype): return diff < DOUBLE_EPS else: return diff < SINGLE_EPS
def diff_is_negligible(m, m_ref): if m.dtype.names is not None: return all( diff_is_negligible(m[name], m_ref[name]) for name in m.dtype.names) assert m.dtype == m_ref.dtype if dtypes.is_integer(m.dtype): return ((m - m_ref) == 0).all() diff = float_diff(m, m_ref) if dtypes.is_double(m.dtype): return diff < DOUBLE_EPS else: return diff < SINGLE_EPS
def supports_dtype(self, dtype): if dtypes.is_double(dtype): extensions = self._device.extensions return "cl_khr_fp64" in extensions or "cl_amd_fp64" in extensions else: return True
def supports_dtype(self, dtype): if dtypes.is_double(dtype): major, minor = self._device.compute_capability() return (major == 1 and minor == 3) or major >= 2 else: return True