Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(torch): torch.histc function added to torch front-end #23678

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ivy/functional/frontends/torch/miscellaneous_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,16 @@ def view_as_real(input):
re_part = ivy.real(input)
im_part = ivy.imag(input)
return ivy.stack((re_part, im_part), axis=-1)


@to_ivy_arrays_and_back
def histc(input, bins=100, min=0, max=0, *, out= None):
input_ivy = ivy.flatten(input) # torch.histc results in a 1D tensor so I flattened it out.
if min ==0 and max ==0:
min = ivy.min(input_ivy); max = ivy.max(input_ivy)
if min == max:
range = (min - 1e-2 , min + 1e-2)
else:
range = (min , max)

return ivy.histogram(input_ivy, bins = bins, range=range, axis =0)
Original file line number Diff line number Diff line change
Expand Up @@ -1824,3 +1824,31 @@ def test_torch_view_as_real(
on_device=on_device,
input=np.asarray(x[0], dtype=input_dtype[0]),
)


# histc
@handle_frontend_test(
fn_tree= "torch.histc",
dtype_and_x = helpers.dtype_and_values(
available_dtypes= helpers.get_dtypes("float"),
),
)
def test_torch_histc(
*,
dtype_and_x,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtype , x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags = test_flags,
fn_tree= fn_tree,
on_device=on_device,
input = x[0],
)
Loading