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

added cosing_embedding_loss #27975

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,60 @@ def test_kl_div(
log_target=log_target,
)

@handle_test(
fn_tree="functional.ivy.cosine_embedding_loss",
dtype_input1=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_value=-1,
max_value=1,
allow_inf=False,
),
dtype_input2=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_value=-1,
max_value=1,
allow_inf=False,
),
dtype_target=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("int"), # target typically contains 1 or -1
min_value=-1,
max_value=1,
allow_inf=False,
shape_constraint="same_as_input", # Ensure target has the same shape as input1 and input2
),
margin=st.floats(min_value=0, max_value=1), # Define range for margin
reduction=st.sampled_from(["sum", "mean", "none"]),
)
def test_cosine_embedding_loss(
*,
dtype_input1,
dtype_input2,
dtype_target,
margin,
reduction,
test_flags,
backend_fw,
fn_name,
on_device,
):
dtype_input1, input1 = dtype_input1
dtype_input2, input2 = dtype_input2
dtype_target, target = dtype_target

helpers.test_function(
input_dtypes=dtype_input1 + dtype_input2 + dtype_target,
test_flags=test_flags,
backend_to_test=backend_fw,
fn_name=fn_name,
on_device=on_device,
atol_=1e-02,
input1=input1[0],
input2=input2[0],
target=target[0],
margin=margin,
reduction=reduction,
)


@handle_test(
fn_tree="functional.ivy.experimental.l1_loss",
Expand Down
Loading