def test_static_graph(self): startup_program = fluid.Program() train_program = fluid.Program() with fluid.program_guard(train_program, startup_program): inputs = fluid.data(name='input', dtype='int64', shape=[7]) weights = fluid.data(name='weights', dtype='int64', shape=[7]) output = paddle.bincount(inputs, weights=weights) place = fluid.CPUPlace() if fluid.core.is_compiled_with_cuda(): place = fluid.CUDAPlace(0) exe = fluid.Executor(place) exe.run(startup_program) img = np.array([0, 1, 1, 3, 2, 1, 7]).astype(np.int64) w = np.array([0, 1, 1, 2, 2, 1, 0]).astype(np.int64) res = exe.run(train_program, feed={ 'input': img, 'weights': w }, fetch_list=[output]) actual = np.array(res[0]) expected = np.bincount(img, weights=w) self.assertTrue( (actual == expected).all(), msg='bincount output is wrong, out =' + str(actual))
def test_dygraph(self): with fluid.dygraph.guard(): inputs_np = np.array([0, 1, 1, 3, 2, 1, 7]).astype(np.int64) inputs = fluid.dygraph.to_variable(inputs_np) actual = paddle.bincount(inputs) expected = np.bincount(inputs) self.assertTrue( (actual.numpy() == expected).all(), msg='bincount output is wrong, out =' + str(actual.numpy()))
def net_func(): input_value = paddle.to_tensor([1, 2, 3, 4, 5]) paddle.bincount(input_value, minlength=-1)
def net_func(): input_value = paddle.to_tensor([[1, 2, 3], [4, 5, 6]]) paddle.bincount(input_value)
def net_func(): input_value = paddle.to_tensor([1, 2, 3, 4, -5]) paddle.bincount(input_value)
def net_func(): input_value = paddle.to_tensor([1, 2, 3, 4, 5]) weights = paddle.to_tensor([1, 1, 1, 1, 1, 1]) paddle.bincount(input_value, weights=weights)
def net_func(): input_value = paddle.to_tensor([1., 2., 3., 4., 5.]) paddle.bincount(input_value)