def check_np_equivalence(fun_name, args, kwargs, array_argnums): ans_truth = getfun(onp, fun_name)(*args, **kwargs) # Original numpy, regular args gnp_fun = getfun(gnp, fun_name) for dtypes in it.product(*[[gnp.float64, gnp.gpu_float32]] * len(array_argnums)): new_args = list(args) for dtype, argnum in zip(dtypes, array_argnums): if isinstance(args[argnum], onp.ndarray): new_args[argnum] = gnp.array(args[argnum], dtype=dtype) try: ans_test = gnp_fun(*new_args, **kwargs) if isinstance(ans_test, gnp.garray): ans_test = gnp.array(ans_test, dtype=gnp.float64) assert equivalent_types(ans_truth, ans_test), \ "Type mismatch! \nTruth: {0}, \nResult: {1}\nTypes: {2}, {3}".format( ans_truth, ans_test, type(ans_truth), type(ans_test)) assert onp.allclose(ans_truth, ans_test, atol=1e-5), \ "Value mismatch.\nTruth: {0}, \nResult: {1}".format(ans_truth, ans_test) except: print "Test failed, dtypes were {0} args were {1}, kwargs were {2}".format( dtypes, args, kwargs) raise
def check_np_equivalence(fun_name, args, kwargs, array_argnums): ans_truth = getfun(onp, fun_name)(*args, **kwargs) # Original numpy, regular args gnp_fun = getfun(gnp, fun_name) for dtypes in it.product(*[[gnp.float64, gnp.gpu_float32]]*len(array_argnums)): new_args = list(args) for dtype, argnum in zip(dtypes, array_argnums): if isinstance(args[argnum], onp.ndarray): new_args[argnum] = gnp.array(args[argnum], dtype=dtype) try: ans_test = gnp_fun(*new_args, **kwargs) if isinstance(ans_test, gnp.garray): ans_test = gnp.array(ans_test, dtype=gnp.float64) assert equivalent_types(ans_truth, ans_test), \ "Type mismatch! \nTruth: {0}, \nResult: {1}\nTypes: {2}, {3}".format( ans_truth, ans_test, type(ans_truth), type(ans_test)) assert onp.allclose(ans_truth, ans_test, atol=1e-5), \ "Value mismatch.\nTruth: {0}, \nResult: {1}".format(ans_truth, ans_test) except: print "Test failed, dtypes were {0} args were {1}, kwargs were {2}".format( dtypes, args, kwargs) raise
def array_from_args(*args): return np.array(args)
def array(A, *args, **kwargs): if isinstance(A, np.ndarray): return np.array(A, *args, **kwargs) else: raw_array = np.array(A, *args, **kwargs) return wrap_if_nodes_inside(raw_array)
def array_from_args(front_shape, *args): new_array = np.array(args) return new_array.reshape(front_shape + new_array.shape[1:])