def get_test_array(shape, dtype, no_zeros=False, high=None): if not isinstance(shape, tuple): shape = (shape,) dtype = dtypes.normalize_type(dtype) if dtypes.is_integer(dtype): low = 1 if no_zeros else 0 if high is None: high = 100 # will work even with signed chars get_arr = lambda: numpy.random.randint(low, high, shape).astype(dtype) else: low = 0.01 if no_zeros else 0 if high is None: high = 1.0 get_arr = lambda: numpy.random.uniform(low, high, shape).astype(dtype) if dtypes.is_complex(dtype): return get_arr() + 1j * get_arr() else: return get_arr()
def get_test_array(shape, dtype, no_zeros=False, high=None): if not isinstance(shape, tuple): shape = (shape, ) dtype = dtypes.normalize_type(dtype) if dtypes.is_integer(dtype): low = 1 if no_zeros else 0 if high is None: high = 100 # will work even with signed chars get_arr = lambda: numpy.random.randint(low, high, shape).astype(dtype) else: low = 0.01 if no_zeros else 0 if high is None: high = 1.0 get_arr = lambda: numpy.random.uniform(low, high, shape).astype(dtype) if dtypes.is_complex(dtype): return get_arr() + 1j * get_arr() else: return get_arr()
def deduce(name): node = self.nodes[name] if node.children is None: # Values received from user may point to the same object. # Therefore we're playing it safe and not assigning them. node.value.fill_with(values_dict[name]) return for child in node.children: deduce(child) # derive type child_dtypes = [self.nodes[child].value.dtype for child in node.children] tr = node.tr_to_children derive_types = tr.derive_i_from_os if node.type == NODE_OUTPUT else tr.derive_o_from_is node.value.dtype = dtypes.normalize_type(derive_types(*child_dtypes)) # derive shape child_shapes = [self.nodes[child].value.shape for child in node.children if hasattr(self.nodes[child].value, 'shape')] assert len(set(child_shapes)) == 1 node.value.shape = child_shapes[0]
to_device = (to_device1, to_device2) from_device = (from_device1, from_device2, from_device3, from_device4, from_device5) for to_d, from_d in itertools.product(to_device, from_device): a_device = to_d(a) a_copy = ctx.copy_array(a_device) a_back = from_d(a_copy) assert diff_is_negligible(a, a_back) @pytest.mark.parametrize( "dtype", TEST_DTYPES, ids=[dtypes.normalize_type(dtype).name for dtype in TEST_DTYPES]) def test_dtype_support(ctx, dtype): # Test passes if either context correctly reports that it does not support given dtype, # or it successfully compiles kernel that operates with this dtype. N = 256 if not ctx.supports_dtype(dtype): pytest.skip() module = ctx.compile(""" KERNEL void test( GLOBAL_MEM ${ctype} *dest, GLOBAL_MEM ${ctype} *a, GLOBAL_MEM ${ctype} *b) { const int i = get_global_id(0); ${ctype} temp = ${func.mul(dtype, dtype)}(a[i], b[i]);
ctx.synchronize() return y to_device = (to_device1, to_device2) from_device = (from_device1, from_device2, from_device3, from_device4, from_device5) for to_d, from_d in itertools.product(to_device, from_device): a_device = to_d(a) a_copy = ctx.copy_array(a_device) a_back = from_d(a_copy) assert diff_is_negligible(a, a_back) @pytest.mark.parametrize( "dtype", TEST_DTYPES, ids=[dtypes.normalize_type(dtype).name for dtype in TEST_DTYPES]) def test_dtype_support(ctx, dtype): # Test passes if either context correctly reports that it does not support given dtype, # or it successfully compiles kernel that operates with this dtype. N = 256 if not ctx.supports_dtype(dtype): pytest.skip() module = ctx.compile( """ KERNEL void test( GLOBAL_MEM ${ctype} *dest, GLOBAL_MEM ${ctype} *a, GLOBAL_MEM ${ctype} *b) { const int i = get_global_id(0);
def __init__(self, dtype): self.dtype = dtypes.normalize_type(dtype) if dtype is not None else None self.is_array = False
def __init__(self, shape, dtype): self.shape = wrap_in_tuple(shape) if shape is not None else None self.dtype = dtypes.normalize_type(dtype) if dtype is not None else None self.is_array = True