def test_np_empty(): dtypes = [np.int8, np.int32, np.float16, np.float32, np.float64, None] expected_dtypes = [ np.int8, np.int32, np.float16, np.float32, np.float64, np.float32 ] orders = ['C', 'F', 'A'] shapes = [ (), 0, (0, ), (0, 0), 2, (2, ), (3, 0), (4, 5), (1, 1, 1, 1), ] ctxes = [npx.current_context(), None] for dtype, expected_dtype in zip(dtypes, expected_dtypes): for shape in shapes: for order in orders: for ctx in ctxes: if order == 'C': ret = np.empty(shape, dtype, order, ctx) assert ret.dtype == expected_dtype assert ret.shape == shape if isinstance( shape, tuple) else (shape, ) assert ret.ctx == npx.current_context() else: assert_exception(np.empty, NotImplementedError, shape, dtype, order, ctx)
def test_np_empty(): # (input dtype, expected output dtype) dtype_pairs = [ (np.int8, np.int8), (np.int32, np.int32), (np.float16, np.float16), (np.float32, np.float32), (np.float64, np.float64), (np.bool_, np.bool_), (np.bool, np.bool_), ('int8', np.int8), ('int32', np.int32), ('float16', np.float16), ('float32', np.float32), ('float64', np.float64), ('bool', np.bool_), (None, np.float32), ] orders = ['C', 'F', 'A'] shapes = [ (), 0, (0, ), (0, 0), 2, (2, ), (3, 0), (4, 5), (1, 1, 1, 1), ] ctxes = [npx.current_context(), None] for dtype, expected_dtype in dtype_pairs: for shape in shapes: for order in orders: for ctx in ctxes: if order == 'C': ret = np.empty(shape, dtype, order, ctx) assert ret.dtype == expected_dtype assert ret.shape == shape if isinstance( shape, tuple) else (shape, ) assert ret.ctx == npx.current_context() else: assert_exception(np.empty, NotImplementedError, shape, dtype, order, ctx)