-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Description
Issue description
torch.histogram test cases use random tensor as bins parameter input, which is not make sense. It should be an increasing sequence
Code example
def sample_inputs_histogram(op_info, device, dtype, requires_grad, **kwargs):
make_arg = partial(make_tensor, dtype=dtype, device=device, requires_grad=requires_grad)
sizes = ((), (S,), (S, S), (S, S, S), (S, 1, S), (S, 0, S))
for size, bin_ct, weighted, density in product(sizes, range(1, 5), [False, True], [False, True]):
input_tensor = make_arg(size)
weight_tensor = make_arg(size) if weighted else None
yield SampleInput(input_tensor, bin_ct,
weight=weight_tensor, density=density)
bins_tensor = make_arg((bin_ct + 1,))
yield SampleInput(input_tensor, bins_tensor,
weight=weight_tensor, density=density)
here bins_tensor = make_arg((bin_ct + 1,))
, bins_tensor is randomly generated and out-of-order.
For example, we could get such test case:
input=6.362441917740258
bins = tensor([ 6.3624, -3.1650, 7.6229, 4.4501]
result is:
torch.return_types.histogram(
hist=tensor([0., 0., 0.], dtype=torch.float64),
bin_edges=tensor([ 6.3624, -3.1650, 7.6229, 4.4501], dtype=torch.float64))
I think it's not make sense that torch.histogram input out-of-order bins.
1, The doc https://pytorch.org/docs/stable/generated/torch.histogram.html#torch-histogram mentions that "If bins is a 1D tensor, it specifies the sequence of bin edges including the rightmost edge. It should contain at least 2 elements and its elements should be increasing."
2, histogram operator implemented with std::upper_bound
for binary search, see
pos = std::upper_bound(bin_seq[dim], bin_seq[dim] + num_bin_edges[dim], elt) |
std::upper_bound
function requires increasing sequence for binary search.
cc @albanD