def test_not(): element_type = Type.boolean shape = Shape([2]) A = Parameter(element_type, shape) parameter_list = [A] function = Function(NodeVector([Not(A)]), parameter_list, 'test') backend, cf = make_backend_call_frame(function) a = backend.make_primary_tensor_view(element_type, shape) result = backend.make_primary_tensor_view(Type.boolean, shape) a.write(util.numpy_to_c(np.array([True, False], dtype=np.bool)), 0, 2) result_arr = np.array([False, False], dtype=np.bool) result.write(util.numpy_to_c(result_arr), 0, 2) cf.call([result], [a]) result.read(util.numpy_to_c(result_arr), 0, 2) a_arr = np.array([True, False], dtype=np.bool) result_arr_ref = np.logical_not(a_arr) assert np.allclose(result_arr, result_arr_ref)
def test_not(): element_type = Type.boolean shape = Shape([2]) A = Parameter(element_type, shape) parameter_list = [A] function = Function(NodeVector([Not(A)]), parameter_list, 'test') backend = Backend.create(pytest.config.getoption('backend')) a = backend.create_tensor(element_type, shape) result = backend.create_tensor(Type.boolean, shape) a.write(util.numpy_to_c(np.array([True, False], dtype=np.bool)), 0, 2) result_arr = np.array([False, False], dtype=np.bool) result.write(util.numpy_to_c(result_arr), 0, 2) backend.call(backend.compile(function), [result], [a]) result.read(util.numpy_to_c(result_arr), 0, 2) a_arr = np.array([True, False], dtype=np.bool) result_arr_ref = np.logical_not(a_arr) assert np.allclose(result_arr, result_arr_ref)
def test_not(): element_type = Type.boolean shape = Shape([2]) A = Parameter(element_type, shape) parameter_list = [A] function = Function([Not(A)], parameter_list, 'test') backend = Backend.create(test.BACKEND_NAME) a = backend.create_tensor(element_type, shape) result = backend.create_tensor(Type.boolean, shape) a.write(util.numpy_to_c(np.array([True, False], dtype=np.bool)), 2) result_arr = np.array([False, False], dtype=np.bool) result.write(util.numpy_to_c(result_arr), 2) handle = backend.compile(function) handle.call([result], [a]) result.read(util.numpy_to_c(result_arr), 2) a_arr = np.array([True, False], dtype=np.bool) result_arr_ref = np.logical_not(a_arr) assert np.allclose(result_arr, result_arr_ref)
def logical_not(node, name=None): # type: (Node, str) -> Node """Return node which applies logical negation to the input node elementwise.""" return Not(node)